diff --git a/src/App.tsx b/src/App.tsx index 78654f8..65f0c5e 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -9,6 +9,7 @@ import ResetPassword from "./pages/ResetPassword"; import Profile from "./pages/Profile"; import Account from "./pages/Account"; import AccountConfirmation from "./pages/AccountConfirmation"; +import Contact from "./pages/Contact"; import { useCartSync } from "./hooks/useCartSync"; const queryClient = new QueryClient(); @@ -20,6 +21,7 @@ function AppContent() { } /> + } /> } /> } /> } /> diff --git a/src/components/Footer.tsx b/src/components/Footer.tsx index c2d8010..ce5b6e6 100644 --- a/src/components/Footer.tsx +++ b/src/components/Footer.tsx @@ -25,7 +25,7 @@ const Footer = () => { Vårt sortiment - + Kontakta oss diff --git a/src/pages/Contact.tsx b/src/pages/Contact.tsx new file mode 100644 index 0000000..16c1f54 --- /dev/null +++ b/src/pages/Contact.tsx @@ -0,0 +1,181 @@ +import { useState } from "react"; +import { z } from "zod"; +import { useNavigate } from "react-router-dom"; +import Header from "@/components/Header"; +import Footer from "@/components/Footer"; +import { Button } from "@/components/ui/button"; +import { Input } from "@/components/ui/input"; +import { Textarea } from "@/components/ui/textarea"; +import { Label } from "@/components/ui/label"; +import { toast } from "sonner"; +import { supabase } from "@/integrations/supabase/client"; +import { Send, ArrowLeft } from "lucide-react"; + +const contactSchema = z.object({ + name: z.string().trim().min(1, "Namn krävs").max(100, "Max 100 tecken"), + email: z.string().trim().email("Ogiltig e-postadress").max(255, "Max 255 tecken"), + company: z.string().trim().max(100, "Max 100 tecken").optional(), + message: z.string().trim().min(1, "Meddelande krävs").max(2000, "Max 2000 tecken"), +}); + +type ContactForm = z.infer; + +const Contact = () => { + const navigate = useNavigate(); + const [form, setForm] = useState({ + name: "", + email: "", + company: "", + message: "", + }); + const [isSubmitting, setIsSubmitting] = useState(false); + const [isSubmitted, setIsSubmitted] = useState(false); + + const handleSubmit = async (e: React.FormEvent) => { + e.preventDefault(); + + const validation = contactSchema.safeParse(form); + if (!validation.success) { + toast.error(validation.error.errors[0].message); + return; + } + + setIsSubmitting(true); + + try { + const { error } = await supabase.functions.invoke("send-contact-email", { + body: { + name: form.name, + email: form.email, + company: form.company || "", + message: form.message, + }, + }); + + if (error) { + throw error; + } + + setIsSubmitted(true); + toast.success("Tack för ditt meddelande!"); + } catch (error: any) { + console.error("Contact form error:", error); + toast.error("Något gick fel. Försök igen senare."); + } finally { + setIsSubmitting(false); + } + }; + + return ( +
+
+
+
+ {/* Back link */} + + + {/* Header */} +
+
+

+ Kontakta oss +

+

+ Har du frågor om våra abonnemang eller vill veta mer? Hör av dig! +

+
+ + {isSubmitted ? ( +
+
+ +
+

+ Tack för ditt meddelande! +

+

+ Vi återkommer till dig så snart som möjligt. +

+ +
+ ) : ( +
+
+ + setForm({ ...form, name: e.target.value })} + placeholder="Ditt namn" + required + /> +
+ +
+ + setForm({ ...form, email: e.target.value })} + placeholder="din@epost.se" + required + /> +
+ +
+ + setForm({ ...form, company: e.target.value })} + placeholder="Ditt företag (valfritt)" + /> +
+ +
+ +