chore: update
This commit is contained in:
@@ -149,7 +149,7 @@ export default function ProductsTab() {
|
||||
</td>
|
||||
<td className="px-4 py-3 text-center">
|
||||
<button
|
||||
onClick={() => toggleProductAvailability(p.id)}
|
||||
onClick={() => toggleProductAvailability(p)}
|
||||
title="Nhấn để đổi trạng thái"
|
||||
className="cursor-pointer border-none bg-transparent"
|
||||
>
|
||||
|
||||
+12
-7
@@ -35,7 +35,7 @@ interface ManagerContextType {
|
||||
addProduct: (product: MenuItemEntity) => void;
|
||||
updateProduct: (product: MenuItemEntity) => void;
|
||||
deleteProduct: (id: string) => void;
|
||||
toggleProductAvailability: (id: string) => void;
|
||||
toggleProductAvailability: (product: MenuItemEntity) => void;
|
||||
}
|
||||
|
||||
// ─── Context ──────────────────────────────────────────────────────────────────
|
||||
@@ -154,12 +154,17 @@ export function ManagerProvider({ children }: { children: ReactNode }) {
|
||||
);
|
||||
};
|
||||
|
||||
const toggleProductAvailability = (id: string) => {
|
||||
setProducts((prev) =>
|
||||
prev.map((p) =>
|
||||
p.id === id ? { ...p, available: !(p.available ?? true) } : p,
|
||||
),
|
||||
);
|
||||
const toggleProductAvailability = async (product: MenuItemEntity) => {
|
||||
const { data } = await mutateUpdateMenuItem({
|
||||
variables: {
|
||||
menuItem: { ...product, available: !product.available },
|
||||
},
|
||||
});
|
||||
|
||||
if (data)
|
||||
setProducts((prev) =>
|
||||
prev.map((p) => (p.id === product.id ? data.updateMenuItem : p)),
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user