"use client"; import React, { useEffect, useState } from "react"; import { useParams } from "next/navigation"; import { Navbar } from "@/components/layout/Navbar"; import { Footer } from "@/components/layout/Footer"; import { apiFetch } from "@/lib/api"; import { formatDate } from "@/lib/date"; import { MessageSquareHeart, CheckCircle2 } from "lucide-react"; import { ExtraFieldInput, isExtraFieldType } from "@/components/shared/FormFieldExtras"; import { errorMessage } from "@/lib/utils"; type Field = { id: string; type: string; label: string; isRequired: boolean; helpText: string | null; options: unknown }; type FeedbackInfo = { event: { title: string; startDate: string }; name: string; intro: string | null; anonymous: boolean; responded: boolean; fields: Field[]; }; const inputCls = "w-full border rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-brand-400"; /** Public page an attendee opens from their post-event feedback email or WhatsApp. */ export default function FeedbackPage() { const params = useParams<{ token: string }>(); const token = params?.token; const [info, setInfo] = useState(null); const [loadError, setLoadError] = useState(null); const [answers, setAnswers] = useState>({}); const [error, setError] = useState(null); const [busy, setBusy] = useState(false); const [done, setDone] = useState(false); useEffect(() => { if (!token) return; apiFetch(`/api/feedback/public/${encodeURIComponent(token)}`) .then(setInfo) .catch(e => setLoadError(e?.message || "This feedback link isn't valid.")); }, [token]); const set = (id: string, v: string) => setAnswers(prev => ({ ...prev, [id]: v })); const submit = async (e: React.FormEvent) => { e.preventDefault(); setBusy(true); setError(null); try { await apiFetch(`/api/feedback/public/${encodeURIComponent(token!)}`, { method: "POST", body: { answers } }); setDone(true); } catch (err) { setError(errorMessage(err) || "Couldn't send your feedback"); } finally { setBusy(false); } }; return (

{info ? `How was ${info.event.title}?` : "Feedback"}

{info &&

{formatDate(new Date(info.event.startDate))}

}
{loadError &&
{loadError}
} {info && (done || info.responded) && (
Thank you{info.name ? `, ${info.name.split(" ")[0]}` : ""}!

{done ? "Your feedback has been sent." : "You've already given feedback for this event."} It really helps us plan the next one.

)} {info && !done && !info.responded && (
{info.intro &&

{info.intro}

}

{info.anonymous ? "Your answers are anonymous — they aren't linked to your name." : `Answering as ${info.name}.`}

{info.fields.map(f => (
{f.type === "statement" ? (

{f.label}

) : f.type === "paragraph" ? (
{f.label}
{f.helpText &&
{f.helpText}
}
) : ( <> {isExtraFieldType(f.type) ? ( set(f.id, v)} /> ) : f.type === "yes_no" ? (
{["yes", "no"].map(v => ( ))}
) : f.type === "numeric" ? ( set(f.id, e.target.value)} /> ) : f.type === "date" ? ( set(f.id, e.target.value)} /> ) : (