chore: update

This commit is contained in:
TakahashiNg
2026-05-13 04:13:47 +00:00
parent 7fb06212ac
commit 0fadcb10c2
2 changed files with 13 additions and 8 deletions
+1 -1
View File
@@ -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
View File
@@ -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 (