"use client"; import React, { useState } from "react"; import "react-phone-number-input/style.css"; import PhoneInput from "react-phone-number-input"; import { useToast } from "@/lib/toast-hook"; export default function ReportContent() { const { showLoading, dismissToast, showSuccess, showError } = useToast(); const [formData, setFormData] = useState({ name: "", emailAddress: "", phoneNumber: "", subject: "", message: "", checkbox: false, }); const handleChange = (e) => { const { name, value, type, checked } = e.target; setFormData((prevState) => ({ ...prevState, [name]: type === "checkbox" ? checked : value, })); }; const handlePhoneChange = (value) => { setFormData((prevState) => ({ ...prevState, phoneNumber: value, })); }; const handleSubmit = async (e) => { const loadingToastId = showLoading("Submitting form..."); e.preventDefault(); try { const response = await fetch("/api/contact-send", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(formData), }); if (response.ok) { dismissToast(loadingToastId); showSuccess("Your form has been successfully submitted."); document.cookie = `prospectClient=true; path=/; max-age=31536000`; } else { dismissToast(loadingToastId); showError( error instanceof Error ? error.message : "Something went wrong" ); throw new Error("Form submission failed"); } } catch (error) { console.error("Error:", error); dismissToast(loadingToastId); showError( error instanceof Error ? error.message : "Something went wrong" ); } }; return (