UNPKG

1.62 kBJavaScriptView Raw
1import { combineReducers } from 'redux';
2import * as types from '../types';
3
4const isLogin = (
5 state = true,
6 action
7) => {
8 switch (action.type) {
9 case types.TOGGLE_LOGIN_MODE:
10 return !state;
11 default:
12 return state;
13 }
14};
15
16const message = (
17 state = '',
18 action
19) => {
20 switch (action.type) {
21 case types.TOGGLE_LOGIN_MODE:
22 case types.MANUAL_LOGIN_USER:
23 case types.SIGNUP_USER:
24 case types.LOGOUT_USER:
25 case types.LOGIN_SUCCESS_USER:
26 case types.SIGNUP_SUCCESS_USER:
27 return '';
28 case types.LOGIN_ERROR_USER:
29 case types.SIGNUP_ERROR_USER:
30 return action.message;
31 default:
32 return state;
33 }
34};
35
36const isWaiting = (
37 state = false,
38 action
39) => {
40 switch (action.type) {
41 case types.MANUAL_LOGIN_USER:
42 case types.SIGNUP_USER:
43 case types.LOGOUT_USER:
44 return true;
45 case types.LOGIN_SUCCESS_USER:
46 case types.SIGNUP_SUCCESS_USER:
47 case types.LOGOUT_SUCCESS_USER:
48 case types.LOGIN_ERROR_USER:
49 case types.SIGNUP_ERROR_USER:
50 case types.LOGOUT_ERROR_USER:
51 return false;
52 default:
53 return state;
54 }
55};
56
57const authenticated = (
58 state = false,
59 action
60) => {
61 switch (action.type) {
62 case types.LOGIN_SUCCESS_USER:
63 case types.SIGNUP_SUCCESS_USER:
64 case types.LOGOUT_ERROR_USER:
65 return true;
66 case types.LOGIN_ERROR_USER:
67 case types.SIGNUP_ERROR_USER:
68 case types.LOGOUT_SUCCESS_USER:
69 return false;
70 default:
71 return state;
72 }
73};
74
75const userReducer = combineReducers({
76 isLogin,
77 isWaiting,
78 authenticated,
79 message
80});
81
82export default userReducer;