forked from blcham/record-manager-ui
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#202] Implement Reducer for Role Group
- Loading branch information
Showing
5 changed files
with
80 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { asyncError, asyncRequest, showServerResponseErrorMessage } from "./AsyncActionUtils.js"; | ||
import * as ActionConstants from "../constants/ActionConstants.js"; | ||
import { axiosBackend } from "./index.js"; | ||
import { API_URL } from "../../config/index.js"; | ||
|
||
export function loadRoleGroups() { | ||
return function (dispatch, getState) { | ||
dispatch(loadRoleGroupsPending()); | ||
return axiosBackend | ||
.get(`${API_URL}/rest/roleGroups`, {}) | ||
.then((response) => { | ||
dispatch(loadRoleGroupsSuccess(response.data)); | ||
}) | ||
.catch((error) => { | ||
dispatch(loadRoleGroupsError(Error(error.response.data))); | ||
dispatch(showServerResponseErrorMessage(error, "roleGroup.loading-error")); | ||
}); | ||
}; | ||
} | ||
|
||
export function loadRoleGroupsPending() { | ||
return asyncRequest(ActionConstants.LOAD_ROLE_GROUPS_PENDING); | ||
} | ||
|
||
export function loadRoleGroupsSuccess(roleGroups) { | ||
return { | ||
type: ActionConstants.LOAD_ROLE_GROUPS_SUCCESS, | ||
roleGroups, | ||
}; | ||
} | ||
|
||
export function loadRoleGroupsError(error) { | ||
return asyncError(ActionConstants.LOAD_ROLE_GROUPS_ERROR, error); | ||
} |
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,38 @@ | ||
import { ACTION_STATUS } from "../constants/DefaultConstants.js"; | ||
import * as ActionConstants from "../constants/ActionConstants.js"; | ||
|
||
const initialState = { | ||
roleGroupsLoaded: {}, | ||
}; | ||
|
||
export default function (state = initialState, action) { | ||
switch (action.type) { | ||
case ActionConstants.LOAD_ROLE_GROUPS_PENDING: | ||
return { | ||
...state, | ||
roleGroupsLoaded: { | ||
...state.roleGroupsLoaded, | ||
status: ACTION_STATUS.PENDING, | ||
}, | ||
}; | ||
case ActionConstants.LOAD_ROLE_GROUPS_SUCCESS: | ||
return { | ||
...state, | ||
roleGroupsLoaded: { | ||
status: ACTION_STATUS.SUCCESS, | ||
roleGroups: action.roleGroups, | ||
error: "", | ||
}, | ||
}; | ||
case ActionConstants.LOAD_ROLE_GROUPS_ERROR: | ||
return { | ||
...state, | ||
roleGroupsLoaded: { | ||
status: ACTION_STATUS.ERROR, | ||
error: action.error, | ||
}, | ||
}; | ||
default: | ||
return state; | ||
} | ||
} |
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