diff --git a/src/redux/RolesRedux.js b/src/redux/RolesRedux.js
new file mode 100644
index 0000000..442398e
--- /dev/null
+++ b/src/redux/RolesRedux.js
@@ -0,0 +1,54 @@
+import { createActions, createReducer } from 'reduxsauce';
+import Immutable from 'seamless-immutable';
+import _ from 'underscore';
+import { getFetchingValue, getErrorValue } from '../services/Utils';
+
+/* ------------- Types and Action Creators ------------- */
+const { Types, Creators } = createActions({
+ getRolesAction: ['payload'],
+ getRolesSuccess: ['data'],
+ getRolesFailure: ['error']
+});
+
+export const RolesTypes = Types;
+const RolesActions = Creators;
+export default RolesActions;
+
+/* ------------- Initial State ------------- */
+export const INITIAL_STATE = Immutable({
+ rolesDetail: [],
+ rolesLoading: false,
+ roleserror: {}
+});
+
+/* ------------- Selectors ------------- */
+export const RolesSelectors = {
+ getRolesDetail: (state) => state.roles.rolesDetail
+};
+
+/* ------------- Reducers ------------- */
+export const onGetRolesAction = (state, { payload }) =>
+ state.merge({
+ fetching: _.uniq([state.fetching, payload?.loader]),
+ error: getErrorValue(state?.error, payload?.loader)
+ });
+
+export const onGetRolesSuccess = (state, { data }) =>
+ state.merge({
+ fetching: getFetchingValue(state.fetching, data?.loader),
+ error: getErrorValue(state?.error, data?.loader),
+ rolesDetail: data.rolesDetail
+ });
+
+export const onGetRolesFailure = (state, { error }) =>
+ state.merge({
+ fetching: _.without(state.fetching, error?.loader),
+ error: { ...state.error, [error?.loader]: error?.error }
+ });
+
+/* ------------- Hookup Reducers To Types ------------- */
+export const rolesReducer = createReducer(INITIAL_STATE, {
+ [Types.GET_ROLES_ACTION]: onGetRolesAction,
+ [Types.GET_ROLES_SUCCESS]: onGetRolesSuccess,
+ [Types.GET_ROLES_FAILURE]: onGetRolesFailure
+});
diff --git a/src/redux/index.js b/src/redux/index.js
index 5e860e9..4e28d5c 100644
--- a/src/redux/index.js
+++ b/src/redux/index.js
@@ -2,12 +2,14 @@ import { combineReducers } from 'redux';
import { authReducer } from './AuthRedux';
import { warehouseReducer } from './WarehouseRedux';
import { usersReducer } from './UsersRedux';
+import { rolesReducer } from './RolesRedux';
// Combine all reducers.
const appReducer = combineReducers({
auth: authReducer,
warehouse: warehouseReducer,
- users: usersReducer
+ users: usersReducer,
+ roles: rolesReducer
});
const rootReducer = (state, action) => {
diff --git a/src/sagas/Roles.js b/src/sagas/Roles.js
new file mode 100644
index 0000000..b2527cd
--- /dev/null
+++ b/src/sagas/Roles.js
@@ -0,0 +1,30 @@
+import { AuthorizedAPI } from 'config';
+import { takeLatest, call, put } from 'redux-saga/effects';
+import RolesActions, { RolesTypes } from '../redux/RolesRedux';
+import ApiServices from 'services/API/ApiServices';
+
+export function* onRequestRolesData({ payload }) {
+ const response = yield call(
+ ApiServices[payload?.method],
+ AuthorizedAPI,
+ payload?.slug,
+ payload?.data
+ );
+ if (response?.status === 200) {
+ yield put(
+ RolesActions.getRolesSuccess({
+ loader: payload?.loader,
+ rolesDetail: response?.data?.data
+ })
+ );
+ } else {
+ payload.onFailedRolesData(response.data.error);
+ yield put(
+ RolesActions.getRolesFailure({
+ loader: payload?.loader,
+ error: response?.data
+ })
+ );
+ }
+}
+export default [takeLatest(RolesTypes.GET_ROLES_ACTION, onRequestRolesData)];
diff --git a/src/sagas/index.js b/src/sagas/index.js
index cd0a209..141f3c3 100644
--- a/src/sagas/index.js
+++ b/src/sagas/index.js
@@ -2,9 +2,11 @@ import { all } from 'redux-saga/effects';
import AuthSaga from './Auth';
import WarehouseSaga from './Warehouse';
import UsersSaga from './Users';
+import RolesSaga from './Roles';
export default function* rootSaga() {
yield all([...AuthSaga]);
yield all([...WarehouseSaga]);
yield all([...UsersSaga]);
+ yield all([...RolesSaga]);
}