(null);
+
+ const openEditForDraft = (purchaseId: string) => {
+ setEditingPurchaseId(purchaseId);
+ setQuickDraftOpen(true);
+ };
+
+ const tabHref = (value: StockPurchaseStatus | "") => {
+ const params = new URLSearchParams();
+ if (value) params.set("status", value);
+ const qs = params.toString();
+ return qs ? `/stock-orders?${qs}` : "/stock-orders";
+ };
+
+ const pageHref = (target: number) => {
+ const params = new URLSearchParams();
+ if (currentStatus) params.set("status", currentStatus);
+ if (target > 1) params.set("page", String(target));
+ const qs = params.toString();
+ return qs ? `/stock-orders?${qs}` : "/stock-orders";
+ };
+
+ return (
+ <>
+ {/* Status filter — server-rendered tabs. */}
+
+ {STATUS_TABS.map((tab) => {
+ const active = currentStatus === tab.value;
+ return (
+
+ {tab.label}
+
+ );
+ })}
+
+
+
+
+
+
+ {rows.length === 0 ? (
+
+
+
+
+ {currentStatus
+ ? `No ${STATUS_LABEL[currentStatus].toLowerCase()} stock orders.`
+ : "No stock orders yet."}
+
+
+ Create your first stock order
+
+
+
+ ) : (
+
+
+
+
+
+ Number
+ Supplier
+ Status
+ Ordered (R)
+ Received (R)
+ Items
+ Created
+
+
+
+
+ {rows.map((row) => {
+ const supplier = row.expand?.supplier;
+ return (
+ {
+ window.location.href = `/stock-orders/${row.id}`;
+ }}
+ >
+
+ {row.purchase_number}
+
+
+ {supplier?.suppliername ?? (
+
+ Unknown supplier
+
+ )}
+
+
+
+ {STATUS_LABEL[row.status]}
+
+
+
+ {formatCurrency(row.ordered_value)}
+
+
+ {formatCurrency(row.received_value)}
+
+
+ {row.item_count}
+
+
+ {formatDate(row.created)}
+
+
+
+ {row.status === "draft" && (
+
+ )}
+
+
+
+
+ );
+ })}
+
+
+
+
+ )}
+
+ {totalPages > 1 && (
+
+
+ Previous
+
+
+ Page {page} of {totalPages}
+
+ = totalPages}
+ className={cn(
+ buttonVariants({ variant: "outline", size: "sm" }),
+ page >= totalPages && "pointer-events-none opacity-50",
+ )}
+ >
+ Next
+
+
+ )}
+
+ {
+ setQuickDraftOpen(next);
+ if (!next) setEditingPurchaseId(null);
+ }}
+ editPurchaseId={editingPurchaseId ?? undefined}
+ />
+ >
+ );
+}