This commit is contained in:
NotII
2025-05-23 10:01:32 +01:00
parent 308a816736
commit 10d7307725
6 changed files with 77 additions and 16 deletions

View File

@@ -266,6 +266,32 @@ export default function ProductsPage() {
}
};
// Handle toggle product enabled status
const handleToggleEnabled = async (productId: string, enabled: boolean) => {
try {
setLoading(true);
await clientFetch(`/products/${productId}`, {
method: "PATCH",
body: JSON.stringify({ enabled }),
});
// Update the local state
setProducts(products.map(product =>
product._id === productId
? { ...product, enabled }
: product
));
toast.success(`Product ${enabled ? 'enabled' : 'disabled'} successfully`);
setLoading(false);
} catch (error) {
console.error(error);
toast.error("Failed to update product status");
setLoading(false);
}
};
return (
<Layout>
<div className="space-y-6">
@@ -315,6 +341,7 @@ export default function ProductsPage() {
loading={loading}
onEdit={handleEditProduct}
onDelete={handleDeleteProduct}
onToggleEnabled={handleToggleEnabled}
getCategoryNameById={getCategoryNameById}
/>