'use client'; import { useState } from 'react'; import { Check, Loader2 } from 'lucide-react'; import { submitMultisplitForm } from '@/app/zapytanie-multisplit/actions'; interface Props { productName: string; productSku: string; } export default function MultisplitContactForm({ productName, productSku }: Props) { const [form, setForm] = useState({ name: '', phone: '', email: '', city: '', rooms: '2', message: '', consent: false, }); const [loading, setLoading] = useState(false); const [sent, setSent] = useState(false); const [error, setError] = useState(''); const handle = (e: React.ChangeEvent) => { const { name, value, type } = e.target; setForm(prev => ({ ...prev, [name]: type === 'checkbox' ? (e.target as HTMLInputElement).checked : value, })); }; const submit = async () => { if (!form.name || !form.phone || !form.consent) { setError('Wypełnij wymagane pola i zaznacz zgodę.'); return; } setLoading(true); setError(''); try { let recaptchaToken = ''; if (process.env.NEXT_PUBLIC_RECAPTCHA_SITE_KEY) { recaptchaToken = await (window as any).grecaptcha.execute( process.env.NEXT_PUBLIC_RECAPTCHA_SITE_KEY, { action: 'submit' } ); } const res = await submitMultisplitForm({ name: form.name, phone: form.phone, email: form.email, city: form.city, rooms: form.rooms, message: form.message, consent: form.consent, productName, productSku, recaptchaToken, }); if (res.success) setSent(true); else setError(res.message || 'Błąd wysyłki. Zadzwoń do nas bezpośrednio.'); } catch { setError('Błąd połączenia. Spróbuj ponownie.'); } setLoading(false); }; if (sent) { return (

Zapytanie wysłane!

Oddzwonimy w ciągu 24 godzin z bezpłatną wyceną.

); } return (
{/* Produkt info */}
Zapytanie dotyczy: {productName}