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