"use client"; import { User, Phone, Mail, MapPin, Send } from "lucide-react"; import Image from "next/image"; import { useState, ChangeEvent, FormEvent, useEffect } from "react"; import ReCAPTCHA from "react-google-recaptcha"; import axios from "axios"; interface FormData { name: string; phone: string; email: string; location: string; } interface FormErrors { name?: string; phone?: string; email?: string; location?: string; captcha?: string; } export default function ContactCTA() { const [formData, setFormData] = useState({ name: "", phone: "", email: "", location: "", }); const [captchaToken, setCaptchaToken] = useState(null); const [formErrors, setFormErrors] = useState({}); const [alert, setAlert] = useState<{ show: boolean; type: string; message: string }>({ show: false, type: "", message: "", }); const [isSubmitting, setIsSubmitting] = useState(false); const handleChange = (e: ChangeEvent) => { const { name, value } = e.target; setFormData((prev) => ({ ...prev, [name]: value })); // Clear error when user types if (formErrors[name as keyof FormErrors]) { setFormErrors(prev => ({ ...prev, [name]: undefined })); } }; const handleCaptchaChange = (token: string | null) => { setCaptchaToken(token); if (token && formErrors.captcha) { setFormErrors(prev => ({ ...prev, captcha: undefined })); } }; const handleSubmit = async (e: FormEvent) => { e.preventDefault(); const errors: FormErrors = {}; if (!formData.name.trim()) errors.name = "Name is required."; if (!formData.phone.trim()) errors.phone = "Phone number is required."; if (!formData.email.trim()) errors.email = "Email is required."; if (!formData.location) errors.location = "Please select a location."; if (!captchaToken) errors.captcha = "Please verify the CAPTCHA."; setFormErrors(errors); if (Object.keys(errors).length > 0) return; setIsSubmitting(true); const emailData = { name: formData.name, phone: formData.phone, email: formData.email, subject: `New Inquiry from ${formData.name} - ${formData.location}`, message: `Name: ${formData.name}
Phone: ${formData.phone}
Email: ${formData.email}
Location Interest: ${formData.location}`, to: "hello@skyandsoil.com", senderName: "Sky and Soil Contact Form", recaptchaToken: captchaToken, }; try { const res = await axios.post("https://mailserver.metatronnest.com/send", emailData, { headers: { "Content-Type": "application/json" }, }); setAlert({ show: true, type: "success", message: res?.data?.message || "Message sent successfully! We will contact you soon.", }); setFormData({ name: "", phone: "", email: "", location: "" }); setCaptchaToken(null); setFormErrors({}); } catch (error) { setAlert({ show: true, type: "danger", message: "Failed to send message. Please try again later.", }); } finally { setIsSubmitting(false); } }; useEffect(() => { if (alert.show) { const timer = setTimeout(() => { setAlert(prev => ({ ...prev, show: false })); }, 5000); return () => clearTimeout(timer); } }, [alert.show]); return (
{/* Left Side - Form */}

Ready to Visit Aurora Springs?

Schedule a private tour or request a call back from our relationship manager.

{alert.show && (
{alert.message}
)}
{formErrors.name && {formErrors.name}}
{formErrors.phone && {formErrors.phone}}
{formErrors.email && {formErrors.email}}
{formErrors.location && {formErrors.location}}
{formErrors.captcha && {formErrors.captcha}}

We respect your privacy. No spam, ever.

{/* Right Side - Image */}
Luxury Interior
); }