-
Notifications
You must be signed in to change notification settings - Fork 7
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
Showing
15 changed files
with
394 additions
and
91 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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[[ | ||
{ | ||
"cobenifet": "TEST_COBENIFET_1" | ||
}, | ||
{ | ||
"cobenifet": "TEST_COBENIFET_2" | ||
}, | ||
{ | ||
"cobenifet": "TEST_COBENIFET_3" | ||
}, | ||
{ | ||
"cobenifet": "TEST_COBENIFET_4" | ||
}, | ||
{ | ||
"cobenifet": "TEST_COBENIFET_5" | ||
} | ||
]] |
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 +1,4 @@ | ||
export * as mockedRetiredTokenResponse from './retired-tokens.json'; | ||
export * as projectRatingResponseStub from './project-ratings.json'; | ||
export * as coBenefitResponseStub from './co-benefits.json'; | ||
export * as qualificationsResponseStub from './qualifications.json'; |
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
[] |
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 |
---|---|---|
@@ -0,0 +1,138 @@ | ||
import _ from 'lodash'; | ||
import { keyMirror } from '../store-functions'; | ||
import constants from '../../constants'; | ||
|
||
import { coBenefitResponseStub, projectRatingResponseStub, qualificationsResponseStub } from '../../mocks'; | ||
|
||
import { | ||
activateProgressIndicator, | ||
deactivateProgressIndicator, | ||
setGlobalErrorMessage, | ||
} from './app'; | ||
|
||
export const actions = keyMirror('GET_RATINGS', 'GET_COBENEFITS', 'QUALIFICATIONS'); | ||
|
||
export const mockedRatingsResponse = { | ||
type: actions.GET_RATINGS, | ||
// Different envs import this differently | ||
payload: _.get( | ||
projectRatingResponseStub, | ||
'default', | ||
projectRatingResponseStub, | ||
), | ||
}; | ||
|
||
export const getRatings = ({ | ||
useMockedResponse = false, | ||
useApiMock = false, | ||
}) => { | ||
return async dispatch => { | ||
dispatch(activateProgressIndicator); | ||
|
||
try { | ||
if (useMockedResponse) { | ||
dispatch(mockedRatingsResponse); | ||
} else { | ||
let url = `${constants.API_HOST}/ratings`; | ||
if (useApiMock) url = `${url}?useMock=true`; | ||
const response = fetch(url); | ||
|
||
if (response.ok) { | ||
const results = await response.json(); | ||
dispatch({ | ||
type: actions.GET_RATINGS, | ||
payload: results, | ||
}); | ||
} | ||
} | ||
} catch { | ||
dispatch(setGlobalErrorMessage('Something went wrong...')); | ||
} finally { | ||
dispatch(deactivateProgressIndicator); | ||
} | ||
}; | ||
}; | ||
|
||
const mockedCoBenefitResponse = { | ||
type: actions.GET_COBENEFITS, | ||
// Different envs import this differently | ||
payload: _.get(coBenefitResponseStub, 'default', coBenefitResponseStub), | ||
}; | ||
|
||
export const getCoBenefits = ({ | ||
useMockedResponse = false, | ||
useApiMock = false, | ||
}) => { | ||
return async dispatch => { | ||
try { | ||
dispatch(activateProgressIndicator); | ||
|
||
if (useMockedResponse) { | ||
dispatch(mockedCoBenefitResponse); | ||
} else { | ||
let url = `${constants.API_HOST}/co-benefits`; | ||
if (useApiMock) { | ||
url = `${url}?useMock=true`; | ||
} | ||
|
||
const response = fetch(url); | ||
|
||
if (response.ok) { | ||
const results = await response.json(); | ||
dispatch({ | ||
type: actions.GET_COBENEFITS, | ||
payload: results, | ||
}); | ||
} | ||
} | ||
} catch { | ||
dispatch(setGlobalErrorMessage('Something went wrong...')); | ||
} finally { | ||
dispatch(deactivateProgressIndicator); | ||
} | ||
}; | ||
}; | ||
|
||
export const mockQualificationsResponse = { | ||
type: actions.QUALIFICATIONS, | ||
// Different envs import this differently | ||
payload: _.get( | ||
qualificationsResponseStub, | ||
'default', | ||
qualificationsResponseStub, | ||
), | ||
}; | ||
|
||
export const getQualifications = ({ | ||
useMockedResponse = false, | ||
useApiMock = false, | ||
}) => { | ||
return async dispatch => { | ||
try { | ||
dispatch(activateProgressIndicator); | ||
|
||
if (useMockedResponse) { | ||
dispatch(mockQualificationsResponse); | ||
} else { | ||
let url = `${constants.API_HOST}/qualifications`; | ||
if (useApiMock) { | ||
url = `${url}?useMock=true`; | ||
} | ||
|
||
const response = fetch(url); | ||
|
||
if (response.ok) { | ||
const results = await response.json(); | ||
dispatch({ | ||
type: actions.QUALIFICATIONS, | ||
payload: results, | ||
}); | ||
} | ||
} | ||
} catch { | ||
dispatch(setGlobalErrorMessage('Something went wrong...')); | ||
} finally { | ||
dispatch(deactivateProgressIndicator); | ||
} | ||
}; | ||
}; |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import u from 'updeep'; | ||
|
||
import { actions as climateWarehouseActions } from '../actions/climateWarehouseActions'; | ||
|
||
const initialState = { | ||
ratings: null, | ||
coBenefits: null, | ||
qualifications: null | ||
}; | ||
|
||
const climateWarehouseReducer = (state = initialState, action) => { | ||
switch (action.type) { | ||
case climateWarehouseActions.GET_RATINGS: | ||
return u({ ratings: action.payload }, state); | ||
|
||
case climateWarehouseActions.GET_COBENEFITS: | ||
return u({ coBenefits: action.payload }, state); | ||
|
||
case climateWarehouseActions.QUALIFICATIONS: | ||
return u({ qualifications: action.payload }, state); | ||
|
||
default: | ||
return state; | ||
} | ||
}; | ||
|
||
export { climateWarehouseReducer }; |
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,2 +1,3 @@ | ||
export * from './appReducer'; | ||
export * from './tokenReducer'; | ||
export * from './climateWarehouseReducer'; | ||
export * from './' |
This file was deleted.
Oops, something went wrong.