40 lines
1.4 KiB
TypeScript
40 lines
1.4 KiB
TypeScript
import { Reducer } from 'redux';
|
|
import produce from 'immer';
|
|
import USER_ACTION from '@Reducers/_Constants/User';
|
|
import GLOBAL_ACTION from '@Reducers/_Constants/Global';
|
|
import { CreateUserReducerParams, UserActionTypes, UserState } from './types';
|
|
|
|
export function createUserReducer(params: CreateUserReducerParams): Reducer<UserState, UserActionTypes> {
|
|
return (state = params.initialState, action: UserActionTypes): UserState => produce(state, (_draft) => {
|
|
const draft = _draft;
|
|
switch (action.type) {
|
|
case USER_ACTION.SET_USER_INITIALIZE:
|
|
draft.initialize();
|
|
break;
|
|
case USER_ACTION.SET_USER_LOGIN_STATE:
|
|
draft.updateUserLoginState(action.isLogin);
|
|
break;
|
|
case USER_ACTION.SET_USER_AUTH_STATE:
|
|
draft.updateUserAuthCheck(action.isAuth);
|
|
break;
|
|
case USER_ACTION.SET_USER_TOKEN:
|
|
draft.updateUserToken(action.token);
|
|
break;
|
|
case USER_ACTION.SET_USER_ACCOUNT_INFO:
|
|
draft.updateUserAccountInFo(action.accountInfo);
|
|
break;
|
|
case USER_ACTION.SET_USER_OAUTH_URL:
|
|
draft.updateUserOAuthUrl(action.url);
|
|
break;
|
|
case USER_ACTION.SET_USER_SIGN_OUT_URL:
|
|
draft.updateUserSignOutUrl(action.url);
|
|
break;
|
|
case GLOBAL_ACTION.SET_GLOBAL_REDUX_RESET:
|
|
draft.initialize();
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
});
|
|
}
|