UNPKG

@omegabigdata/honoplay-redux-helper

Version:
148 lines (139 loc) 3.41 kB
import { CREATE_QUESTION_FAILED, CREATE_QUESTION_SUCCESS, CREATING_QUESTION, FETCHING_QUESTION, FETCHING_QUESTION_LIST, FETCH_QUESTION_FAILED, FETCH_QUESTION_LIST_FAILED, FETCH_QUESTION_LIST_SUCCESS, FETCH_QUESTION_SUCCESS, UPDATE_QUESTION_FAILED, UPDATE_QUESTION_SUCCESS, UPDATING_QUESTION } from "../helpers/ActionTypes/Question"; const QUESTION_LIST_INITIAL_STATE = { isQuestionListLoading: false, questionsList: null, errorQuestionList: null }; const QUESTION_INITIAL_STATE = { isQuestionLoading: false, question: null, errorQuestion: null }; const CREATE_QUESTION_INITIAL_STATE = { isCreateQuestionLoading: false, createQuestion: null, errorCreateQuestion: null }; const UPDATE_QUESTION_INITIAL_STATE = { isUpdateQuestionLoading: false, updateQuestion: null, errorUpdateQuestion: null }; export const questionListReducers = ( state = QUESTION_LIST_INITIAL_STATE, action ) => { switch (action.type) { case FETCHING_QUESTION_LIST: return { ...state, isQuestionListLoading: true, errorQuestionList: null }; case FETCH_QUESTION_LIST_SUCCESS: return { ...state, isQuestionListLoading: false, questionsList: action.data }; case FETCH_QUESTION_LIST_FAILED: return { ...state, isQuestionListLoading: false, errorQuestionList: action.data.error }; default: return state; } }; export const questionReducers = (state = QUESTION_INITIAL_STATE, action) => { switch (action.type) { case FETCHING_QUESTION: return { ...state, isQuestionLoading: true, errorQuestion: null }; case FETCH_QUESTION_SUCCESS: return { ...state, isQuestionLoading: false, question: action.data }; case FETCH_QUESTION_FAILED: return { ...state, isQuestionLoading: false, errorQuestion: action.data.error }; default: return state; } }; export const createQuestionReducers = ( state = CREATE_QUESTION_INITIAL_STATE, action ) => { switch (action.type) { case CREATING_QUESTION: return { ...state, isCreateQuestionLoading: true, errorCreateQuestion: null }; case CREATE_QUESTION_SUCCESS: return { ...state, isCreateQuestionLoading: false, createQuestion: action.data }; case CREATE_QUESTION_FAILED: return { ...state, isCreateQuestionLoading: false, errorCreateQuestion: action.data.error }; default: return state; } }; export const updateQuestionReducers = ( state = UPDATE_QUESTION_INITIAL_STATE, action ) => { switch (action.type) { case UPDATING_QUESTION: return { ...state, isUpdateQuestionLoading: true, errorUpdateQuestion: null }; case UPDATE_QUESTION_SUCCESS: return { ...state, isUpdateQuestionLoading: false, updateQuestion: action.data }; case UPDATE_QUESTION_FAILED: return { ...state, isUpdateQuestionLoading: false, errorUpdateQuestion: action.data.error }; default: return state; } };