芝麻web文件管理V1.00
编辑当前文件:/home/qrafawbu/rentandbuyrealty.com/rentandbuyrealty.com/web/src/Components/ContactUs/ContactUS.jsx
"use client" import React, { useEffect, useRef, useState } from 'react' import Breadcrumb from "@/Components/Breadcrumb/Breadcrumb"; import { AiFillTwitterCircle } from "react-icons/ai"; import { BsInstagram, BsPinterest } from "react-icons/bs"; import { FiMail, FiPhoneCall } from "react-icons/fi"; import { MdLocationPin } from "react-icons/md"; import { PiFacebookLogoBold } from "react-icons/pi"; import { toast } from "react-hot-toast"; import { translate } from "@/utils"; import { useSelector } from "react-redux"; import { languageData } from "@/store/reducer/languageSlice"; import { ContactUsApi } from "@/store/actions/campaign"; import { settingsData } from "@/store/reducer/settingsSlice"; import Layout from '../Layout/Layout'; const ContactUS = () => { const lang = useSelector(languageData); useEffect(() => { }, [lang]); const [formData, setFormData] = useState({ firstName: "", lastName: "", email: "", subject: "", message: "", }); const systemsettings = useSelector(settingsData); const formRef = useRef(null); // Create a ref for the form const validateForm = () => { if (!formData.firstName || !formData.lastName || !formData.email || !formData.subject || !formData.message) { // If any field is empty, show "Please fill all fields" error toast.error(translate("allFields")); // alert("Please fill all fields") return false; } if (!isValidEmail(formData.email)) { // If email is invalid, show "Invalid email format" error toast.error(translate("emailIsNotValid")); return false; } return true; }; const isValidEmail = (email) => { const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; return emailRegex.test(email); }; const handleInputChange = (e) => { const { name, value } = e.target; setFormData((prevFormData) => ({ ...prevFormData, [name]: value, })); }; const handleContactUsSubmit = (e) => { e.preventDefault(); // Check if all fields are filled if (!formData.firstName || !formData.lastName || !formData.email || !formData.subject || !formData.message) { toast.error(translate("allFields")); } else if (!isValidEmail(formData.email)) { // Check if the email is valid toast.error(translate("emailIsNotValid")); } else { // All fields are filled and email is valid, proceed with the API call ContactUsApi( formData.firstName, formData.lastName, formData.email, formData.subject, formData.message, (response) => { toast.success(response.message); setFormData({ firstName: "", lastName: "", email: "", subject: "", message: "", }); }, (error) => { toast.error(error); } ); } }; return (
{translate("haveQue")}
{translate("getInTouch")}
{/* First Name */}
{translate("firstName")}
{/* Last Name */}
{translate("lastName")}
{/* Email */}
{translate("email")}
{/* Subject */}
{translate("subject")}
{/* Message */}
{translate("message")}
{translate("submit")}
{translate("contactInfo")}
{translate("officeAdd")}
{systemsettings?.company_address}
{translate("tele")}
{systemsettings?.company_tel1}
{systemsettings?.company_tel2}
{translate("emailUs")}
{systemsettings?.company_email}
{systemsettings?.facebook_id && systemsettings?.instagram_id && systemsettings?.twitter_id && systemsettings?.pintrest_id &&
{translate("followUs")}
{systemsettings?.facebook_id ? (
) : null} {systemsettings?.instagram_id ? (
) : null} {systemsettings?.pintrest_id ? (
) : null} {systemsettings?.twitter_id ? (
) : null}
}
) } export default ContactUS