Blame view

redux/reducers/faqsReducer.js 716 Bytes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
import { GET_FAQS_REQUEST, CLEAR_ERRORS, GET_FAQS_SUCCESS, GET_FAQS_FAIL } from "../constants/faqsConstants";

export const getAllFaqsReducer = (state = { loading: true, success: false, faqs: null }, action) => {
    switch (action.type) {
      case GET_FAQS_REQUEST:
        return {
          loading: true,
        };
  
      case GET_FAQS_SUCCESS:
        return {
          loading: false,
          faqs: action.payload
        };
  
      case GET_FAQS_FAIL:
        return {
          loading: false,
          error: action.payload.error.message
        };
  
      case CLEAR_ERRORS:
        return {
          ...state,
          error: null
        };
  
      default:
        return state;
    }
  };