clear state on close
This commit is contained in:
@@ -12,11 +12,10 @@ import {
|
||||
saveProductImage,
|
||||
deleteProductData,
|
||||
} from "@/lib/productData";
|
||||
import { ProductModal } from "@/components/modals/product-modal";
|
||||
import ProductTable from "@/components/tables/product-table";
|
||||
import { Category } from "@/models/categories";
|
||||
import ImportProductsModal from "@/components/modals/import-products-modal";
|
||||
import { ProductModal } from "@/components/modals/product-modal";
|
||||
|
||||
|
||||
export default function ProductsPage() {
|
||||
const router = useRouter();
|
||||
@@ -186,7 +185,7 @@ export default function ProductsPage() {
|
||||
: [{ minQuantity: 1, pricePerUnit: 0 }],
|
||||
});
|
||||
setEditing(true);
|
||||
setModalOpen(true);
|
||||
setAddProductOpen(true);
|
||||
};
|
||||
|
||||
// Reset product data when adding a new product
|
||||
@@ -200,7 +199,7 @@ export default function ProductsPage() {
|
||||
image: null,
|
||||
});
|
||||
setEditing(false);
|
||||
setModalOpen(true);
|
||||
setAddProductOpen(true);
|
||||
};
|
||||
|
||||
// Get category name by ID
|
||||
@@ -214,6 +213,22 @@ export default function ProductsPage() {
|
||||
return category.name;
|
||||
};
|
||||
|
||||
const handleModalClose = () => {
|
||||
setAddProductOpen(false);
|
||||
setEditing(false);
|
||||
setProductData({
|
||||
name: "",
|
||||
description: "",
|
||||
unitType: "pcs",
|
||||
category: "",
|
||||
pricing: [{ minQuantity: 1, pricePerUnit: 0 }],
|
||||
image: null,
|
||||
});
|
||||
if (setImagePreview) {
|
||||
setImagePreview(null);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Layout>
|
||||
<div className="space-y-6">
|
||||
@@ -240,13 +255,13 @@ export default function ProductsPage() {
|
||||
products={products}
|
||||
loading={loading}
|
||||
onEdit={handleEditProduct}
|
||||
onDelete={handleDeleteProduct} // Pass handleDeleteProduct
|
||||
onDelete={handleDeleteProduct}
|
||||
getCategoryNameById={getCategoryNameById}
|
||||
/>
|
||||
|
||||
<ProductModal
|
||||
open={addProductOpen}
|
||||
onClose={() => setAddProductOpen(false)}
|
||||
onClose={handleModalClose}
|
||||
onSave={handleSaveProduct}
|
||||
productData={productData}
|
||||
categories={categories}
|
||||
|
||||
Reference in New Issue
Block a user