From b77f0d007dd22873a07df0c7f0ffe8b697c86a9f Mon Sep 17 00:00:00 2001 From: NotII <46204250+NotII@users.noreply.github.com> Date: Mon, 9 Jun 2025 22:06:33 +0100 Subject: [PATCH] Add ML, fix product stock data --- app/dashboard/products/page.tsx | 11 ++++++++++- lib/types/index.ts | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/dashboard/products/page.tsx b/app/dashboard/products/page.tsx index c46432d..6fbec7c 100644 --- a/app/dashboard/products/page.tsx +++ b/app/dashboard/products/page.tsx @@ -115,6 +115,15 @@ export default function ProductsPage() { throw new Error("Cannot update product without an ID"); } + // Prepare the product data with stock management fields + const productData = { + ...data, + stockTracking: data.stockTracking ?? true, + currentStock: data.currentStock ?? 0, + lowStockThreshold: data.lowStockThreshold ?? 10, + stockStatus: data.stockStatus ?? 'out_of_stock' + }; + // Save the product data const endpoint = editing ? `/products/${data._id}` : "/products"; const method = editing ? "PUT" : "POST"; @@ -124,7 +133,7 @@ export default function ProductsPage() { headers: { "Content-Type": "application/json", }, - body: JSON.stringify(data), + body: JSON.stringify(productData), }); // If there's a new image to upload diff --git a/lib/types/index.ts b/lib/types/index.ts index 33c9631..88896cc 100644 --- a/lib/types/index.ts +++ b/lib/types/index.ts @@ -42,7 +42,7 @@ export interface Product { currentStock?: number lowStockThreshold?: number stockStatus?: 'in_stock' | 'low_stock' | 'out_of_stock' - unitType: string + unitType: 'pcs' | 'gr' | 'kg' | 'ml' category: string enabled?: boolean pricing: PricingTier[]