-
Notifications
You must be signed in to change notification settings - Fork 0
/
userActions.js
40 lines (33 loc) · 910 Bytes
/
userActions.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
import * as APIUtil from '../util/userAPIUtil';
export const RECEIVE_USERS = 'RECEIVE_USERS';
export const RECEIVE_USER = 'RECEIVE_USER';
export const RESET_USERS = 'RESET_USERS';
export const RESET_USER = 'RESET_USER';
export const receiveUsers = response => ({
type: RECEIVE_USERS,
response,
});
export const receiveUser = response => ({
type: RECEIVE_USER,
response,
});
export const resetUsers = () => ({
type: RESET_USERS,
});
export const resetUser = () => ({
type: RESET_USER,
});
export const fetchUsers = () => dispatch => {
dispatch(resetUsers());
APIUtil.fetchUsers().then(response => response.json())
.then(response => (
dispatch(receiveUsers(response))
));
};
export const fetchUser = id => dispatch => {
dispatch(resetUser());
APIUtil.fetchUser(id).then(response => response.json())
.then(response => (
dispatch(receiveUser(response))
));
};