import { useState } from 'preact/hooks'; import { submitLead } from './api'; import { IconSpan } from './icon-span'; import { useWidgetStore } from './store'; export const Contact = () => { const { visitor, updateVisitor, captchaToken } = useWidgetStore(); const [interest, setInterest] = useState(''); const [message, setMessage] = useState(''); const [loading, setLoading] = useState(false); const [success, setSuccess] = useState(false); const [error, setError] = useState(''); const handleSubmit = async () => { if (!visitor.name.trim() || !visitor.phone.trim()) return; setLoading(true); setError(''); try { await submitLead({ name: visitor.name.trim(), phone: visitor.phone.trim(), interest: interest.trim() || undefined, message: message.trim() || undefined, captchaToken, }); setSuccess(true); } catch { setError('Submission failed. Please try again.'); } finally { setLoading(false); } }; if (success) { return (
Thank you!
An agent will call you shortly on {visitor.phone}.
We typically respond within 30 minutes during business hours.
); } return (
Get in touch
Leave your details and we'll call you back.
{error &&
{error}
}
updateVisitor({ name: e.target.value })} />
updateVisitor({ phone: e.target.value })} />