Add handler to fetch all of the system permissions and load them into the state
This commit is contained in:
parent
867dbf3bd2
commit
d69f816d9d
8 changed files with 106 additions and 6 deletions
25
resources/scripts/state/permissions.ts
Normal file
25
resources/scripts/state/permissions.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
import { SubuserPermission } from '@/state/server/subusers';
|
||||
import { action, Action, thunk, Thunk } from 'easy-peasy';
|
||||
import getSystemPermissions from '@/api/getSystemPermissions';
|
||||
|
||||
export interface GloablPermissionsStore {
|
||||
data: SubuserPermission[];
|
||||
setPermissions: Action<GloablPermissionsStore, SubuserPermission[]>;
|
||||
getPermissions: Thunk<GloablPermissionsStore, void, {}, any, Promise<void>>;
|
||||
}
|
||||
|
||||
const permissions: GloablPermissionsStore = {
|
||||
data: [],
|
||||
|
||||
setPermissions: action((state, payload) => {
|
||||
state.data = payload;
|
||||
}),
|
||||
|
||||
getPermissions: thunk(async (actions) => {
|
||||
const permissions = await getSystemPermissions();
|
||||
|
||||
actions.setPermissions(permissions);
|
||||
}),
|
||||
};
|
||||
|
||||
export default permissions;
|
Reference in a new issue