@omegabigdata/honoplay-redux-helper
Version:
honoplay-redux-helper
114 lines (107 loc) • 3.12 kB
JavaScript
import {
CREATING_QUESTİON_CATEGORY,
CREATE__QUESTİON_CATEGORY_SUCCESS,
CREATE_QUESTİON_CATEGORY_FAILED,
UPDATING_QUESTİON_CATEGORY,
UPDATE_QUESTİON_CATEGORY_SUCCESS,
UPDATE_QUESTİON_CATEGORY_FAILED,
FETCHING_QUESTİON_CATEGORY_LIST,
FETCH_QUESTİON_CATEGORY_LIST_SUCCESS,
FETCH_QUESTİON_CATEGORY_LIST_FAILED
} from '../helpers/ActionTypes/QuestionCategory';
const CREATE_QUESTİON_CATEGORY_INITIAL_STATE = {
isCreateQuestionCategoryLoading: false,
newQuestionCategory: null,
errorCreateQuestionCategory: null
};
const UPDATE_QUESTİON_CATEGORY_INITIAL_STATE = {
isUpdateQuestionCategoryLoading: false,
updatedQuestionCategory: null,
errorUpdateQuestionCategory: null
};
const QUESTİON_CATEGORY_LIST_INITIAL_STATE = {
isQuestionCategoryListLoading: false,
questionCategories: null,
errorQuestionCategoryList: null
};
export const createQuestionCategoryReducers = (
state = CREATE_QUESTİON_CATEGORY_INITIAL_STATE,
action
) => {
switch (action.type) {
case CREATING_QUESTİON_CATEGORY:
return {
...state,
isCreateQuestionCategoryLoading: true,
errorCreateQuestionCategory: null
};
case CREATE__QUESTİON_CATEGORY_SUCCESS:
return {
...state,
isCreateQuestionCategoryLoading: false,
newQuestionCategory: action.data
};
case CREATE_QUESTİON_CATEGORY_FAILED:
return {
...state,
isCreateQuestionCategoryLoading: false,
errorCreateQuestionCategory: action.data.error
};
default:
return state;
}
};
export const updateQuestionCategoryReducers = (
state = UPDATE_QUESTİON_CATEGORY_INITIAL_STATE,
action
) => {
switch (action.type) {
case UPDATING_QUESTİON_CATEGORY:
return {
...state,
isUpdateQuestionCategoryLoading: true,
errorUpdateQuestionCategory: null
};
case UPDATE_QUESTİON_CATEGORY_SUCCESS:
return {
...state,
isUpdateQuestionCategoryLoading: false,
updatedQuestionCategory: action.data
};
case UPDATE_QUESTİON_CATEGORY_FAILED:
return {
...state,
isUpdateQuestionCategoryLoading: false,
errorUpdateQuestionCategory: action.data.error
};
default:
return state;
}
};
export const questionCategoryListReducers = (
state = QUESTİON_CATEGORY_LIST_INITIAL_STATE,
action
) => {
switch (action.type) {
case FETCHING_QUESTİON_CATEGORY_LIST:
return {
...state,
isQuestionCategoryListLoading: true,
errorQuestionCategoryList: null
};
case FETCH_QUESTİON_CATEGORY_LIST_SUCCESS:
return {
...state,
isQuestionCategoryListLoading: false,
questionCategories: action.data
};
case FETCH_QUESTİON_CATEGORY_LIST_FAILED:
return {
...state,
isQuestionCategoryListLoading: false,
errorQuestionCategoryList: action.data.error
};
default:
return state;
}
};