accounts_meta: switch to immer, use the results for useOwnAccount

This commit is contained in:
Alex Gleason
2024-03-24 17:50:54 -05:00
parent 0716c5189e
commit c3ebb5c428
4 changed files with 46 additions and 31 deletions

View File

@ -8,12 +8,12 @@ export const PERMISSION_MANAGE_REPORTS = 0x0000000000000010;
type Permission = typeof PERMISSION_CREATE_GROUPS | typeof PERMISSION_INVITE_USERS | typeof PERMISSION_MANAGE_USERS | typeof PERMISSION_MANAGE_REPORTS
export const hasPermission = (state: RootState, permission: Permission) => {
const account = state.accounts_meta.get(state.me as string)!;
return true;
// const role = state.accounts_meta[state.me as string]?.role;
if (!account?.role) return true;
// if (!role) return true;
// const { permissions } = role;
const permissions = account.getIn(['role', 'permissions']) as number;
if (!permission) return true;
return (permissions & permission) === permission;
// if (!permission) return true;
// return (permissions & permission) === permission;
};