1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-24 20:36:40 +07:00

added register_socials to reducer

This commit is contained in:
Fedor Katurov 2020-08-20 10:55:14 +07:00
parent 358b197c19
commit 837b4ee6f3
8 changed files with 1471 additions and 1412 deletions

View file

@ -138,3 +138,15 @@ export const authGotOauthEvent = (event: IOAuthEvent) => ({
type: AUTH_USER_ACTIONS.GOT_OAUTH_EVENT, type: AUTH_USER_ACTIONS.GOT_OAUTH_EVENT,
event, event,
}); });
export const authSetRegisterSocial = (register_social: Partial<IAuthState['register_social']>) => ({
type: AUTH_USER_ACTIONS.SET_REGISTER_SOCIAL,
register_social,
});
export const authSetRegisterSocialErrors = (
errors: Partial<IAuthState['register_social']['errors']>
) => ({
type: AUTH_USER_ACTIONS.SET_REGISTER_SOCIAL_ERRORS,
errors,
});

View file

@ -32,6 +32,9 @@ export const AUTH_USER_ACTIONS = {
ATTACH_SOCIAL: 'ATTACH_SOCIAL', ATTACH_SOCIAL: 'ATTACH_SOCIAL',
LOGIN_WITH_SOCIAL: 'LOGIN_WITH_SOCIAL', LOGIN_WITH_SOCIAL: 'LOGIN_WITH_SOCIAL',
GOT_OAUTH_EVENT: 'GOT_OAUTH_EVENT', GOT_OAUTH_EVENT: 'GOT_OAUTH_EVENT',
SET_REGISTER_SOCIAL: 'SET_REGISTER_SOCIAL',
SET_REGISTER_SOCIAL_ERRORS: 'SET_REGISTER_SOCIAL_ERRORS',
}; };
export const USER_ERRORS = { export const USER_ERRORS = {

View file

@ -64,6 +64,7 @@ const setRestore: ActionHandler<typeof ActionCreators.authSetRestore> = (state,
...restore, ...restore,
}, },
}); });
const setSocials: ActionHandler<typeof ActionCreators.authSetSocials> = (state, { socials }) => ({ const setSocials: ActionHandler<typeof ActionCreators.authSetSocials> = (state, { socials }) => ({
...state, ...state,
profile: { profile: {
@ -75,6 +76,31 @@ const setSocials: ActionHandler<typeof ActionCreators.authSetSocials> = (state,
}, },
}); });
const setRegisterSocial: ActionHandler<typeof ActionCreators.authSetRegisterSocial> = (
state,
{ register_social }
) => ({
...state,
register_social: {
...state.register_social,
...register_social,
},
});
const setRegisterSocialErrors: ActionHandler<typeof ActionCreators.authSetRegisterSocialErrors> = (
state,
{ errors }
) => ({
...state,
register_social: {
...state.register_social,
errors: {
...state.register_social.errors,
...errors,
},
},
});
export const AUTH_USER_HANDLERS = { export const AUTH_USER_HANDLERS = {
[AUTH_USER_ACTIONS.SET_LOGIN_ERROR]: setLoginError, [AUTH_USER_ACTIONS.SET_LOGIN_ERROR]: setLoginError,
[AUTH_USER_ACTIONS.SET_USER]: setUser, [AUTH_USER_ACTIONS.SET_USER]: setUser,
@ -84,4 +110,6 @@ export const AUTH_USER_HANDLERS = {
[AUTH_USER_ACTIONS.SET_LAST_SEEN_MESSAGES]: setLastSeenMessages, [AUTH_USER_ACTIONS.SET_LAST_SEEN_MESSAGES]: setLastSeenMessages,
[AUTH_USER_ACTIONS.SET_RESTORE]: setRestore, [AUTH_USER_ACTIONS.SET_RESTORE]: setRestore,
[AUTH_USER_ACTIONS.SET_SOCIALS]: setSocials, [AUTH_USER_ACTIONS.SET_SOCIALS]: setSocials,
[AUTH_USER_ACTIONS.SET_REGISTER_SOCIAL]: setRegisterSocial,
[AUTH_USER_ACTIONS.SET_REGISTER_SOCIAL_ERRORS]: setRegisterSocialErrors,
}; };

View file

@ -47,6 +47,16 @@ const INITIAL_STATE: IAuthState = {
is_succesfull: false, is_succesfull: false,
error: null, error: null,
}, },
register_social: {
errors: {
username: '',
password: '',
},
error: '',
token: '',
is_loading: false,
},
}; };
export default createReducer(INITIAL_STATE, HANDLERS); export default createReducer(INITIAL_STATE, HANDLERS);

View file

@ -74,4 +74,14 @@ export type IAuthState = Readonly<{
is_succesfull: boolean; is_succesfull: boolean;
error: string; error: string;
}; };
register_social: {
errors: {
username: string;
password: string;
};
error: string;
token: string;
is_loading: boolean;
};
}>; }>;

View file

@ -7,7 +7,7 @@ import { connectRouter, RouterState, routerMiddleware } from 'connected-react-ro
import { createBrowserHistory } from 'history'; import { createBrowserHistory } from 'history';
import { PersistConfig, Persistor } from 'redux-persist/es/types'; import { PersistConfig, Persistor } from 'redux-persist/es/types';
import auth from '~/redux/auth/reducer'; import auth from '~/redux/auth';
import authSaga from '~/redux/auth/sagas'; import authSaga from '~/redux/auth/sagas';
import { IAuthState } from '~/redux/auth/types'; import { IAuthState } from '~/redux/auth/types';

View file

@ -1,9 +1,9 @@
// create-reducer.ts // create-index.ts
import { Action } from 'redux'; import { Action } from 'redux';
type Handlers<State, Types extends string, Actions extends Action<Types>> = { type Handlers<State, Types extends string, Actions extends Action<Types>> = {
readonly [Type in Types]: (state: State, action: Actions) => State readonly [Type in Types]: (state: State, action: Actions) => State;
} };
// export const createReducer = <State, Types extends string, Actions extends Action<Types>>( // export const createReducer = <State, Types extends string, Actions extends Action<Types>>(
// initialState: State, // initialState: State,
@ -11,9 +11,5 @@ type Handlers<State, Types extends string, Actions extends Action<Types>> = {
// ) => (state = initialState, action: Actions) => // ) => (state = initialState, action: Actions) =>
// handlers.hasOwnProperty(action.type) ? handlers[action.type as Types](state, action) : state; // handlers.hasOwnProperty(action.type) ? handlers[action.type as Types](state, action) : state;
export const createReducer = ( export const createReducer = (initialState, handlers) => (state = initialState, action) =>
initialState, handlers.hasOwnProperty(action.type) ? handlers[action.type](state, action) : state;
handlers,
) => (state = initialState, action) => (handlers.hasOwnProperty(action.type)
? handlers[action.type](state, action)
: state);

View file

@ -1561,7 +1561,7 @@ Lockfile:
babel-generator "^6.26.0" babel-generator "^6.26.0"
babel-helpers "^6.24.1" babel-helpers "^6.24.1"
babel-messages "^6.23.0" babel-messages "^6.23.0"
babel-register "^6.26.0" babel-register_social "^6.26.0"
babel-runtime "^6.26.0" babel-runtime "^6.26.0"
babel-template "^6.26.0" babel-template "^6.26.0"
babel-traverse "^6.26.0" babel-traverse "^6.26.0"
@ -2219,9 +2219,9 @@ Lockfile:
babel-plugin-transform-exponentiation-operator "^6.24.1" babel-plugin-transform-exponentiation-operator "^6.24.1"
babel-plugin-transform-object-rest-spread "^6.22.0" babel-plugin-transform-object-rest-spread "^6.22.0"
babel-register@^6.26.0: babel-register_social@^6.26.0:
version "6.26.0" version "6.26.0"
resolved "https://registry.yarnpkg.com/babel-register/-/babel-register-6.26.0.tgz#6ed021173e2fcb486d7acb45c6009a856f647071" resolved "https://registry.yarnpkg.com/babel-register_social/-/babel-register_social-6.26.0.tgz#6ed021173e2fcb486d7acb45c6009a856f647071"
integrity sha1-btAhFz4vy0htestFxgCahW9kcHE= integrity sha1-btAhFz4vy0htestFxgCahW9kcHE=
dependencies: dependencies:
babel-core "^6.26.0" babel-core "^6.26.0"