hmm
This commit is contained in:
@@ -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}
|
||||
/>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user