import { useState } from 'react'; import { csrfHeader } from '@/lib/api'; type Status = 'idle' | 'sending' | 'sent' | 'error'; const ContactPage = () => { const [formData, setFormData] = useState({ name: '', email: '', message: '' }); const [status, setStatus] = useState('idle'); const [error, setError] = useState(''); const handleChange = (e: React.ChangeEvent) => { setFormData({ ...formData, [e.target.name]: e.target.value }); }; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setStatus('sending'); setError(''); try { // csrfHeader() is empty unless security is switched on, so this posts the same as it always // has on a deployment with no identity provider — and keeps working once one is configured, // where an unaccompanied POST would otherwise be rejected. const res = await fetch('/api/contact', { method: 'POST', headers: { 'Content-Type': 'application/json', ...csrfHeader() }, body: JSON.stringify(formData), }); const data = await res.json(); if (!res.ok) throw new Error(data.error || 'Could not send the message.'); setStatus('sent'); setFormData({ name: '', email: '', message: '' }); } catch (err) { // Never claim success we did not get. Tell them, and give them the phone number. setStatus('error'); setError(err instanceof Error ? err.message : 'Could not send the message.'); } }; return (
{/* Page header */}

Contact us

{/* Contact Form Section */}

Get in touch

Or call us: (309) 701-0660