2021-07-01 16:51:19 +00:00
|
|
|
import { ROLES } from '../actions/actionsTypes';
|
2022-01-17 18:16:24 +00:00
|
|
|
import { IActionRoles } from '../actions/roles';
|
2021-07-01 16:51:19 +00:00
|
|
|
|
2022-01-17 18:16:24 +00:00
|
|
|
export type IRoles = Record<string, string>;
|
2021-07-01 16:51:19 +00:00
|
|
|
|
2022-01-17 18:16:24 +00:00
|
|
|
export const initialState: IRoles = {};
|
|
|
|
|
|
|
|
export default function roles(state = initialState, action: IActionRoles): IRoles {
|
2021-07-01 16:51:19 +00:00
|
|
|
switch (action.type) {
|
|
|
|
case ROLES.SET:
|
|
|
|
return action.roles;
|
|
|
|
case ROLES.UPDATE:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
[action.payload.id]: action.payload.desc || action.payload.id
|
|
|
|
};
|
|
|
|
case ROLES.REMOVE: {
|
|
|
|
const newState = { ...state };
|
|
|
|
delete newState[action.payload.id];
|
|
|
|
return newState;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|