diff --git a/app/api/inventory/route.js b/app/api/inventory/route.js index 773df2b..c91a737 100644 --- a/app/api/inventory/route.js +++ b/app/api/inventory/route.js @@ -1,6 +1,8 @@ import { NextResponse } from "next/server"; import { prisma } from "@/lib/prisma"; +export const dynamic = "force-dynamic"; + // GET all inventory items export async function GET() { try { diff --git a/app/print/page.js b/app/print/page.js index 43f4d16..b60b41e 100644 --- a/app/print/page.js +++ b/app/print/page.js @@ -6,6 +6,7 @@ import { Printer, AlertCircle } from "lucide-react"; export default function PrintPage() { const [items, setItems] = useState([]); + const [selectedIds, setSelectedIds] = useState(new Set()); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); @@ -16,6 +17,7 @@ export default function PrintPage() { if (!res.ok) throw new Error("Failed to fetch inventory from database"); const data = await res.json(); setItems(data); + setSelectedIds(new Set(data.map(i => i.id))); } catch (err) { setError(err.message); } finally { @@ -26,9 +28,24 @@ export default function PrintPage() { }, []); const handlePrint = () => { + if (selectedIds.size === 0) return alert("Please select at least one label to print."); window.print(); }; + const toggleSelection = (id) => { + const next = new Set(selectedIds); + if (next.has(id)) next.delete(id); + else next.add(id); + setSelectedIds(next); + }; + + const toggleAll = () => { + if (selectedIds.size === items.length) setSelectedIds(new Set()); + else setSelectedIds(new Set(items.map(i => i.id))); + }; + + const itemsToPrint = items.filter(i => selectedIds.has(i.id)); + if (loading) return
| + 0} + onChange={toggleAll} + /> + | +Name | +QR ID | +Category | +
|---|---|---|---|
| + {}} /* Handled by row click */ + /> + | +{item.name} | +{item.qrCodeId} |
+ {item.category || "-"} | +