chore: update
This commit is contained in:
@@ -11,10 +11,7 @@ import {
|
|||||||
} from "react";
|
} from "react";
|
||||||
|
|
||||||
import { eateryClient } from "./apollo-clients";
|
import { eateryClient } from "./apollo-clients";
|
||||||
import { MENU_CATEGORIES, MOCK_COMBOS } from "./constants";
|
|
||||||
import type {
|
import type {
|
||||||
Combo,
|
|
||||||
MenuCategory,
|
|
||||||
MenuItemEntity,
|
MenuItemEntity,
|
||||||
addMenuItemMutation,
|
addMenuItemMutation,
|
||||||
allEateriesQuery,
|
allEateriesQuery,
|
||||||
@@ -27,8 +24,6 @@ export type ManagerTab = "products" | "combos" | "categories" | "menu-items";
|
|||||||
interface ManagerContextType {
|
interface ManagerContextType {
|
||||||
// Data
|
// Data
|
||||||
products: MenuItemEntity[];
|
products: MenuItemEntity[];
|
||||||
combos: Combo[];
|
|
||||||
categories: MenuCategory[];
|
|
||||||
|
|
||||||
// Active tab
|
// Active tab
|
||||||
activeTab: ManagerTab;
|
activeTab: ManagerTab;
|
||||||
@@ -39,17 +34,6 @@ interface ManagerContextType {
|
|||||||
updateProduct: (product: MenuItemEntity) => void;
|
updateProduct: (product: MenuItemEntity) => void;
|
||||||
deleteProduct: (id: string) => void;
|
deleteProduct: (id: string) => void;
|
||||||
toggleProductAvailability: (id: string) => void;
|
toggleProductAvailability: (id: string) => void;
|
||||||
|
|
||||||
// Combo actions
|
|
||||||
addCombo: (combo: Omit<Combo, "id">) => void;
|
|
||||||
updateCombo: (combo: Combo) => void;
|
|
||||||
deleteCombo: (id: number) => void;
|
|
||||||
toggleComboAvailability: (id: number) => void;
|
|
||||||
|
|
||||||
// Category actions
|
|
||||||
addCategory: (category: Omit<MenuCategory, "id">) => void;
|
|
||||||
updateCategory: (category: MenuCategory) => void;
|
|
||||||
deleteCategory: (id: string) => void;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ─── Context ──────────────────────────────────────────────────────────────────
|
// ─── Context ──────────────────────────────────────────────────────────────────
|
||||||
@@ -89,11 +73,6 @@ const ADD_MENU_ITEM = gql`
|
|||||||
|
|
||||||
export function ManagerProvider({ children }: { children: ReactNode }) {
|
export function ManagerProvider({ children }: { children: ReactNode }) {
|
||||||
const [products, setProducts] = useState<MenuItemEntity[]>([]);
|
const [products, setProducts] = useState<MenuItemEntity[]>([]);
|
||||||
const [combos, setCombos] = useState<Combo[]>(MOCK_COMBOS);
|
|
||||||
// Filter out the "all" pseudo-category — managers manage real categories only
|
|
||||||
const [categories, setCategories] = useState<MenuCategory[]>(
|
|
||||||
MENU_CATEGORIES.filter((c) => c.id !== "all"),
|
|
||||||
);
|
|
||||||
const [activeTab, setActiveTab] = useState<ManagerTab>("products");
|
const [activeTab, setActiveTab] = useState<ManagerTab>("products");
|
||||||
|
|
||||||
const { data } = useQuery<allEateriesQuery>(GET_EATERY_MENU, {
|
const { data } = useQuery<allEateriesQuery>(GET_EATERY_MENU, {
|
||||||
@@ -139,72 +118,16 @@ export function ManagerProvider({ children }: { children: ReactNode }) {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
// ── Combo actions ────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
const addCombo = (combo: Omit<Combo, "id">) => {
|
|
||||||
const newCombo: Combo = { ...combo, id: Date.now() };
|
|
||||||
setCombos((prev) => [...prev, newCombo]);
|
|
||||||
};
|
|
||||||
|
|
||||||
const updateCombo = (combo: Combo) => {
|
|
||||||
setCombos((prev) => prev.map((c) => (c.id === combo.id ? combo : c)));
|
|
||||||
};
|
|
||||||
|
|
||||||
const deleteCombo = (id: number) => {
|
|
||||||
setCombos((prev) => prev.filter((c) => c.id !== id));
|
|
||||||
};
|
|
||||||
|
|
||||||
const toggleComboAvailability = (id: number) => {
|
|
||||||
setCombos((prev) =>
|
|
||||||
prev.map((c) => (c.id === id ? { ...c, available: !c.available } : c)),
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
// ── Category actions ─────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
const addCategory = (category: Omit<MenuCategory, "id">) => {
|
|
||||||
const slug = category.name
|
|
||||||
.toLowerCase()
|
|
||||||
.normalize("NFD")
|
|
||||||
.replace(/[\u0300-\u036f]/g, "")
|
|
||||||
.replace(/[^a-z0-9]+/g, "-")
|
|
||||||
.replace(/(^-|-$)/g, "");
|
|
||||||
const newCategory: MenuCategory = {
|
|
||||||
...category,
|
|
||||||
id: `${slug}-${Date.now()}`,
|
|
||||||
};
|
|
||||||
setCategories((prev) => [...prev, newCategory]);
|
|
||||||
};
|
|
||||||
|
|
||||||
const updateCategory = (category: MenuCategory) => {
|
|
||||||
setCategories((prev) =>
|
|
||||||
prev.map((c) => (c.id === category.id ? category : c)),
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const deleteCategory = (id: string) => {
|
|
||||||
setCategories((prev) => prev.filter((c) => c.id !== id));
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ManagerContext.Provider
|
<ManagerContext.Provider
|
||||||
value={{
|
value={{
|
||||||
products,
|
products,
|
||||||
combos,
|
|
||||||
categories,
|
|
||||||
activeTab,
|
activeTab,
|
||||||
setActiveTab,
|
setActiveTab,
|
||||||
addProduct,
|
addProduct,
|
||||||
updateProduct,
|
updateProduct,
|
||||||
deleteProduct,
|
deleteProduct,
|
||||||
toggleProductAvailability,
|
toggleProductAvailability,
|
||||||
addCombo,
|
|
||||||
updateCombo,
|
|
||||||
deleteCombo,
|
|
||||||
toggleComboAvailability,
|
|
||||||
addCategory,
|
|
||||||
updateCategory,
|
|
||||||
deleteCategory,
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
|
|||||||
Reference in New Issue
Block a user