forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser.ts
More file actions
40 lines (33 loc) · 1.13 KB
/
user.ts
File metadata and controls
40 lines (33 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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 {
data?: UserData;
setUserData: Action<UserStore, UserData>;
updateUserData: Action<UserStore, Partial<UserData>>;
updateUserEmail: Thunk<UserStore, { email: string; password: string }, any, UserStore, Promise<void>>;
}
const user: UserStore = {
data: undefined,
setUserData: action((state, payload) => {
state.data = payload;
}),
updateUserData: action((state, payload) => {
// @ts-expect-error limitation of Typescript, can't do much about that currently unfortunately.
state.data = { ...state.data, ...payload };
}),
updateUserEmail: thunk(async (actions, payload) => {
await updateAccountEmail(payload.email, payload.password);
actions.updateUserData({ email: payload.email });
}),
};
export default user;