-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreducer.ts
More file actions
40 lines (33 loc) · 819 Bytes
/
reducer.ts
File metadata and controls
40 lines (33 loc) · 819 Bytes
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
import { HYDRATE } from 'next-redux-wrapper';
import { AppState, Action, actionTypes } from './interfaces';
export const initialState: AppState = {
token: '',
loading: false,
};
const reducer = (
state = initialState,
action: Action | { type: typeof HYDRATE; payload: AppState },
): AppState => {
switch (action.type) {
case HYDRATE:
return { ...state, ...action.payload };
case actionTypes.SIGN_IN_REQUEST:
return {
...state,
...{ loading: true },
};
case actionTypes.SIGN_IN_RESPONSE:
return {
...state,
...{ token: action.token, loading: false },
};
case actionTypes.SIGN_IN_FAILURE:
return {
...state,
...{ loading: false },
};
default:
return state;
}
};
export default reducer;