enquiryAction.js 1.15 KB
import axios from "axios";
import { CLEAR_ERRORS, ENQUIRY_SUBMIT_FAIL, ENQUIRY_SUBMIT_REQUEST, ENQUIRY_SUBMIT_SUCCESS } from "../constants/enquiryConstants";

export const postEnqiryDetails = enquiryData => async dispatch => {
  try {
    dispatch({
      type: ENQUIRY_SUBMIT_REQUEST
    });

    const config = {
      headers: {
        "Content-Type": "application/json"
      }
    };

    const response = await axios.post(
      `${process.env.NEXT_PUBLIC_BACKEND_API_URL}/api/leads`,
      {
        data: {
          fullName: enquiryData.fullName,
          mobileNumber: enquiryData.mobileNumber,
          email: enquiryData.email,
          projects: enquiryData.projects,
          comments: enquiryData.comments
        }
      },
      config
    );

    dispatch({
      type: ENQUIRY_SUBMIT_SUCCESS,
      payload: response.data
    });
  } catch (error) {
    console.log("Error while submitting enquiry details: ");
    console.log(error);

    dispatch({
      type: ENQUIRY_SUBMIT_FAIL,
      payload: error.response.data
    });
  }
};

// Clear errors
export const clearErrors = () => async dispatch => {
  dispatch({
    type: CLEAR_ERRORS
  });
};