enquiryReducer.js 1.81 KB
import {
  ENQUIRY_SUBMIT_FAIL,
  ENQUIRY_SUBMIT_REQUEST,
  ENQUIRY_SUBMIT_SUCCESS,
  GET_ENQUIRIES_BY_ADMIN_FAIL,
  GET_ENQUIRIES_BY_ADMIN_REQUEST,
  GET_ENQUIRIES_BY_ADMIN_SUCCESS,
  GET_ENQUIRIES_BY_VENDOR_FAIL,
  GET_ENQUIRIES_BY_VENDOR_REQUEST,
  GET_ENQUIRIES_BY_VENDOR_SUCCESS
} from "../constants/enquiryConstants";

export const enquiryReducer = (state = { enquiry: null }, action) => {
  switch (action.type) {
    case ENQUIRY_SUBMIT_REQUEST:
      return {
        loading: true,
        success: false
      };
    case ENQUIRY_SUBMIT_SUCCESS:
      return {
        loading: false,
        success: true,
        enquiry: action.payload
      };
    case ENQUIRY_SUBMIT_FAIL:
      return {
        loading: false,
        success: false,
        error: action.payload.error.message
      };

    default:
      return state;
  }
};

export const getEnquiriesReducer = (state = { enquiriesByVendor: null }, action) => {
  switch (action.type) {
    case GET_ENQUIRIES_BY_VENDOR_REQUEST:
      return {
        loading: true
      };
    case GET_ENQUIRIES_BY_VENDOR_SUCCESS:
      return {
        loading: false,
        enquiriesByVendor: action.payload
      };
    case GET_ENQUIRIES_BY_VENDOR_FAIL:
      return {
        loading: false,
        error: action.payload.error.message
      };

    default:
      return state;
  }
};

export const getEnquiriesByVendorReducer = (state = { enquiriesByAdmin: null }, action) => {
  switch (action.type) {
    case GET_ENQUIRIES_BY_ADMIN_REQUEST:
      return {
        loading: true
      };
    case GET_ENQUIRIES_BY_ADMIN_SUCCESS:
      return {
        loading: false,
        enquiriesByAdmin: action.payload
      };
    case GET_ENQUIRIES_BY_ADMIN_FAIL:
      return {
        loading: false,
        error: action.payload.error.message
      };

    default:
      return state;
  }
};