misc_pterodactyl-panel/resources/scripts/state/admin/roles.ts

33 lines
864 B
TypeScript
Raw Normal View History

import { action, Action } from 'easy-peasy';
import { Role } from '@/api/admin/roles/getRoles';
export interface AdminRoleStore {
data: Role[];
setRoles: Action<AdminRoleStore, Role[]>;
appendRole: Action<AdminRoleStore, Role>;
removeRole: Action<AdminRoleStore, number>;
}
const roles: AdminRoleStore = {
data: [],
setRoles: action((state, payload) => {
state.data = payload;
}),
appendRole: action((state, payload) => {
2021-01-01 00:27:16 +00:00
if (state.data.find(role => role.id === payload.id)) {
state.data = state.data.map(role => role.id === payload.id ? payload : role);
} else {
state.data = [ ...state.data, payload ];
}
}),
removeRole: action((state, payload) => {
state.data = [ ...state.data.filter(role => role.id !== payload) ];
}),
};
export default roles;