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

41 lines
1.1 KiB
TypeScript
Raw Permalink Normal View History

2019-06-25 04:43:46 +00:00
import { Action, action, Thunk, thunk } from 'easy-peasy';
import updateAccountEmail from '@/api/account/updateAccountEmail';
export interface UserData {
uuid: string;
username: string;
email: string;
language: string;
rootAdmin: boolean;
useTotp: boolean;
createdAt: Date;
updatedAt: Date;
}
export interface UserStore {
2019-06-25 04:43:46 +00:00
data?: UserData;
setUserData: Action<UserStore, UserData>;
updateUserData: Action<UserStore, Partial<UserData>>;
2020-07-05 01:30:50 +00:00
updateUserEmail: Thunk<UserStore, { email: string; password: string }, any, UserStore, Promise<void>>;
2019-06-25 04:43:46 +00:00
}
const user: UserStore = {
data: undefined,
setUserData: action((state, payload) => {
state.data = payload;
}),
2019-06-25 04:43:46 +00:00
updateUserData: action((state, payload) => {
2022-06-26 19:30:05 +00:00
// @ts-expect-error limitation of Typescript, can't do much about that currently unfortunately.
2019-06-25 04:43:46 +00:00
state.data = { ...state.data, ...payload };
}),
updateUserEmail: thunk(async (actions, payload) => {
await updateAccountEmail(payload.email, payload.password);
actions.updateUserData({ email: payload.email });
}),
};
export default user;