'use client' import { useState } from 'react' interface LeadFormBlockProps { title?: string | null subtitle?: string | null formSource?: string | null showPhone?: boolean | null showEmail?: boolean | null ctaLabel?: string | null successMessage?: string | null } export function LeadFormBlockComponent({ title, subtitle, formSource, showPhone, showEmail, ctaLabel, successMessage, }: LeadFormBlockProps) { const [name, setName] = useState('') const [phone, setPhone] = useState('') const [email, setEmail] = useState('') const [submitted, setSubmitted] = useState(false) const [loading, setLoading] = useState(false) async function handleSubmit(e: React.FormEvent) { e.preventDefault() setLoading(true) try { await fetch('/api/leads', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ name, phone: showPhone ? phone : undefined, email: showEmail ? email : undefined, source: formSource ?? 'block-form', }), }) } catch { /* noop */ } setSubmitted(true) setLoading(false) } return (
{title && (

{title}

)} {subtitle &&

{subtitle}

} {submitted ? (

{successMessage ?? "Дякуємо! Ми зв'яжемося з вами найближчим часом."}

) : (
setName(e.target.value)} placeholder="Ваше ім'я" className="w-full rounded-[10px] border border-[#272727]/20 px-5 py-3 text-[16px] text-[#272727] outline-none focus:ring-2 focus:ring-[#f28b4a]" /> {showPhone && ( setPhone(e.target.value)} placeholder="Телефон" className="w-full rounded-[10px] border border-[#272727]/20 px-5 py-3 text-[16px] text-[#272727] outline-none focus:ring-2 focus:ring-[#f28b4a]" /> )} {showEmail && ( setEmail(e.target.value)} placeholder="Email" className="w-full rounded-[10px] border border-[#272727]/20 px-5 py-3 text-[16px] text-[#272727] outline-none focus:ring-2 focus:ring-[#f28b4a]" /> )}
)}
) }