import SEO from '@/components/SEO' import { useState } from 'react' import { toast } from 'sonner' import { Button } from '@/components/ui/Button' import { Input } from '@/components/ui/Input' import { Textarea } from '@/components/ui/Textarea' import { Select } from '@/components/ui/Select' import RecaptchaPlaceholder from '@/components/RecaptchaPlaceholder' import { submitLead } from '@/lib/api' import { useDebounce } from '@/hooks/useDebounce' const Contact = () => { const [formState, setFormState] = useState({ company: '', name: '', email: '', phone: '', zip: '', message: '', service_interest: '', recaptcha_token: '', company_website: '', }) const [errors, setErrors] = useState({ company: '', name: '', email: '', zip: '', message: '', recaptcha_token: '', }) const debouncedErrors = useDebounce(errors, 300) const [isSubmitting, setIsSubmitting] = useState(false) const validateForm = () => { const newErrors = { company: '', name: '', email: '', zip: '', message: '', recaptcha_token: '' } if (!formState.company.trim()) newErrors.company = 'Company name is required' if (!formState.name.trim()) newErrors.name = 'Name is required' if (!formState.zip.trim()) newErrors.zip = 'ZIP code is required' if (!formState.message.trim()) newErrors.message = 'Message is required' const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/ if (!formState.email.trim()) { newErrors.email = 'Email is required' } else if (!emailRegex.test(formState.email)) { newErrors.email = 'Please enter a valid email address' } const hasErrors = Object.values(newErrors).some(error => error !== '') setErrors(newErrors) if (hasErrors) { toast.error('Please fix the errors in the form') return false } return true } const handleSubmit = (e) => { e.preventDefault() if (!validateForm()) return handleSubmitForm() } const handleSubmitForm = async () => { setIsSubmitting(true) try { await submitLead(formState) toast.success("Thanks! We'll be in touch shortly.") setFormState({ company: '', name: '', email: '', phone: '', zip: '', message: '', service_interest: '', recaptcha_token: '', company_website: '' }) setErrors({ company: '', name: '', email: '', zip: '', message: '', recaptcha_token: '' }) } catch (error) { if (error.response?.status === 409) { toast.success("We already have your submission! We'll be in touch.") } else if (error.response?.status === 400 && error.fields) { setErrors(prev => ({ ...prev, ...error.fields })) toast.error('Please fix the errors in the form') } else { toast.error(error.message || 'Failed to submit form. Please try again.') } } finally { setIsSubmitting(false) } } const handleChange = (e) => { const { name, value } = e.target setFormState(prev => ({ ...prev, [name]: value })) if (errors[name]) setErrors(prev => ({ ...prev, [name]: '' })) } const contactDetails = [ { label: 'Phone', icon: ( ), content: (
), }, { label: 'Office', icon: ( ), content: ( 7901 4th St N St. Petersburg, FL 33702 ), }, { label: 'Hours', icon: ( ), content:Mon – Fri: 8:00 AM – 6:00 PM CT
, }, ] const trustPoints = [Tell us about your business and we'll cut through the noise to find what actually works for you.
{item.label}
{item.content}Why Queue North
We typically respond within one business day.