'use client' import { useState, useTransition } from 'react' import { getUtmParams } from '@/lib/utm' const FONT = 'var(--font-montserrat, Montserrat), sans-serif' const GROUP_TYPES = [ { value: 'school', label: 'Шкільна екскурсія' }, { value: 'kindergarten', label: 'Дитячий садок' }, { value: 'corporate', label: 'Корпоратив' }, { value: 'other', label: 'Інше' }, ] export function GroupRequestForm() { const [name, setName] = useState('') const [phone, setPhone] = useState('') const [email, setEmail] = useState('') const [groupSize, setGroupSize] = useState('') const [preferredDate, setPreferredDate] = useState('') const [groupType, setGroupType] = useState('') const [message, setMessage] = useState('') const [success, setSuccess] = useState(false) const [error, setError] = useState(null) const [isPending, startTransition] = useTransition() function handleSubmit(e: React.FormEvent) { e.preventDefault() setError(null) startTransition(async () => { try { const utm = getUtmParams() const res = await fetch('/api/leads', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ name, phone, email: email || undefined, formSource: 'group-request', groupSize: groupSize ? Number(groupSize) : undefined, preferredDate: preferredDate || undefined, message: [groupType ? `Тип групи: ${groupType}` : '', message].filter(Boolean).join('\n') || undefined, ...utm, }), }) const data = (await res.json()) as { ok?: boolean; error?: string } if (!res.ok) { setError(data.error ?? 'Щось пішло не так. Спробуйте ще раз.') return } setSuccess(true) } catch { setError("Помилка мережі. Перевірте з'єднання та спробуйте ще раз.") } }) } if (success) { return (

Заявку отримано!

Менеджер зателефонує вам протягом 30 хвилин для уточнення деталей.

) } return (
setName(e.target.value)} placeholder="Іван Іванов" className={INPUT_CLS} style={{ fontFamily: FONT }} /> setPhone(e.target.value)} placeholder="+38 (0__) ___-__-__" className={INPUT_CLS} style={{ fontFamily: FONT }} /> setEmail(e.target.value)} placeholder="your@email.com" className={INPUT_CLS} style={{ fontFamily: FONT }} /> setGroupSize(e.target.value)} placeholder="30" className={INPUT_CLS} style={{ fontFamily: FONT }} /> setPreferredDate(e.target.value)} className={INPUT_CLS} style={{ fontFamily: FONT }} />