diff --git a/src/components/book-out/BookOutForm.tsx b/src/components/book-out/BookOutForm.tsx index 47ce6cf..28987ad 100644 --- a/src/components/book-out/BookOutForm.tsx +++ b/src/components/book-out/BookOutForm.tsx @@ -9,12 +9,13 @@ import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from " import { Input } from "../ui/input" import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "../ui/card" import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "../ui/table" -import { Trash2 } from "lucide-react" +import { Trash2, Camera } from "lucide-react" import { showSuccess, showError } from "../../utils/toast" import { CustomerCombobox } from "./CustomerCombobox" import { StockItemSearch } from "./StockItemSearch" import { Customer } from "../customers/columns" import { StockItem } from "../stock/columns" +import QRScannerDialog from "../stock/QRScannerDialog" // Sample data - in a real app, this would come from an API const customersData: Customer[] = [ @@ -53,6 +54,7 @@ const formSchema = z.object({ export function BookOutForm() { const [customers, setCustomers] = React.useState(customersData.map(c => ({ value: c.id, label: c.companyName }))); const [stockItems, setStockItems] = React.useState(stockData); + const [scannerOpen, setScannerOpen] = React.useState(false); const form = useForm>({ resolver: zodResolver(formSchema), @@ -85,6 +87,16 @@ export function BookOutForm() { }); }; + const handleScanSuccess = (decodedText: string) => { + const item = stockItems.find(i => i.sku.toLowerCase() === decodedText.toLowerCase()); + if (item) { + handleAddItem(item); + } else { + showError("Scanned item not found in stock."); + } + setScannerOpen(false); + }; + function onSubmit(values: z.infer) { console.log(values) showSuccess("Stock booked out successfully!") @@ -92,98 +104,113 @@ export function BookOutForm() { } return ( - - - Book Out Stock - Select a customer and add items to book out from your inventory. - - -
- -
- ( - - Customer - - - - )} - /> - - Add Stock Item - + + + + Book Out Stock + Select a customer and add items to book out from your inventory. + + + + +
+ ( + + Customer + + + + )} /> - -
+ + Add Stock Item +
+
+ +
+ +
+
+
-
-

Selected Items

-
- - - - Item - Available - Quantity - - - - - {fields.length > 0 ? ( - fields.map((field, index) => ( - - -

{field.name}

-

SKU: {field.sku}

-
- {field.maxQuantity} - - ( - - - - - - - )} - /> - - - +
+

Selected Items

+
+
+ + + Item + Available + Quantity + + + + + {fields.length > 0 ? ( + fields.map((field, index) => ( + + +

{field.name}

+

SKU: {field.sku}

+
+ {field.maxQuantity} + + ( + + + + + + + )} + /> + + + + +
+ )) + ) : ( + + + No items added yet. - )) - ) : ( - - - No items added yet. - - - )} -
-
+ )} + + +
+ {form.formState.errors.items?.message || form.formState.errors.items?.root?.message}
- {form.formState.errors.items?.message || form.formState.errors.items?.root?.message} - - -
- -
-
+ + + + + + ) } \ No newline at end of file