-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3908d53
commit ae3caaf
Showing
4 changed files
with
106 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,65 @@ | ||
// @flow | ||
import printError from "common/utils/printError" | ||
import { | ||
FETCH_GOA_REQUEST, | ||
FETCH_GOA_FAILURE, | ||
FETCH_GOA_SUCCESS, | ||
} from "./goaConstants" | ||
import printError from "common/utils/printError" | ||
|
||
/** | ||
* All of the Redux actions related to GOA data | ||
*/ | ||
|
||
const fetchGoaRequest = () => { | ||
return { | ||
type: FETCH_GOA_REQUEST, | ||
payload: { | ||
isFetching: true, | ||
}, | ||
} | ||
} | ||
const fetchGoaRequest = () => ({ | ||
type: FETCH_GOA_REQUEST, | ||
payload: { | ||
isFetching: true, | ||
}, | ||
}) | ||
|
||
const fetchGoaFailure = error => { | ||
return { | ||
type: FETCH_GOA_FAILURE, | ||
payload: { | ||
isFetching: false, | ||
error: error, | ||
}, | ||
} | ||
} | ||
const fetchGoaFailure = error => ({ | ||
type: FETCH_GOA_FAILURE, | ||
payload: { | ||
isFetching: false, | ||
error, | ||
}, | ||
}) | ||
|
||
const fetchGoaSuccess = (data: Object) => { | ||
return { | ||
type: FETCH_GOA_SUCCESS, | ||
payload: { | ||
isFetching: false, | ||
data, | ||
}, | ||
} | ||
} | ||
const fetchGoaSuccess = (data: Object) => ({ | ||
type: FETCH_GOA_SUCCESS, | ||
payload: { | ||
isFetching: false, | ||
data, | ||
}, | ||
}) | ||
|
||
export const fetchGoa = (url: string) => { | ||
return async (dispatch: Function, getState) => { | ||
if (getState().goa.data) { | ||
return | ||
} | ||
try { | ||
dispatch(fetchGoaRequest()) | ||
const res = await fetch(url, { | ||
headers: { Accept: "application/json" }, | ||
}) | ||
const json = await res.json() | ||
if (res.ok) { | ||
if (json.status >= 300) { | ||
dispatch(fetchGoaFailure(json.title)) | ||
} | ||
dispatch(fetchGoaSuccess(json)) | ||
} else { | ||
export const fetchGoa = (url: string) => async ( | ||
dispatch: Function, | ||
getState: Function, | ||
) => { | ||
if (getState().goa.data) { | ||
return | ||
} | ||
try { | ||
dispatch(fetchGoaRequest()) | ||
const res = await fetch(url, { | ||
headers: { Accept: "application/json" }, | ||
}) | ||
const json = await res.json() | ||
if (res.ok) { | ||
if (json.status >= 300) { | ||
dispatch(fetchGoaFailure(json.title)) | ||
if (process.env.NODE_ENV !== "production") { | ||
printError(res, json) | ||
} | ||
} | ||
} catch (error) { | ||
dispatch(fetchGoaSuccess(json)) | ||
} else { | ||
dispatch(fetchGoaFailure(json.title)) | ||
if (process.env.NODE_ENV !== "production") { | ||
console.error(`Network error: ${error.message}`) | ||
printError(res, json) | ||
} | ||
} | ||
} catch (error) { | ||
if (process.env.NODE_ENV !== "production") { | ||
console.error(`Network error: ${error.message}`) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,66 @@ | ||
// @flow | ||
// import { push } from "connected-react-router" | ||
import printError from "common/utils/printError" | ||
import { | ||
FETCH_GENERAL_DATA_REQUEST, | ||
FETCH_GENERAL_DATA_FAILURE, | ||
FETCH_GENERAL_DATA_SUCCESS, | ||
} from "./summaryConstants" | ||
import printError from "common/utils/printError" | ||
|
||
/** | ||
* All of the Redux actions related to the Summary tab | ||
*/ | ||
|
||
const fetchGeneralDataRequest = () => { | ||
return { | ||
type: FETCH_GENERAL_DATA_REQUEST, | ||
payload: { | ||
isFetching: true, | ||
}, | ||
} | ||
} | ||
const fetchGeneralDataRequest = () => ({ | ||
type: FETCH_GENERAL_DATA_REQUEST, | ||
payload: { | ||
isFetching: true, | ||
}, | ||
}) | ||
|
||
const fetchGeneralDataFailure = error => { | ||
return { | ||
type: FETCH_GENERAL_DATA_FAILURE, | ||
payload: { | ||
isFetching: false, | ||
error: error, | ||
}, | ||
} | ||
} | ||
const fetchGeneralDataFailure = error => ({ | ||
type: FETCH_GENERAL_DATA_FAILURE, | ||
payload: { | ||
isFetching: false, | ||
error, | ||
}, | ||
}) | ||
|
||
const fetchGeneralDataSuccess = (data: Array<Object>) => { | ||
return { | ||
type: FETCH_GENERAL_DATA_SUCCESS, | ||
payload: { | ||
isFetching: false, | ||
data, | ||
}, | ||
} | ||
} | ||
const fetchGeneralDataSuccess = (data: Array<Object>) => ({ | ||
type: FETCH_GENERAL_DATA_SUCCESS, | ||
payload: { | ||
isFetching: false, | ||
data, | ||
}, | ||
}) | ||
|
||
export const fetchGeneralData = (url: string) => { | ||
return async (dispatch: Function, getState) => { | ||
if (getState().general.data) { | ||
return | ||
} | ||
try { | ||
dispatch(fetchGeneralDataRequest()) | ||
const res = await fetch(url, { | ||
headers: { Accept: "application/json" }, | ||
}) | ||
const json = await res.json() | ||
if (res.ok) { | ||
if (json.status >= 300) { | ||
dispatch(fetchGeneralDataFailure(json.title)) | ||
} | ||
dispatch(fetchGeneralDataSuccess(json)) | ||
} else { | ||
export const fetchGeneralData = (url: string) => async ( | ||
dispatch: Function, | ||
getState: Function, | ||
) => { | ||
if (getState().general.data) { | ||
return | ||
} | ||
try { | ||
dispatch(fetchGeneralDataRequest()) | ||
const res = await fetch(url, { | ||
headers: { Accept: "application/json" }, | ||
}) | ||
const json = await res.json() | ||
if (res.ok) { | ||
if (json.status >= 300) { | ||
dispatch(fetchGeneralDataFailure(json.title)) | ||
if (process.env.NODE_ENV !== "production") { | ||
printError(res, json) | ||
} | ||
} | ||
} catch (error) { | ||
dispatch(fetchGeneralDataSuccess(json)) | ||
} else { | ||
dispatch(fetchGeneralDataFailure(json.title)) | ||
if (process.env.NODE_ENV !== "production") { | ||
console.error(`Network error: ${error.message}`) | ||
printError(res, json) | ||
} | ||
} | ||
} catch (error) { | ||
if (process.env.NODE_ENV !== "production") { | ||
console.error(`Network error: ${error.message}`) | ||
} | ||
} | ||
} |