homeDeliveryStatsReducer.js 661 Bytes
import { CLEAR_ERRORS } from "../constants/homeDeliveryStatsConstants";
import { FETCH_HOME_DELIVERY_STATS_FAIL, FETCH_HOME_DELIVERY_STATS_SUCCESS } from "../constants/homeDeliveryStatsConstants";

export const homeDeliveryStatReducer = (state = { homeDeliveryStats: {} }, action) => {
  switch (action.type) {
    case FETCH_HOME_DELIVERY_STATS_SUCCESS:
      return {
        homeDeliveryStats: action.payload.data
      };
    case FETCH_HOME_DELIVERY_STATS_FAIL:
      return {
        error: action.payload.error.message
      };
    case CLEAR_ERRORS:
      return {
        ...state,
        error: null
      };

    default:
      return state;
  }
};