diff --git a/components/contact-section.tsx b/components/contact-section.tsx index 11f8468..29be95a 100644 --- a/components/contact-section.tsx +++ b/components/contact-section.tsx @@ -1,11 +1,54 @@ "use client"; +import { useState } from "react"; import { useInView } from "@/hooks/use-in-view"; import { Button } from "@/components/ui/button"; -import { Mail, Phone, MapPin, Zap } from "lucide-react"; +import { Mail, Phone, MapPin, Zap, Check, AlertCircle, Loader2 } from "lucide-react"; + +const CONTACT_API = "https://email-relay.jeffemmett.com/contact"; export function ContactSection() { const { ref, isInView } = useInView(0.1); + const [status, setStatus] = useState<"idle" | "sending" | "sent" | "error">("idle"); + const [errorMsg, setErrorMsg] = useState(""); + + async function handleSubmit(e: React.FormEvent) { + e.preventDefault(); + setStatus("sending"); + setErrorMsg(""); + + const form = e.currentTarget; + const data = new FormData(form); + + try { + const res = await fetch(CONTACT_API, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ + name: data.get("name"), + email: data.get("email"), + subject: "PortaPower Event Inquiry", + message: data.get("message") || "", + fields: { + "Festival / Event": data.get("festival") || "Not specified", + "Expected Attendance": data.get("attendees") || "Not specified", + }, + }), + }); + + if (res.ok) { + setStatus("sent"); + form.reset(); + } else { + const body = await res.json().catch(() => ({})); + setErrorMsg(body.error || "Something went wrong. Please try again."); + setStatus("error"); + } + } catch { + setErrorMsg("Network error. Please check your connection and try again."); + setStatus("error"); + } + } return (
@@ -34,10 +77,27 @@ export function ContactSection() { className={`${isInView ? "animate-fade-in-up" : "opacity-0"}`} style={{ animationDelay: "0.2s" }} > + {status === "sent" ? ( +
+
+ +
+

Message Sent!

+

+ Thanks for reaching out. We'll get back to you shortly. +

+ +
+ ) : (
@@ -128,11 +188,23 @@ export function ContactSection() { />
-
+ )} {/* Contact info */}