Files
frontend/apps/common/features/src/shared/store/menu-store.ts
T

30 lines
906 B
TypeScript

import { createStore } from "zustand/vanilla";
import type { MenuItem } from "@/entities/menu";
import type { PageMenuAuthority } from "@/entities/menu-authority";
export type MenuState = {
currentMenuInfo: MenuItem | null;
pageMenuAuthority: PageMenuAuthority | null;
};
export type MenuActions = {
setCurrentMenuInfo: (menu: MenuItem) => void;
setPageMenuAuthority: (authority: PageMenuAuthority) => void;
};
export type MenuStore = MenuState & MenuActions;
export const defaultInitState: MenuState = {
currentMenuInfo: null,
pageMenuAuthority: null,
};
export const createMenuStore = (initState: MenuState = defaultInitState) => {
return createStore<MenuStore>()((set) => ({
...initState,
setCurrentMenuInfo: (menu: MenuItem) => set({ currentMenuInfo: menu }),
setPageMenuAuthority: (authority: PageMenuAuthority) =>
set({ pageMenuAuthority: authority }),
}));
};