"use client"; import Iconss from "@/components/ui/icons"; import { Mail, Send, WebhookIcon, Bug, Shield } from "lucide-react"; import { zodResolver } from "@hookform/resolvers/zod"; import { useForm } from "react-hook-form"; import { z } from "zod"; import { contactFormSchema } from "@/lib/validations/validation"; import { Button } from "@/components/ui/button"; import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage, } from "@/components/ui/form"; import { Input } from "@/components/ui/input"; import { Textarea } from "@/components/ui/textarea"; import { useToast } from "@/components/ui/use-toast"; import { useState } from "react"; import { Separator } from "@/components/ui/separator"; import { emails } from "@/constants"; import HCaptcha from "@hcaptcha/react-hcaptcha"; const ContactUs = () => { const { toast } = useToast(); const [loading, setLoading] = useState(false); const [showCaptcha, setShowCaptcha] = useState(false); const [captchaToken, setCaptchaToken] = useState(null); const form = useForm>({ resolver: zodResolver(contactFormSchema), defaultValues: { name: "", email: "", message: "", }, }); async function onSubmit(values: z.infer) { if (!captchaToken) { setShowCaptcha(true); return; } setLoading(true); try { const res = await fetch("/api/contact", { method: "POST", body: JSON.stringify({ ...values, captchaToken }), headers: { "Content-Type": "application/json", Accept: "application/json", }, }); if (res.ok) { form.reset(); setCaptchaToken(null); // Reset captcha token after successful submission toast({ description: "Your message has been sent.", }); } else { toast({ title: "Uh oh! Something went wrong.", variant: "destructive", }); } } catch (error) { console.error(error); toast({ title: "Uh oh! Something went wrong.", variant: "destructive", }); } finally { setLoading(false); setShowCaptcha(false); // Hide captcha after submission attempt } } function handleCaptchaVerify(token: string) { setCaptchaToken(token); onSubmit(form.getValues()); // Trigger form submission after captcha is verified } return ( <>

Contact Us

{/* Left contact page */}
( Name )} /> ( Email )} /> ( Message