From 8a65de5ba694fe2a8194ddd0e4200965f03aa51d Mon Sep 17 00:00:00 2001 From: Todd Date: Fri, 1 May 2026 09:02:02 -0400 Subject: [PATCH] edit for deplyment --- app/api/inventory/route.js | 2 ++ app/print/page.js | 65 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 65 insertions(+), 2 deletions(-) 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
Loading inventory codes...
; if (error) return
Error: {error}
; @@ -64,11 +81,55 @@ export default function PrintPage() { + {/* Item Selection Table (Hidden in Print) */} +
+
+

Select Labels to Print ({selectedIds.size} selected)

+ +
+
+ + + + + + + + + + + {items.map(item => ( + toggleSelection(item.id)}> + + + + + + ))} + +
+ 0} + onChange={toggleAll} + /> + NameQR IDCategory
+ {}} /* Handled by row click */ + /> + {item.name}{item.qrCodeId}{item.category || "-"}
+
+
+ {/* Printable Sheet Area */} {/* Printable Sheet Area */} - {Array.from({ length: Math.ceil(items.length / 30) }, (_, pageIndex) => ( + {Array.from({ length: Math.ceil(itemsToPrint.length / 30) }, (_, pageIndex) => (
- {items.slice(pageIndex * 30, (pageIndex + 1) * 30).map((item) => ( + {itemsToPrint.slice(pageIndex * 30, (pageIndex + 1) * 30).map((item) => (