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

28 lines
761 B
TypeScript
Raw Normal View History

import { action, Action } from 'easy-peasy';
export interface AdminRoleStore {
selectedRoles: number[];
setSelectedRoles: Action<AdminRoleStore, number[]>;
appendSelectedRole: Action<AdminRoleStore, number>;
removeSelectedRole: Action<AdminRoleStore, number>;
}
const roles: AdminRoleStore = {
selectedRoles: [],
setSelectedRoles: action((state, payload) => {
state.selectedRoles = payload;
}),
appendSelectedRole: action((state, payload) => {
state.selectedRoles = state.selectedRoles.filter(id => id !== payload).concat(payload);
}),
removeSelectedRole: action((state, payload) => {
state.selectedRoles = state.selectedRoles.filter(id => id !== payload);
}),
};
export default roles;