From d93a92db3990fec1755702a5a461a9d9711e14ea Mon Sep 17 00:00:00 2001 From: "focp212@naver.com" Date: Wed, 5 Nov 2025 10:58:23 +0900 Subject: [PATCH] menu grant --- src/entities/menu/ui/menu-category.tsx | 12 ++++--- src/entities/user/model/store.ts | 15 ++++++++ src/widgets/sub-layout/index.tsx | 48 ++++++++++++++++++++++++-- 3 files changed, 69 insertions(+), 6 deletions(-) diff --git a/src/entities/menu/ui/menu-category.tsx b/src/entities/menu/ui/menu-category.tsx index 51136fc..60aa534 100644 --- a/src/entities/menu/ui/menu-category.tsx +++ b/src/entities/menu/ui/menu-category.tsx @@ -37,10 +37,14 @@ export const MenuCategory = ({ const [favoriteItems, setFavoriteItems] = useState>([]); const [menuIds, setMenuIds] = useState>([]); - const onClickToNavigate = (path?: string) => { - if(!!path && !!setMenuOn && !editMode){ + const onClickToNavigate = (path?: string, menuId?: number) => { + if(!!path && !!setMenuOn && !editMode && !!menuId){ setMenuOn(false); - navigate(path); + navigate(path, { + state: { + menuId: menuId + } + }); } }; @@ -121,7 +125,7 @@ export const MenuCategory = ({ rs.push(
  • onClickToNavigate(subMenu[i]?.programPath) } + onClick={ () => onClickToNavigate(subMenu[i]?.programPath, subMenu[i]?.menuId) } > { displayName }
    diff --git a/src/entities/user/model/store.ts b/src/entities/user/model/store.ts index 55cf9c5..76e1b32 100644 --- a/src/entities/user/model/store.ts +++ b/src/entities/user/model/store.ts @@ -7,6 +7,8 @@ export interface UserInfoState { userInfo: UserInfo; setUserInfo: (update: SetStateAction>) => void; resetUserInfo: () => void; + menuGrantsByKey: Record>; + setMenuGrantsByKey: (update: SetStateAction>>) => void; businessInfo: BusinessInfo; setBusinessInfo: (update: SetStateAction>) => void; @@ -32,6 +34,7 @@ export interface UserInfoState { const initialUserInfoState = { userInfo: {} as UserInfo, + menuGrantsByKey: {} as Record>, businessInfo: {} as BusinessInfo, userFavorite: [] as Array, userMids: [] as Array, @@ -59,6 +62,18 @@ export const createUserInfoStore = lens((set, get) => ({ }; }); }, + setMenuGrantsByKey: (update) => { + set((state: UserInfoState) => { + const newMenuGrantsByKey = (typeof update === 'function') + ? update(state.menuGrantsByKey): update; + return { + ...state, + menuGrantsByKey: { + ...newMenuGrantsByKey + }, + }; + }); + }, setBusinessInfo: (update) => { set((state: UserInfoState) => { const newBusinessInfo = (typeof update === 'function') diff --git a/src/widgets/sub-layout/index.tsx b/src/widgets/sub-layout/index.tsx index ebe9dcd..3ea3d0e 100644 --- a/src/widgets/sub-layout/index.tsx +++ b/src/widgets/sub-layout/index.tsx @@ -23,6 +23,7 @@ import { BusinessPropertyParams, BusinessPropertyResponse, LoginResponse, + MenuGrantsItem, ShortcutUserParams, ShortcutUserResponse, UserFindAuthMethodParams @@ -257,7 +258,7 @@ export const SubLayout = () => { }); callCodesSelect({ codeCl: '0325' }); callCodesSelect({ codeCl: '0074' }); - + onSetGrant(); }).catch((error: any) => { setLoginSuccess(false); }); @@ -284,6 +285,50 @@ export const SubLayout = () => { }); }; + const onSetGrant = () => { + let userInfo = useStore.getState().UserStore.userInfo; + const menuGrants = userInfo.menuGrants; + let grantObj: Record> = {}; + let grantKeys = [8, 4, 2, 1]; + if(!!menuGrants){ + for(let i=0;i= 0){ + grant = grant - grantKey; + if(j === 0){ + grantObj[''+menuId]?.push('D'); + } + else if(j === 1){ + grantObj[''+menuId]?.push('X'); + } + else if(j === 2){ + grantObj[''+menuId]?.push('W'); + } + else if(j === 3){ + grantObj[''+menuId]?.push('R'); + } + } + else{ + continue; + } + } + } + } + } + } + useStore.getState().UserStore.setMenuGrantsByKey(grantObj); + }; + const onSetCommonCodes = ({ data, codeCl, @@ -330,7 +375,6 @@ export const SubLayout = () => { updateUserData(token); }; const alarmLink = (options: AlarmLinkOptions) => { - console.log(options); if(options?.linkUrl){ setAlarmRoutesOn(true); setAlarmOptions(options);