import { getFetchWithCount } from "@/components/lib/api"; import toast from "react-hot-toast"; export type authState = { auth: { mngAuthrtYn: string; inqAuthrtYn: string; regAuthrtYn: string; mdfcnAuthrtYn: string; delAuthrtYn: string; }; }; export type authType = authState & authActions; export const authStateExport: authState = { auth: { mngAuthrtYn: "Y", inqAuthrtYn: "Y", regAuthrtYn: "Y", mdfcnAuthrtYn: "Y", delAuthrtYn: "Y", }, }; export type authActions = { getMenuAuthrts: (menuCd: number) => void; }; export const authActionsExport: (set: any) => authActions = (set: any) => { return { getMenuAuthrts: async (menuCd: number) => { try{ const response = await getFetchWithCount( 'LOCAL', `/cms-service/api/v1/menu-authrts/pageinfo/${menuCd}` ); set((state: authState) => { return { ...state, auth: { mngAuthrtYn: response[0].mngAuthrtYn, inqAuthrtYn: response[0].mngAuthrtYn, regAuthrtYn: response[0].mngAuthrtYn, mdfcnAuthrtYn: response[0].mngAuthrtYn, delAuthrtYn: response[0].mngAuthrtYn, }, }; }); }catch(e){ toast.error('권한 정보를 가져오는 중 오류가 발생했습니다. 관리자에게 문의하세요.'); console.error('Error fetching menu authorities:', e); } }, }; };