activitiesReducer.js 1.33 KB
import { CREATE_ACTIVITY_FAIL, CREATE_ACTIVITY_REQUEST, CREATE_ACTIVITY_SUCCESS, GET_ACTIVITIES_FAIL, GET_ACTIVITIES_REQUEST, GET_ACTIVITIES_SUCCESS } from "../constants/activitiesConstants";
import { CLEAR_ERRORS } from "../constants/vendorConstants";

export const createActivityReducer = (state = {}, action) => {
    switch (action.type) {
      case CREATE_ACTIVITY_REQUEST:
        return { loading: true };
  
      case CREATE_ACTIVITY_SUCCESS:
        return {
          loading: false,
          activityData: action.payload
        };
  
      case CREATE_ACTIVITY_FAIL:
        return {
          loading: false,
          error: action.payload.error.message
        };
  
      case CLEAR_ERRORS:
        return {
          ...state,
          error: null
        };
  
      default:
        return state;
    }
  };


export const getActivitiesReducer = (state = {}, action) => {
  switch (action.type) {
    case GET_ACTIVITIES_REQUEST:
      return { loading: true };

    case GET_ACTIVITIES_SUCCESS:
      return {
        loading: false,
        allActivitiesData: action.payload
      };

    case GET_ACTIVITIES_FAIL:
      return {
        loading: false,
        error: action.payload.error.message
      };

    case CLEAR_ERRORS:
      return {
        ...state,
        error: null
      };

    default:
      return state;
  }
};