"use client"; import { useState } from "react"; import { LandingShell } from "@/components/landing/shell"; import type { LandingProps } from "@/components/landing/types"; import { FEEDBACK_SCALES, feedbackDataSchema } from "@/lib/qr/types/feedback"; export function FeedbackLanding({ data, codeId }: LandingProps) { const { title, question, scale, allowComment, commentLabel, thankYou } = feedbackDataSchema.parse(data); const [note, setNote] = useState(null); const [kommentar, setKommentar] = useState(""); const [laeuft, setLaeuft] = useState(false); const [fertig, setFertig] = useState(false); const [fehler, setFehler] = useState(null); const symbole = FEEDBACK_SCALES[scale].symbols; async function absenden() { if (note === null) return; setLaeuft(true); setFehler(null); try { const response = await fetch("/api/feedback", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ codeId, rating: note, comment: kommentar }), }); if (!response.ok) { const body = await response.json().catch(() => null); setFehler(body?.error ?? "Die Rückmeldung konnte nicht gesendet werden."); return; } setFertig(true); } catch { setFehler( "Die Rückmeldung konnte nicht gesendet werden. Besteht die Verbindung noch?", ); } finally { setLaeuft(false); } } if (fertig) { return (

{thankYou}

); } return (
{question}
{symbole.map((symbol, index) => { const wert = index + 1; const gewaehlt = note !== null && note >= wert; return ( ); })}
{note !== null ? (

{note} von 5

) : null}
{allowComment ? (