"use client" import { useState } from "react" import { useForm } from "react-hook-form" import { zodResolver } from "@hookform/resolvers/zod" import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { Textarea } from "@/components/ui/textarea" import { Card, CardContent } from "@/components/ui/card" import { Loader2, CheckCircle } from "lucide-react" import { contactFormSchema, ContactFormValues } from "@/lib/schemas" import { submitContactForm } from "@/lib/actions/contact" import { toast } from "sonner" export function ContactForm() { const [isSubmitting, setIsSubmitting] = useState(false) const [isSuccess, setIsSuccess] = useState(false) const form = useForm({ resolver: zodResolver(contactFormSchema), defaultValues: { name: "", surname: "", email: "", phone: "", subject: "", message: "", }, }) async function onSubmit(data: ContactFormValues) { setIsSubmitting(true) try { const response = await submitContactForm(data) if (response.success) { setIsSuccess(true) form.reset() toast.success("Mesajınız başarıyla gönderildi.") } else { toast.error("Hata: " + response.error) } } catch { toast.error("Bir hata oluştu.") } finally { setIsSubmitting(false) } } return ( {isSuccess ? (

Mesajınız Alındı!

En kısa sürede size dönüş yapacağız.

) : (
{form.formState.errors.name &&

{form.formState.errors.name.message}

}
{form.formState.errors.surname &&

{form.formState.errors.surname.message}

}
{form.formState.errors.email &&

{form.formState.errors.email.message}

}
🇹🇷 +90
{ let value = e.target.value.replace(/\D/g, ''); // Remove non-digits if (value.startsWith('90')) value = value.slice(2); // Remove leading 90 if user types it // Format: (5XX) XXX XX XX let formattedValue = ''; if (value.length > 0) formattedValue += '(' + value.substring(0, 3); if (value.length > 3) formattedValue += ') ' + value.substring(3, 6); if (value.length > 6) formattedValue += ' ' + value.substring(6, 8); if (value.length > 8) formattedValue += ' ' + value.substring(8, 10); e.target.value = formattedValue; return e; } })} />
{form.formState.errors.phone &&

{form.formState.errors.phone.message}

}
{form.formState.errors.subject &&

{form.formState.errors.subject.message}

}