forked from jeffbski/redux-logic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
actions.js
62 lines (53 loc) · 1.35 KB
/
actions.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
// unique key namespace used by combineReducers.
// By convention it will match the directory structure to
// make it easy to locate the src.
// Also action types will prefix with the capitalized version
export const key = 'users';
// action type constants
export const USERS_FIELD_UPDATED = 'USERS_FIELD_UPDATED';
export const USERS_FIELD_INVALID = 'USERS_FIELD_INVALID';
export const USERS_ADD = 'USERS_ADD';
export const USERS_ADD_SUCCESS = 'USERS_ADD_SUCCESS';
export const USERS_ADD_FAILED = 'USERS_ADD_FAILED';
export const actionTypes = {
USERS_FIELD_UPDATED,
USERS_FIELD_INVALID,
USERS_ADD,
USERS_ADD_SUCCESS,
USERS_ADD_FAILED
};
// action creators
export const usersFieldUpdated = (evt) => ({
type: USERS_FIELD_UPDATED,
payload: {
name: evt.target.name || evt.target.id,
value: evt.target.value
}
});
export const usersFieldInvalid = (errors, fieldUpdate) => ({
type: USERS_FIELD_INVALID,
payload: {
errors,
fieldUpdate
}
});
export const usersAdd = (evt) => {
evt.preventDefault();
return { type: USERS_ADD };
};
export const usersAddSuccess = (user) => ({
type: USERS_ADD_SUCCESS,
payload: user
});
export const usersAddFailed = (err) => ({
type: USERS_ADD_FAILED,
payload: err,
error: true
});
export const actions = {
usersFieldUpdated,
usersFieldInvalid,
usersAdd,
usersAddSuccess,
usersAddFailed
};