-
Notifications
You must be signed in to change notification settings - Fork 33
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
e196e52
commit 2fbec7e
Showing
9 changed files
with
192 additions
and
5 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
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,41 @@ | ||
import { logError } from '@edx/frontend-platform/logging'; | ||
import { | ||
FETCH_ENTERPRISE_BUDGETS_REQUEST, | ||
FETCH_ENTERPRISE_BUDGETS_SUCCESS, | ||
FETCH_ENTERPRISE_BUDGETS_FAILURE, | ||
CLEAR_ENTERPRISE_BUDGETS, | ||
} from '../constants/enterpriseBudgets'; | ||
import EnterpriseDataApiService from '../services/EnterpriseDataApiService'; | ||
|
||
const fetchEnterpriseBudgetsRequest = () => ({ type: FETCH_ENTERPRISE_BUDGETS_REQUEST }); | ||
const fetchEnterpriseBudgetsSuccess = data => ({ | ||
type: FETCH_ENTERPRISE_BUDGETS_SUCCESS, | ||
payload: { data }, | ||
}); | ||
const fetchEnterpriseBudgetsFailure = error => ({ | ||
type: FETCH_ENTERPRISE_BUDGETS_FAILURE, | ||
payload: { error }, | ||
}); | ||
|
||
const fetchEnterpriseBudgets = enterpriseId => ( | ||
(dispatch) => { | ||
dispatch(fetchEnterpriseBudgetsRequest()); | ||
return EnterpriseDataApiService.fetchEnterpriseBudgets(enterpriseId) | ||
.then((response) => { | ||
dispatch(fetchEnterpriseBudgetsSuccess(response.data)); | ||
}) | ||
.catch((error) => { | ||
logError(error); | ||
dispatch(fetchEnterpriseBudgetsFailure(error)); | ||
}); | ||
} | ||
); | ||
|
||
const clearEnterpriseBudgets = () => dispatch => (dispatch({ | ||
type: CLEAR_ENTERPRISE_BUDGETS, | ||
})); | ||
|
||
export { | ||
fetchEnterpriseBudgets, | ||
clearEnterpriseBudgets, | ||
}; |
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,11 @@ | ||
const FETCH_ENTERPRISE_BUDGETS_REQUEST = 'FETCH_ENTERPRISE_BUDGETS_REQUEST'; | ||
const FETCH_ENTERPRISE_BUDGETS_SUCCESS = 'FETCH_ENTERPRISE_BUDGETS_SUCCESS'; | ||
const FETCH_ENTERPRISE_BUDGETS_FAILURE = 'FETCH_ENTERPRISE_BUDGETS_FAILURE'; | ||
const CLEAR_ENTERPRISE_BUDGETS = 'CLEAR_ENTERPRISE_BUDGETS'; | ||
|
||
export { | ||
FETCH_ENTERPRISE_BUDGETS_REQUEST, | ||
FETCH_ENTERPRISE_BUDGETS_SUCCESS, | ||
FETCH_ENTERPRISE_BUDGETS_FAILURE, | ||
CLEAR_ENTERPRISE_BUDGETS, | ||
}; |
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,47 @@ | ||
import { | ||
FETCH_ENTERPRISE_BUDGETS_REQUEST, | ||
FETCH_ENTERPRISE_BUDGETS_SUCCESS, | ||
FETCH_ENTERPRISE_BUDGETS_FAILURE, | ||
CLEAR_ENTERPRISE_BUDGETS, | ||
} from '../constants/enterpriseBudgets'; | ||
|
||
const initialState = { | ||
loading: false, | ||
error: null, | ||
budgets: null, | ||
}; | ||
|
||
const enterpriseBudgets = (state = initialState, action) => { | ||
switch (action.type) { | ||
case FETCH_ENTERPRISE_BUDGETS_REQUEST: | ||
return { | ||
...state, | ||
loading: true, | ||
error: null, | ||
}; | ||
case FETCH_ENTERPRISE_BUDGETS_SUCCESS: | ||
return { | ||
...state, | ||
loading: false, | ||
budgets: action.payload.data, | ||
}; | ||
case FETCH_ENTERPRISE_BUDGETS_FAILURE: | ||
return { | ||
...state, | ||
loading: false, | ||
error: action.payload.error, | ||
budgets: null, | ||
}; | ||
case CLEAR_ENTERPRISE_BUDGETS: | ||
return { | ||
...state, | ||
loading: false, | ||
error: null, | ||
budgets: null, | ||
}; | ||
default: | ||
return state; | ||
} | ||
}; | ||
|
||
export default enterpriseBudgets; |
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