-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorchestras.js
56 lines (49 loc) · 1.62 KB
/
orchestras.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
import api from '../api/axiosInstance';
export const FETCH_ORCHESTRA_BEGIN = 'FETCH_ORCHESTRA_BEGIN';
export const FETCH_ORCHESTRA_SUCCESS = 'FETCH_ORCHESTRA_SUCCESS';
export const FETCH_ORCHESTRA_FAILURE = 'FETCH_ORCHESTRA_FAILURE';
export const fetchOrchestraBegin = () => ({
type: FETCH_ORCHESTRA_BEGIN
});
export const fetchOrchestraSuccess = orchestras => ({
type: FETCH_ORCHESTRA_SUCCESS,
payload: orchestras
});
export const fetchOrchestraFailure = error => ({
type: FETCH_ORCHESTRA_FAILURE,
payload: { error }
});
// /orchestra/list_all`,
export function fetchOrchestras() {
return dispatch => {
dispatch(fetchOrchestraBegin());
return api.get(`/orchestra`)
//.then(handleErrors)
.then(json => {
console.log("got this json: " + json.data);
dispatch(fetchOrchestraSuccess({list: json.data, signup: false}));
return json.data;
})
.catch(error => dispatch(fetchOrchestraFailure(error)));
};
}
export function fetchOrchestraFromSignup() {
return dispatch => {
dispatch(fetchOrchestraBegin());
return api.get(`/orchestra_signup`)
//.then(handleErrors)
.then(json => {
console.log("got this json: " + json.data);
dispatch(fetchOrchestraSuccess({list: json.data, signup: true}));
return json.data;
})
.catch(error => dispatch(fetchOrchestraFailure(error)));
};
}
// // Handle HTTP errors since fetch won't.
// function handleErrors(response) {
// if (!response.ok) {
// throw Error(response.statusText);
// }
// return response;
// }