mirror of
https://github.com/MrUnknownDE/panel.git
synced 2026-04-18 22:33:44 +02:00
Finish code for updating email
This commit is contained in:
@@ -1,11 +1,41 @@
|
||||
import { UserState } from '@/state/types';
|
||||
import { action } from 'easy-peasy';
|
||||
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 UserState {
|
||||
data?: UserData;
|
||||
setUserData: Action<UserState, UserData>;
|
||||
updateUserData: Action<UserState, Partial<UserData>>;
|
||||
updateUserEmail: Thunk<UserState, { email: string; password: string }, any, {}, Promise<void>>;
|
||||
}
|
||||
|
||||
const user: UserState = {
|
||||
data: undefined,
|
||||
setUserData: action((state, payload) => {
|
||||
state.data = payload;
|
||||
}),
|
||||
|
||||
updateUserData: action((state, payload) => {
|
||||
// Limitation of Typescript, can't do much about that currently unfortunately.
|
||||
// @ts-ignore
|
||||
state.data = { ...state.data, ...payload };
|
||||
}),
|
||||
|
||||
updateUserEmail: thunk(async (actions, payload) => {
|
||||
await updateAccountEmail(payload.email, payload.password);
|
||||
|
||||
actions.updateUserData({ email: payload.email });
|
||||
}),
|
||||
};
|
||||
|
||||
export default user;
|
||||
|
||||
17
resources/scripts/state/types.d.ts
vendored
17
resources/scripts/state/types.d.ts
vendored
@@ -1,5 +1,6 @@
|
||||
import { FlashMessageType } from '@/components/MessageBox';
|
||||
import { Action } from 'easy-peasy';
|
||||
import { UserState } from '@/state/models/user';
|
||||
|
||||
export interface ApplicationState {
|
||||
flashes: FlashState;
|
||||
@@ -12,22 +13,6 @@ export interface FlashState {
|
||||
clearFlashes: Action<FlashState, string | void>;
|
||||
}
|
||||
|
||||
export interface UserState {
|
||||
data?: UserData;
|
||||
setUserData: Action<UserState, UserData>;
|
||||
}
|
||||
|
||||
export interface UserData {
|
||||
uuid: string;
|
||||
username: string;
|
||||
email: string;
|
||||
language: string;
|
||||
rootAdmin: boolean;
|
||||
useTotp: boolean;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
}
|
||||
|
||||
export interface FlashMessage {
|
||||
id?: string;
|
||||
key?: string;
|
||||
|
||||
Reference in New Issue
Block a user