Skip to content

Commit

Permalink
[#202] Implement Reducer for Role Group
Browse files Browse the repository at this point in the history
  • Loading branch information
palagdan authored and blcham committed Oct 9, 2024
1 parent 71aa293 commit 89d74a5
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/actions/RoleGroupActions.js
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);
}
4 changes: 4 additions & 0 deletions src/constants/ActionConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ export const IMPERSONATE_LOGOUT_SUCCESS = "IMPERSONATE_LOGOUT_SUCCESS";
export const PUBLISH_MESSAGE = "PUBLISH_MESSAGE";
export const DISMISS_MESSAGE = "DISMISS_MESSAGE";

export const LOAD_ROLE_GROUPS_PENDING = "LOAD_ROLE_GROUPS_PENDING";
export const LOAD_ROLE_GROUPS_SUCCESS = "LOAD_ROLE_GROUPS_SUCCESS";
export const LOAD_ROLE_GROUPS_ERROR = "LOAD_ROLE_GROUPS_ERROR";

export const LOAD_RECORDS_PHASES_PENDING = "LOAD_PHASES_PENDING";
export const LOAD_RECORDS_PHASES_SUCCESS = "LOAD_PHASES_SUCCESS";
export const LOAD_RECORDS_PHASES_ERROR = "LOAD_PHASES_ERROR";
2 changes: 2 additions & 0 deletions src/i18n/cs.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ export default {
"record.load-error": "Záznam se nepodařilo načíst. {error}",
"record.load-form-error": "Formulář se nepodařilo načíst. {error}",

"roleGroup.loading-error": "Nedaří se načíst skupiny rolí. {error}",

"help.local-name":
'Účelem tohoto atributu je pomoci vám identifikovat vyplněný záznam. Můžete použít např. číslování záznam ("záznam_1", "záznam_2").',

Expand Down
38 changes: 38 additions & 0 deletions src/reducers/RoleGroupsReducer.js
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;
}
}
2 changes: 2 additions & 0 deletions src/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import StatisticsReducer from "./StatisticsReducer";
import IntlReducer from "./IntlReducer";
import FormTemplatesReducer from "./FormTemplatesReducer";
import MessageReducer from "./MessageReducer";
import RoleGroupsReducer from "./RoleGroupsReducer.js";

const rootReducer = (state, action) => {
if (action.type === ActionConstants.UNAUTH_USER) {
Expand All @@ -35,6 +36,7 @@ const appReducer = combineReducers({
statistics: StatisticsReducer,
institution: InstitutionReducer,
institutions: InstitutionsReducer,
roleGroups: RoleGroupsReducer,
});

export default rootReducer;

0 comments on commit 89d74a5

Please sign in to comment.