misc_pterodactyl-panel/resources/scripts/state/permissions.ts

32 lines
841 B
TypeScript
Raw Normal View History

import { action, Action, thunk, Thunk } from 'easy-peasy';
import getSystemPermissions from '@/api/getSystemPermissions';
export interface PanelPermissions {
[key: string]: {
description: string;
keys: { [k: string]: string };
};
}
export interface GloablPermissionsStore {
data: PanelPermissions;
setPermissions: Action<GloablPermissionsStore, PanelPermissions>;
2020-07-05 01:30:50 +00:00
getPermissions: Thunk<GloablPermissionsStore, void, Record<string, unknown>, any, Promise<void>>;
}
const permissions: GloablPermissionsStore = {
data: {},
setPermissions: action((state, payload) => {
state.data = payload;
}),
2022-11-25 20:25:03 +00:00
getPermissions: thunk(async actions => {
const permissions = await getSystemPermissions();
actions.setPermissions(permissions);
}),
};
export default permissions;