From 3302bae7660d6d484b983d79a0a469ce15d94798 Mon Sep 17 00:00:00 2001 From: Daniel Bedeleanu Date: Sun, 19 Apr 2026 14:47:08 +0300 Subject: [PATCH] refactor: extract StockAdjustmentPanel component - Extracted from page.tsx (lines 450-710) - Pure presentational component with all state passed as props - Props: selectedItem, isEditing, editedItem, adjustQty, adjustType, trashReason, categories, fieldScanning - Callbacks: onCancel, onEdit, onEditChange, onQuantityChange, onTypeChange, onReasonChange, onShowScanner, onAdjustStock, onUpdateItem, onDeleteItem - Includes edit mode and adjustment mode with quantity controls - 291 tests passing, build successful --- frontend/app/page.tsx | 371 +++---------------- frontend/components/StockAdjustmentPanel.tsx | 316 ++++++++++++++++ 2 files changed, 358 insertions(+), 329 deletions(-) create mode 100644 frontend/components/StockAdjustmentPanel.tsx diff --git a/frontend/app/page.tsx b/frontend/app/page.tsx index 66607351..adc201f0 100644 --- a/frontend/app/page.tsx +++ b/frontend/app/page.tsx @@ -11,6 +11,9 @@ import Scanner from '@/components/Scanner'; import AIOnboarding from '@/components/AIOnboarding'; import PageShell from '@/components/PageShell'; import ItemComparisonModal from '@/components/ItemComparisonModal'; +import StockAdjustmentPanel from '@/components/StockAdjustmentPanel'; +import NewItemDialog from '@/components/NewItemDialog'; +import ScannerSection from '@/components/ScannerSection'; import { toast } from 'react-hot-toast'; import { Package, @@ -23,10 +26,6 @@ import { ChevronRight, Edit2, RefreshCw, - Sparkles, - Smartphone, - ArrowDownCircle, - ArrowUpCircle, Search } from 'lucide-react'; import { generateBarcode128, getQRCodeURL } from '@/lib/labels'; @@ -360,71 +359,15 @@ export default function Home() { -
- {/* Mode Switcher */} -
- {[ - { id: 'CHECK_IN', label: 'Check In', icon: ArrowDownCircle }, - { id: 'CHECK_OUT', label: 'Check Out', icon: ArrowUpCircle }, - { id: 'TRASH', label: 'Trash', icon: Trash2 } - ].map((m) => ( - - ))} -
- - {/* Scanner Section */} -
- {showScanner ? ( -
-
-

scanning...

- -
- -
- ) : ( -
- - -
- -
-
- )} -
-
+ setMode(newMode as any)} + showScanner={showScanner} + onShowScanner={setShowScanner} + onScanSuccess={onScanSuccess} + onOCRMatch={onOCRMatch} + onAddItemClick={() => setShowOnboarding(true)} + /> {/* Onboarding Overlay */} {showOnboarding && ( @@ -446,267 +389,37 @@ export default function Home() { loading={comparisonLoading} /> - {/* Stock Adjustment Overlay */} - {selectedItem && ( -
-
-
-

- {isEditing ? "Edit Metadata" : selectedItem.name} - {!isEditing && ( - - In Stock: {selectedItem.quantity} - - )} -

-
- {!isEditing && ( - - )} - {isEditing && ( - - )} - -
-
+ {/* Stock Adjustment Panel */} + { + setSelectedItem(null); + setIsEditing(false); + }} + onEdit={(item) => { + setEditedItem(item); + setIsEditing(true); + }} + onEditChange={setEditedItem} + onQuantityChange={setAdjustQty} + onTypeChange={setAdjustType} + onReasonChange={setTrashReason} + onShowScanner={(active, field) => { + setFieldScanning({ active, field }); + setShowScanner(true); + }} + onAdjustStock={handleAdjustStock} + onUpdateItem={handleUpdateItem} + onDeleteItem={handleDeleteItem} + /> - {isEditing ? ( -
-
-
- -