vendorReducers.js 2.24 KB
import { UPDATE_VENDOR_DETAILS_FAIL, UPDATE_VENDOR_DETAILS_REQUEST, UPDATE_VENDOR_DETAILS_SUCCESS, CLEAR_ERRORS, GET_LOGGED_IN_VENDOR_REQUEST, GET_LOGGED_IN_VENDOR_SUCCESS, GET_LOGGED_IN_VENDOR_FAIL, GET_VENDOR_DETAILS_FAIL, GET_VENDOR_DETAILS_SUCCESS, GET_VENDOR_DETAILS_REQUEST } from "../constants/vendorConstants";


// Load user reducer
export const loggedInVendorReducer = (state = { loading: true, success: false, loggedInVendor: null }, action) => {
  switch (action.type) {
    case GET_LOGGED_IN_VENDOR_REQUEST:
      return {
        loading: true,
        isAuthenticated: false
      };

    case GET_LOGGED_IN_VENDOR_SUCCESS:
      return {
        loading: false,
        isAuthenticated: true,
        loggedInVendor: action.payload
      };

    case GET_LOGGED_IN_VENDOR_FAIL:
      return {
        loading: false,
        isAuthenticated: true,
        error: action.payload.error.message
      };

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

    default:
      return state;
  }
};

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

    case UPDATE_VENDOR_DETAILS_SUCCESS:
      return {
        loading: false,
        updatedVendorData: action.payload
      };

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

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

    default:
      return state;
  }
};

export const getVendorDetailsReducer = (state = { loading: true, success: false, vendorDetails: null }, action) => {
  switch (action.type) {
    case GET_VENDOR_DETAILS_REQUEST:
      return {
        loading: true,
        isAuthenticated: false
      };

    case GET_VENDOR_DETAILS_SUCCESS:
      return {
        loading: false,
        isAuthenticated: true,
        vendorDetails: action.payload
      };

    case GET_VENDOR_DETAILS_FAIL:
      return {
        loading: false,
        isAuthenticated: true,
        error: action.payload.error.message
      };

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

    default:
      return state;
  }
};