mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 21:06:42 +07:00
moved history listen to sagas
This commit is contained in:
parent
e5be4c383e
commit
d7ed0cbe54
9 changed files with 107 additions and 61 deletions
|
@ -76,3 +76,13 @@ export const authPatchUser = (user: Partial<IUser>) => ({
|
|||
type: AUTH_USER_ACTIONS.PATCH_USER,
|
||||
user,
|
||||
});
|
||||
|
||||
export const authSetRestore = (restore: Partial<IAuthState['restore']>) => ({
|
||||
type: AUTH_USER_ACTIONS.SET_RESTORE,
|
||||
restore,
|
||||
});
|
||||
|
||||
export const authRestorePassword = (code: string) => ({
|
||||
type: AUTH_USER_ACTIONS.RESTORE_PASSWORD,
|
||||
code,
|
||||
});
|
||||
|
|
|
@ -18,6 +18,9 @@ export const AUTH_USER_ACTIONS = {
|
|||
SET_UPDATES: 'SET_UPDATES',
|
||||
SET_LAST_SEEN_MESSAGES: 'SET_LAST_SEEN_MESSAGES',
|
||||
PATCH_USER: 'PATCH_USER',
|
||||
|
||||
SET_RESTORE: 'SET_RESTORE',
|
||||
RESTORE_PASSWORD: 'RESTORE_PASSWORD',
|
||||
};
|
||||
|
||||
export const USER_ERRORS = {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { AUTH_USER_ACTIONS } from '~/redux/auth/constants';
|
||||
import * as ActionCreators from '~/redux/auth/actions';
|
||||
import { IAuthState } from '~/redux/auth/types';
|
||||
import { Action } from 'history';
|
||||
|
||||
interface ActionHandler<T> {
|
||||
(state: IAuthState, payload: T extends (...args: any[]) => infer R ? R : any): IAuthState;
|
||||
|
@ -57,6 +58,14 @@ const setLastSeenMessages: ActionHandler<typeof ActionCreators.authSetLastSeenMe
|
|||
},
|
||||
});
|
||||
|
||||
const setRestore: ActionHandler<typeof ActionCreators.authSetRestore> = (state, { restore }) => ({
|
||||
...state,
|
||||
restore: {
|
||||
...state.restore,
|
||||
...restore,
|
||||
},
|
||||
});
|
||||
|
||||
export const AUTH_USER_HANDLERS = {
|
||||
[AUTH_USER_ACTIONS.SET_LOGIN_ERROR]: setLoginError,
|
||||
[AUTH_USER_ACTIONS.SET_USER]: setUser,
|
||||
|
@ -64,4 +73,5 @@ export const AUTH_USER_HANDLERS = {
|
|||
[AUTH_USER_ACTIONS.SET_PROFILE]: setProfile,
|
||||
[AUTH_USER_ACTIONS.SET_UPDATES]: setUpdates,
|
||||
[AUTH_USER_ACTIONS.SET_LAST_SEEN_MESSAGES]: setLastSeenMessages,
|
||||
[AUTH_USER_ACTIONS.SET_RESTORE]: setRestore,
|
||||
};
|
||||
|
|
|
@ -31,6 +31,13 @@ const INITIAL_STATE: IAuthState = {
|
|||
messages_error: null,
|
||||
patch_errors: {},
|
||||
},
|
||||
|
||||
restore: {
|
||||
code: '',
|
||||
is_loading: false,
|
||||
is_succesfull: false,
|
||||
errors: {},
|
||||
},
|
||||
};
|
||||
|
||||
export default createReducer(INITIAL_STATE, HANDLERS);
|
||||
|
|
|
@ -49,4 +49,11 @@ export type IAuthState = Readonly<{
|
|||
|
||||
patch_errors: Record<string, string>;
|
||||
};
|
||||
|
||||
restore: {
|
||||
code: string;
|
||||
is_loading: boolean;
|
||||
is_succesfull: boolean;
|
||||
errors: Record<string, string>;
|
||||
};
|
||||
}>;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue