faqsReducer.js 716 Bytes
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;
    }
  };