contactUsAction.js 1.19 KB
import axios from "axios";
import { CLEAR_ERRORS, CONTACT_US_SUBMIT_FAIL, CONTACT_US_SUBMIT_REQUEST, CONTACT_US_SUBMIT_SUCCESS } from "../constants/contactUsConstants";

export const postContactUsDetails = contactUsData => async dispatch => {
  try {
    dispatch({
      type: CONTACT_US_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: contactUsData?.fullName,
          email: contactUsData?.emailAddress,
          mobileNumber: contactUsData?.mobileNumber,
          project: contactUsData?.projects,
          comments: contactUsData?.comments
        }
      },
      config
    );
    dispatch({
        type: CONTACT_US_SUBMIT_SUCCESS,
        payload: response.data
      });
  } catch (error) {
    console.log("Error while submitting referral details: ");
    console.log(error);

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

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