import React, { useState, useEffect } from 'react'; import { motion } from 'framer-motion'; import { useInView } from 'react-intersection-observer'; import { Phone, Mail, MapPin, Clock, Send, Save } from 'lucide-react'; import ParticlesBackground from '../components/ParticlesBackground'; import { supabase } from '../lib/supabase'; import { toast } from 'react-hot-toast'; import type { Database } from '../lib/database.types'; import { Helmet } from "react-helmet"; import useFormPersistence from '../hooks/useFormPersistence'; import { StorageKeys } from '../utils/localStorage'; import { useUserPreferences } from '../contexts/UserPreferencesContext'; type ContactInfo = Database['public']['Tables']['contact_info']['Row']; interface DisplayContactInfo { icon: JSX.Element; title: string; details: string[]; actions?: { href: string; text: string; isExternal?: boolean; }[]; } const Contact = () => { const [ref, inView] = useInView({ triggerOnce: true, threshold: 0.1, }); const [contactData, setContactData] = useState([]); const [loading, setLoading] = useState(true); const [submitting, setSubmitting] = useState(false); // Get both preferences and addLastVisitedPage from the hook const { preferences, addLastVisitedPage } = useUserPreferences(); // Use form persistence hook instead of useState const { formValues, handleInputChange, clearPersistedData, lastSaved, isSupported } = useFormPersistence({ formId: 'contact-form', storageKey: StorageKeys.CONTACT_FORM, initialValues: { firstName: '', lastName: '', email: '', phone: '', message: '' }, autoSaveDelay: 1000 }); // Handle form submission const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setSubmitting(true); try { // Format message const fullName = `${formValues.firstName} ${formValues.lastName}`; const formattedMessage = ` Contact Form Submission ----------------------- Name: ${fullName} Email: ${formValues.email} Phone: ${formValues.phone} Message: ${formValues.message} `; // Insert into Supabase const { error } = await supabase.from('booking_forms').insert({ form_type: 'Contact', name: fullName, email: formValues.email, phone: formValues.phone, message: formattedMessage, status: 'new' }); if (error) throw error; // Send email notification const { error: emailError } = await supabase.functions.invoke('send-booking-notification', { body: { to: 'amoebaproductionsstudio@gmail.com', subject: `New Contact Form Submission`, name: fullName, email: formValues.email, phone: formValues.phone, message: formattedMessage } }); if (emailError) { console.error('Email notification error:', emailError); // Continue with form completion even if email fails } toast.success('Your message has been sent successfully!'); // Clear form data from localStorage after successful submission clearPersistedData(); } catch (error) { console.error('Error submitting form:', error); toast.error('There was an error sending your message. Please try again.'); } finally { setSubmitting(false); } }; // Add user preference tracking (fixed version) useEffect(() => { if (preferences && !preferences.lastVisitedPages?.includes('/contact')) { addLastVisitedPage('/contact'); } }, [preferences, addLastVisitedPage]); useEffect(() => { const fetchAndFormatContactInfo = async () => { setLoading(true); const { data, error } = await supabase .from('contact_info') .select('*') .maybeSingle(); if (error || !data) { console.error('Error fetching contact info for contact page:', error); setLoading(false); return; } const formatted: DisplayContactInfo[] = []; if (data.phone && data.phone.length > 0) { // Show both phone numbers if available formatted.push({ icon: , title: 'Phone', details: data.phone.slice(0, 2), // Show up to 2 phone numbers actions: data.phone.slice(0, 2).map((num: string) => ({ href: `tel:${num.replace(/\s/g, '')}`, text: num, })), }); } if (data.email && data.email.length > 0) { // Show only one email (the first one) const emailAddress = data.email[0]; formatted.push({ icon: , title: 'Email', details: [emailAddress], // Only show one email address actions: [{ href: `mailto:${emailAddress}`, text: emailAddress, }], }); } if (data.address && data.address.length > 0) { formatted.push({ icon: , title: 'Location', details: data.address, actions: [ { href: 'https://www.google.com/maps/search/?api=1&query=' + encodeURIComponent(data.address.join(', ')), text: 'View on Map', isExternal: true, } ], }); } if (data.business_hours && data.business_hours.length > 0) { formatted.push({ icon: , title: 'Business Hours', details: data.business_hours, }); } setContactData(formatted); setLoading(false); }; fetchAndFormatContactInfo(); }, []); return (
Contact Us | Amoeba Productions - Event Management Company Patna {/* Hero Section */}
Contact Us Get in Touch with Our Team
{/* Main Content */}
{/* Contact Form */}

Send us a Message

{isSupported && lastSaved && (
Autosaved {new Date(lastSaved).toLocaleTimeString()}
)}