1
0
Fork 0
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:
Fedor Katurov 2019-11-25 12:12:51 +07:00
parent e5be4c383e
commit d7ed0cbe54
9 changed files with 107 additions and 61 deletions

View file

@ -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,
});

View file

@ -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 = {

View file

@ -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,
};

View file

@ -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);

View file

@ -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>;
};
}>;