-
Notifications
You must be signed in to change notification settings - Fork 785
/
Copy pathauth.reducer.js
126 lines (124 loc) · 2.66 KB
/
auth.reducer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import { getLocale } from 'utils';
import {
LOGIN,
LOGOUT,
GET_AUTH_USER,
GET_AUTH_ORGS,
CHANGE_LOCALE,
GET_AUTH_STAR_COUNT,
} from './auth.type';
export const initialState = {
isLoggingIn: false,
isSigningOut: false,
isAuthenticated: false,
accessToken: null,
user: {},
hasInitialUser: false,
orgs: [],
events: [],
// TODO: there should not be a dependency here that can't be constructor injected.
locale: getLocale(),
isPendingUser: false,
isPendingOrgs: false,
isPendingEvents: false,
error: '',
};
export const authReducer = (state = initialState, action = {}) => {
switch (action.type) {
case LOGIN.PENDING:
return {
...state,
isLoggingIn: true,
isAuthenticated: false,
};
case LOGIN.SUCCESS:
return {
...state,
isLoggingIn: false,
isAuthenticated: true,
accessToken: action.payload,
};
case LOGIN.ERROR:
return {
...state,
isLoggingIn: false,
isAuthenticated: false,
error: action.payload,
};
case LOGOUT.PENDING:
return {
...state,
isSigningOut: true,
};
case LOGOUT.SUCCESS:
return {
...initialState,
hasInitialUser: false,
};
case LOGOUT.ERROR:
return {
...state,
isSigningOut: false,
error: action.payload,
};
case GET_AUTH_USER.PENDING:
return {
...state,
isPendingUser: true,
};
case GET_AUTH_USER.SUCCESS:
return {
...state,
isPendingUser: false,
hasInitialUser: true,
user: action.payload,
};
case GET_AUTH_USER.ERROR:
return {
...state,
isPendingUser: false,
error: action.payload,
};
case GET_AUTH_STAR_COUNT.PENDING:
return {
...state,
isPendingStarCount: true,
};
case GET_AUTH_STAR_COUNT.SUCCESS:
return {
...state,
isPendingStarCount: false,
starCount: action.payload,
};
case GET_AUTH_STAR_COUNT.ERROR:
return {
...state,
isPendingStarCount: false,
error: action.payload,
};
case GET_AUTH_ORGS.PENDING:
return {
...state,
isPendingOrgs: true,
};
case GET_AUTH_ORGS.SUCCESS:
return {
...state,
isPendingOrgs: false,
orgs: action.payload,
};
case GET_AUTH_ORGS.ERROR:
return {
...state,
isPendingOrgs: false,
error: action.payload,
};
case CHANGE_LOCALE.SUCCESS:
return {
...state,
locale: action.payload,
};
default:
return state;
}
};