chore: update
This commit is contained in:
+20
-5
@@ -15,6 +15,7 @@ import {
|
||||
type MenuItemEntity,
|
||||
type addMenuItemMutation,
|
||||
type allEateriesQuery,
|
||||
deleteMenuItemMutation,
|
||||
updateMenuItemMutation,
|
||||
} from "./types";
|
||||
|
||||
@@ -82,6 +83,12 @@ const UPDATE_MENU_ITEM = gql`
|
||||
}
|
||||
`;
|
||||
|
||||
const DELETE_MENU_ITEM = gql`
|
||||
mutation deleteMenuItem($input: String!) {
|
||||
deleteMenuItem(menuItemId: $input)
|
||||
}
|
||||
`;
|
||||
|
||||
// ─── Provider ─────────────────────────────────────────────────────────────────
|
||||
|
||||
export function ManagerProvider({ children }: { children: ReactNode }) {
|
||||
@@ -99,9 +106,12 @@ export function ManagerProvider({ children }: { children: ReactNode }) {
|
||||
|
||||
const [mutateUpdateMenuItem] = useMutation<updateMenuItemMutation>(
|
||||
UPDATE_MENU_ITEM,
|
||||
{
|
||||
client: eateryClient,
|
||||
},
|
||||
{ client: eateryClient },
|
||||
);
|
||||
|
||||
const [mutateDeleteMenuItem] = useMutation<deleteMenuItemMutation>(
|
||||
DELETE_MENU_ITEM,
|
||||
{ client: eateryClient },
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -135,8 +145,13 @@ export function ManagerProvider({ children }: { children: ReactNode }) {
|
||||
);
|
||||
};
|
||||
|
||||
const deleteProduct = (id: string) => {
|
||||
setProducts((prev) => prev.filter((p) => p.id !== id));
|
||||
const deleteProduct = async (id: string) => {
|
||||
const { data } = await mutateDeleteMenuItem({ variables: { input: id } });
|
||||
|
||||
if (data)
|
||||
setProducts((prev) =>
|
||||
prev.filter((p) => !(p.id == id && data.deleteMenuItem)),
|
||||
);
|
||||
};
|
||||
|
||||
const toggleProductAvailability = (id: string) => {
|
||||
|
||||
@@ -142,3 +142,7 @@ export interface addMenuItemMutation {
|
||||
export interface updateMenuItemMutation {
|
||||
updateMenuItem: MenuItemEntity;
|
||||
}
|
||||
|
||||
export interface deleteMenuItemMutation {
|
||||
deleteMenuItem: boolean;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user