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