2021-02-25 16:41:44 +00:00
|
|
|
import { PERMISSIONS } from '../actions/actionsTypes';
|
2022-02-02 17:01:31 +00:00
|
|
|
import { TActionPermissions } from '../actions/permissions';
|
2022-04-07 16:53:07 +00:00
|
|
|
import { SUPPORTED_PERMISSIONS } from '../lib/methods/getPermissions';
|
2021-02-25 16:41:44 +00:00
|
|
|
|
2022-02-17 13:06:31 +00:00
|
|
|
export type TSupportedPermissions = typeof SUPPORTED_PERMISSIONS[number];
|
2021-02-25 16:41:44 +00:00
|
|
|
|
2022-02-17 13:06:31 +00:00
|
|
|
export type IPermissionsState = {
|
|
|
|
[K in TSupportedPermissions]?: string[];
|
|
|
|
};
|
2022-02-02 17:01:31 +00:00
|
|
|
|
2022-02-17 13:06:31 +00:00
|
|
|
export const initialState: IPermissionsState = {};
|
|
|
|
|
|
|
|
export default function permissions(state = initialState, action: TActionPermissions): IPermissionsState {
|
2021-02-25 16:41:44 +00:00
|
|
|
switch (action.type) {
|
|
|
|
case PERMISSIONS.SET:
|
|
|
|
return action.permissions;
|
2021-07-01 13:57:23 +00:00
|
|
|
case PERMISSIONS.UPDATE:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
[action.payload.id]: action.payload.roles
|
|
|
|
};
|
2021-02-25 16:41:44 +00:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|