"use client" import { useActionState, useEffect, useId, useRef } from "react" import { CircleAlert, CircleCheck } from "lucide-react" import { Button, ButtonArrow } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" import { Textarea } from "@/components/ui/textarea" import { play } from "@/lib/sound" import { cn } from "@/lib/utils" import { CONTACT_PREFILL_EVENT } from "@/modules/landingPage/lib/contact-prefill" import { initialContactState, type ContactField, } from "@/modules/landingPage/schema/contact-schema" import { submitContact } from "@/modules/landingPage/server/contact-action" export function ContactForm() { const [state, formAction, pending] = useActionState( submitContact, initialContactState ) const id = useId() const messageRef = useRef(null) useEffect(() => { if (state.status === "success") play("confirm") }, [state]) // Text handed over by other sections, e.g. the price calculator useEffect(() => { const onPrefill = (event: Event) => { const el = messageRef.current if (!el) return const text = (event as CustomEvent).detail // Keep whatever the visitor already wrote el.value = el.value.trim() ? `${text} ${el.value}` : text // The page is still scrolling there, so focus without jumping el.focus({ preventScroll: true }) el.setSelectionRange(el.value.length, el.value.length) } window.addEventListener(CONTACT_PREFILL_EVENT, onPrefill) return () => window.removeEventListener(CONTACT_PREFILL_EVENT, onPrefill) }, []) const fieldId = (field: ContactField) => `${id}-${field}` const errorId = (field: ContactField) => `${id}-${field}-error` const errorFor = (field: ContactField) => state.fieldErrors?.[field]?.[0] // Wires label, error text and aria attributes together for one field const fieldProps = (field: ContactField) => ({ id: fieldId(field), name: field, "aria-invalid": errorFor(field) ? true : undefined, "aria-describedby": errorFor(field) ? errorId(field) : undefined, }) if (state.status === "success") { return (

{state.message}

Du bekommst eine Antwort von einem Menschen, nicht von einem Ticketsystem.

) } return (