import { useEffect, useState } from "react";
import { Star } from "lucide-react";
import { Link, useSearchParams } from "react-router-dom";
import { HeaderMobile } from "../components/HeaderMobile";
import { LegalFooterLinks } from "../components/marketing/LegalFooterLinks";
import { MobileShell } from "../components/MobileShell";
import { DynamicFeedbackForm } from "../components/DynamicFeedbackForm";
import { useEventRegistrationSettings } from "../hooks/useEventRegistrationSettings";
import { getVisitorFeedbackFormSchema, getVisitorLoginPreview, type VisitorPublicFeedbackForm } from "../lib/api";
import { readStoredVisitorContext } from "../types/visitorContext";
function StarRow({
label,
value,
onChange,
}: {
label: string;
value: number;
onChange: (n: number) => void;
}) {
return (
{label}
{Array.from({ length: 5 }, (_, i) => (
))}
);
}
export function RatingsPage() {
const [searchParams] = useSearchParams();
const formId = searchParams.get("form_id")?.trim() || "";
const urlEventId = searchParams.get("event_id")?.trim() || "";
const ctx = readStoredVisitorContext();
const eventId = urlEventId || ctx?.eventId || "";
const [eventSnapshot, setEventSnapshot] = useState(
ctx?.eventId === eventId && ctx.event ? ctx.event : null,
);
const [schema, setSchema] = useState(null);
const [schemaLoading, setSchemaLoading] = useState(false);
const [schemaErr, setSchemaErr] = useState(null);
const [a, setA] = useState(0);
const [b, setB] = useState(0);
const [c, setC] = useState(0);
useEffect(() => {
if (!eventId) {
setEventSnapshot(null);
return;
}
if (ctx?.eventId === eventId && ctx.event) {
setEventSnapshot(ctx.event);
return;
}
let cancelled = false;
getVisitorLoginPreview(eventId)
.then((ev) => {
if (!cancelled) setEventSnapshot(ev);
})
.catch(() => {
if (!cancelled) setEventSnapshot(null);
});
return () => {
cancelled = true;
};
}, [eventId, ctx?.eventId, ctx?.event]);
useEffect(() => {
if (!formId || !eventId) {
setSchema(null);
setSchemaErr(null);
setSchemaLoading(false);
return;
}
let cancelled = false;
setSchemaLoading(true);
setSchemaErr(null);
getVisitorFeedbackFormSchema(eventId, formId)
.then((s) => {
if (!cancelled) setSchema(s);
})
.catch((e) => {
if (!cancelled) {
setSchema(null);
setSchemaErr(e instanceof Error ? e.message : "Could not load form.");
}
})
.finally(() => {
if (!cancelled) setSchemaLoading(false);
});
return () => {
cancelled = true;
};
}, [formId, eventId]);
const reg = useEventRegistrationSettings(eventSnapshot);
if (!eventId) {
return (
Ratings
Open ratings from your event or session link.
Home
);
}
if (!reg.enableRatings) {
return (
Ratings
Ratings are disabled for this event.
Back to event
);
}
if (formId) {
return (
{schema?.name || "Ratings"}
{schemaLoading ? (
Loading form…
) : schemaErr ? (
{schemaErr}
Back to event
) : schema ? (
) : null}
);
}
return (
Event Ratings
Your Rating
We'd love to hear your thoughts about this event. Your rating helps us improve future
events.
Cancel
);
}