@omegabigdata/honoplay-redux-helper
Version:
honoplay-redux-helper
71 lines (66 loc) • 2.02 kB
JavaScript
import {
CREATING_DEPARTMENT,
CREATE_DEPARTMENT_SUCCESS,
CREATE_DEPARTMENT_FAILED,
FETCHING_DEPARTMENT_LIST,
FETCH_DEPARTMENT_LIST_SUCCESS,
FETCH_DEPARTMENT_LIST_FAILED
} from '../helpers/ActionTypes/Department';
const CREATE_DEPARTMENT_INITIAL_STATE = {
isCreateDepartmentLoading: false,
departments: null,
errorCreateDepartment: null
};
const DEPARTMENT_LIST_INITIAL_STATE = {
isDepartmentListLoading: false,
departmentList: null,
errorDepartmentList: null
};
export const createDepartmentReducers = (state = CREATE_DEPARTMENT_INITIAL_STATE, action) => {
switch (action.type) {
case CREATING_DEPARTMENT:
return {
...state,
isCreateDepartmentLoading: true,
errorCreateDepartment: null
};
case CREATE_DEPARTMENT_SUCCESS:
return {
...state,
isCreateDepartmentLoading: false,
departments: action.data
};
case CREATE_DEPARTMENT_FAILED:
return {
...state,
isCreateDepartmentLoading: false,
errorCreateDepartment: action.data.error
}
default:
return state;
}
}
export const departmentListReducers = (state = DEPARTMENT_LIST_INITIAL_STATE, action) => {
switch (action.type) {
case FETCHING_DEPARTMENT_LIST:
return {
...state,
isDepartmentListLoading: true,
errorDepartmentList: null
};
case FETCH_DEPARTMENT_LIST_SUCCESS:
return {
...state,
isDepartmentListLoading: false,
departmentList: action.data
};
case FETCH_DEPARTMENT_LIST_FAILED:
return {
...state,
isDepartmentListLoading: false,
errorDepartmentList: action.data.error
};
default:
return state;
}
};