-
Notifications
You must be signed in to change notification settings - Fork 257
/
Copy pathrequest-test-buttons.js
75 lines (69 loc) · 2.1 KB
/
request-test-buttons.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
63
64
65
66
67
68
69
70
71
72
73
74
75
import {fetch, xhr} from "../../../src/index";
export const REQUEST_TEST_START = "REQUEST_TEST_START";
export const REQUEST_TEST_COMPLETE = "REQUEST_TEST_COMPLETE";
export const REQUEST_TEST_ERROR = "REQUEST_TEST_ERROR";
export const DISMISS_REQUEST_TEST_SUCCESS_MODAL = "DISMISS_REQUEST_TEST_SUCCESS_MODAL";
export const DISMISS_REQUEST_TEST_ERROR_MODAL = "DISMISS_REQUEST_TEST_ERROR_MODAL";
export function dismissRequestTestSuccessModal() {
return { type: DISMISS_REQUEST_TEST_SUCCESS_MODAL };
}
export function dismissRequestTestErrorModal() {
return { type: DISMISS_REQUEST_TEST_ERROR_MODAL };
}
export function requestTestStart(key) {
return { type: REQUEST_TEST_START, key };
}
export function requestTestComplete(key) {
return { type: REQUEST_TEST_COMPLETE, key };
}
export function requestTestError(key) {
return { type: REQUEST_TEST_ERROR, key };
}
export function requestTest(url, key) {
return dispatch => {
dispatch(requestTestStart(key));
return fetch(url, {
credentials: "include"
})
.then(resp => {
if (resp && resp.statusText === "OK") {
dispatch(requestTestComplete(key))
} else {
dispatch(requestTestError(key));
}
return resp.json();
})
.then(json => {
console.log("@-->resp json", json);
return json;
})
.catch(resp => {
console.log("fail", resp);
dispatch(requestTestError(key))
});
};
}
export function requestTestXhr(url, key) {
return dispatch => {
dispatch(requestTestStart(key));
return xhr(url, {
credentials: "include"
})
.then(resp => {
if (resp && resp.statusText === "OK") {
dispatch(requestTestComplete(key))
} else {
dispatch(requestTestError(key));
}
return resp.json();
})
.then(json => {
console.log("@-->resp json", json);
return json;
})
.catch(resp => {
console.log("fail", resp);
dispatch(requestTestError(key))
});
};
}