menu grant
This commit is contained in:
@@ -37,10 +37,14 @@ export const MenuCategory = ({
|
|||||||
const [favoriteItems, setFavoriteItems] = useState<Array<UserFavorite>>([]);
|
const [favoriteItems, setFavoriteItems] = useState<Array<UserFavorite>>([]);
|
||||||
const [menuIds, setMenuIds] = useState<Array<number | undefined>>([]);
|
const [menuIds, setMenuIds] = useState<Array<number | undefined>>([]);
|
||||||
|
|
||||||
const onClickToNavigate = (path?: string) => {
|
const onClickToNavigate = (path?: string, menuId?: number) => {
|
||||||
if(!!path && !!setMenuOn && !editMode){
|
if(!!path && !!setMenuOn && !editMode && !!menuId){
|
||||||
setMenuOn(false);
|
setMenuOn(false);
|
||||||
navigate(path);
|
navigate(path, {
|
||||||
|
state: {
|
||||||
|
menuId: menuId
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -121,7 +125,7 @@ export const MenuCategory = ({
|
|||||||
rs.push(
|
rs.push(
|
||||||
<li
|
<li
|
||||||
key={ `menu-item-key-${menuId}-${i}` }
|
key={ `menu-item-key-${menuId}-${i}` }
|
||||||
onClick={ () => onClickToNavigate(subMenu[i]?.programPath) }
|
onClick={ () => onClickToNavigate(subMenu[i]?.programPath, subMenu[i]?.menuId) }
|
||||||
>
|
>
|
||||||
<span>{ displayName }</span>
|
<span>{ displayName }</span>
|
||||||
<div className="check_box_scrap">
|
<div className="check_box_scrap">
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ export interface UserInfoState {
|
|||||||
userInfo: UserInfo;
|
userInfo: UserInfo;
|
||||||
setUserInfo: (update: SetStateAction<Partial<UserInfo>>) => void;
|
setUserInfo: (update: SetStateAction<Partial<UserInfo>>) => void;
|
||||||
resetUserInfo: () => void;
|
resetUserInfo: () => void;
|
||||||
|
menuGrantsByKey: Record<string, Array<string>>;
|
||||||
|
setMenuGrantsByKey: (update: SetStateAction<Record<string, Array<string>>>) => void;
|
||||||
businessInfo: BusinessInfo;
|
businessInfo: BusinessInfo;
|
||||||
setBusinessInfo: (update: SetStateAction<Partial<BusinessInfo>>) => void;
|
setBusinessInfo: (update: SetStateAction<Partial<BusinessInfo>>) => void;
|
||||||
|
|
||||||
@@ -32,6 +34,7 @@ export interface UserInfoState {
|
|||||||
|
|
||||||
const initialUserInfoState = {
|
const initialUserInfoState = {
|
||||||
userInfo: {} as UserInfo,
|
userInfo: {} as UserInfo,
|
||||||
|
menuGrantsByKey: {} as Record<string, Array<string>>,
|
||||||
businessInfo: {} as BusinessInfo,
|
businessInfo: {} as BusinessInfo,
|
||||||
userFavorite: [] as Array<UserFavorite>,
|
userFavorite: [] as Array<UserFavorite>,
|
||||||
userMids: [] as Array<string>,
|
userMids: [] as Array<string>,
|
||||||
@@ -59,6 +62,18 @@ export const createUserInfoStore = lens<UserInfoState>((set, get) => ({
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
setMenuGrantsByKey: (update) => {
|
||||||
|
set((state: UserInfoState) => {
|
||||||
|
const newMenuGrantsByKey = (typeof update === 'function')
|
||||||
|
? update(state.menuGrantsByKey): update;
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
menuGrantsByKey: {
|
||||||
|
...newMenuGrantsByKey
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
|
},
|
||||||
setBusinessInfo: (update) => {
|
setBusinessInfo: (update) => {
|
||||||
set((state: UserInfoState) => {
|
set((state: UserInfoState) => {
|
||||||
const newBusinessInfo = (typeof update === 'function')
|
const newBusinessInfo = (typeof update === 'function')
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import {
|
|||||||
BusinessPropertyParams,
|
BusinessPropertyParams,
|
||||||
BusinessPropertyResponse,
|
BusinessPropertyResponse,
|
||||||
LoginResponse,
|
LoginResponse,
|
||||||
|
MenuGrantsItem,
|
||||||
ShortcutUserParams,
|
ShortcutUserParams,
|
||||||
ShortcutUserResponse,
|
ShortcutUserResponse,
|
||||||
UserFindAuthMethodParams
|
UserFindAuthMethodParams
|
||||||
@@ -257,7 +258,7 @@ export const SubLayout = () => {
|
|||||||
});
|
});
|
||||||
callCodesSelect({ codeCl: '0325' });
|
callCodesSelect({ codeCl: '0325' });
|
||||||
callCodesSelect({ codeCl: '0074' });
|
callCodesSelect({ codeCl: '0074' });
|
||||||
|
onSetGrant();
|
||||||
}).catch((error: any) => {
|
}).catch((error: any) => {
|
||||||
setLoginSuccess(false);
|
setLoginSuccess(false);
|
||||||
});
|
});
|
||||||
@@ -284,6 +285,50 @@ export const SubLayout = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const onSetGrant = () => {
|
||||||
|
let userInfo = useStore.getState().UserStore.userInfo;
|
||||||
|
const menuGrants = userInfo.menuGrants;
|
||||||
|
let grantObj: Record<string, Array<string>> = {};
|
||||||
|
let grantKeys = [8, 4, 2, 1];
|
||||||
|
if(!!menuGrants){
|
||||||
|
for(let i=0;i<menuGrants.length;i++){
|
||||||
|
let menuGrantItem = menuGrants[i];
|
||||||
|
if(menuGrantItem){
|
||||||
|
let menuId: number = menuGrantItem.menuId;
|
||||||
|
let grant: number = menuGrantItem.grant;
|
||||||
|
if(!grantObj.hasOwnProperty(''+menuId)){
|
||||||
|
grantObj[''+menuId] = [];
|
||||||
|
}
|
||||||
|
for(let j=0;j<grantKeys.length;j++){
|
||||||
|
let grantKey = grantKeys[j];
|
||||||
|
if(!!grantKey){
|
||||||
|
//grant = grant - grantKey;
|
||||||
|
if((grant - grantKey) >= 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 = ({
|
const onSetCommonCodes = ({
|
||||||
data,
|
data,
|
||||||
codeCl,
|
codeCl,
|
||||||
@@ -330,7 +375,6 @@ export const SubLayout = () => {
|
|||||||
updateUserData(token);
|
updateUserData(token);
|
||||||
};
|
};
|
||||||
const alarmLink = (options: AlarmLinkOptions) => {
|
const alarmLink = (options: AlarmLinkOptions) => {
|
||||||
console.log(options);
|
|
||||||
if(options?.linkUrl){
|
if(options?.linkUrl){
|
||||||
setAlarmRoutesOn(true);
|
setAlarmRoutesOn(true);
|
||||||
setAlarmOptions(options);
|
setAlarmOptions(options);
|
||||||
|
|||||||
Reference in New Issue
Block a user