-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstate.jsx
More file actions
65 lines (54 loc) · 1.36 KB
/
state.jsx
File metadata and controls
65 lines (54 loc) · 1.36 KB
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
const initState = {
versions: [],
};
export const reducer = (state = initState, action) => {
switch (action.type) {
case 'LOAD_VERSIONS_SUCCESS':
return { ...state, versions: action.payload };
default:
return state;
}
};
import { push } from 'redux-router';
const getAllVersions = () => ({
type: 'LOAD_VERSIONS',
payload: {
request: '/api/version',
},
});
const createVersion = (data) => ({
type: 'CREATE_VERSION',
payload: {
request: {
url: '/api/version',
method: 'post',
data,
},
},
});
const createTask = (data) => ({
type: 'CREATE_TASK',
payload: {
request: {
url: '/api/tasks',
method: 'post',
data,
},
},
});
export const showPage = () => (dispatch) => dispatch(getAllVersions());
export function addVersion() {
return (dispatch) => {
const title = prompt('Create new Version', '');
if (title) {
dispatch(createVersion({ title }))
.then(() => dispatch(getAllVersions()));
}
};
}
export function addTask(form) {
return (dispatch, getState) => {
const { router: { params: { projectId } } } = getState();
dispatch(createTask(form)).then(() => dispatch(push(`/projects/${projectId}/tasks`)));
};
}