Skip to content

Commit 13b5b11

Browse files
committed
fix add product dialog and business insights page
1 parent 22c193b commit 13b5b11

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

app/AppTable/ProductDialog/AddProductDialog.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export default function AddProductDialog({
9898
setSelectedCategory(selectedProduct.categoryId || "");
9999
setSelectedSupplier(selectedProduct.supplierId || "");
100100
} else {
101+
// Reset form to default values for adding a new product
101102
reset({
102103
productName: "",
103104
sku: "",
@@ -192,8 +193,19 @@ export default function AddProductDialog({
192193
}
193194
};
194195

196+
const handleOpenChange = (open: boolean) => {
197+
if (open) {
198+
// When opening the dialog for adding a new product, clear any selected product
199+
setSelectedProduct(null);
200+
} else {
201+
// When closing the dialog, also clear the selected product to ensure clean state
202+
setSelectedProduct(null);
203+
}
204+
setOpenProductDialog(open);
205+
};
206+
195207
return (
196-
<Dialog open={openProductDialog} onOpenChange={setOpenProductDialog}>
208+
<Dialog open={openProductDialog} onOpenChange={handleOpenChange}>
197209
<DialogTrigger asChild>
198210
<Button className="h-10 font-semibold">+Add Product</Button>
199211
</DialogTrigger>
@@ -271,8 +283,8 @@ export default function AddProductDialog({
271283
{isSubmitting
272284
? "Loading..."
273285
: selectedProduct
274-
? "Update Product"
275-
: "Add Product"}
286+
? "Update Product"
287+
: "Add Product"}
276288
</Button>
277289
</DialogFooter>
278290
</form>

app/business-insights/page.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,6 @@ export default function BusinessInsightsPage() {
240240
quantity: Number(product.quantity),
241241
}));
242242

243-
// Debug logging for topProducts
244-
console.log("Top Products by Value:", topProducts);
245-
246243
// Low stock products (matching product table logic: quantity > 0 AND quantity <= 20)
247244
const lowStockProducts = allProducts
248245
.filter(

0 commit comments

Comments
 (0)