Found by the manual e2e of the production build: - paste guests preview counted an array, so it read "[object Object]" and never offered Save guests; - New event and Add user errors now clear when the field is fixed; - "Send to all unsent" says when nothing was unsent; - the check-in lookup shows an error on an empty submit and carries the typed email or mobile into the walk-in form; - invitation emails sent over Pub/Sub now save their recipient's link, so the Emails page shows the recipient. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
93 lines
4.2 KiB
TypeScript
93 lines
4.2 KiB
TypeScript
"use client";
|
|
|
|
import { useEffect, useState, type FormEvent } from "react";
|
|
import { useParams } from "next/navigation";
|
|
import { AlertCircle, CheckCircle2, Clock, Loader2 } from "lucide-react";
|
|
import { Button } from "@/app/components/ui/button";
|
|
import { Input } from "@/app/components/ui/input";
|
|
import { Label } from "@/app/components/ui/label";
|
|
import { VisitorCard, VisitorState } from "@/app/components/registration/VisitorCard";
|
|
import { RegistrationForm, apiData, failMessage } from "@/app/components/registration/RegistrationForm";
|
|
import { getCheckin, lookupCheckin, registerWalkIn, type CheckinState } from "@/app/lib/services/publicInvite";
|
|
import { useT } from "@/app/lib/i18n/MessagesProvider";
|
|
|
|
type Phase = "loading" | "inactive" | "error" | "lookup" | "form" | "welcome" | "done";
|
|
|
|
// Public event check-in page (QR at the venue): a known person is looked up by mobile or email, anyone else registers as a walk-in.
|
|
export default function CheckinPage() {
|
|
const t = useT();
|
|
const { token } = useParams<{ token: string }>();
|
|
const [phase, setPhase] = useState<Phase>("loading");
|
|
const [state, setState] = useState<CheckinState | null>(null);
|
|
const [value, setValue] = useState("");
|
|
const [firstName, setFirstName] = useState("");
|
|
const [error, setError] = useState<string | null>(null);
|
|
const [busy, setBusy] = useState(false);
|
|
|
|
useEffect(() => {
|
|
getCheckin(token)
|
|
.then((s) => {
|
|
setState(s);
|
|
setPhase("lookup");
|
|
})
|
|
.catch((err) => {
|
|
if (apiData(err).code === "CODE_INACTIVE") setPhase("inactive");
|
|
else {
|
|
setError(apiData(err).code === "TOO_MANY" ? t("InviteTooMany") : t("RegLoadFailed"));
|
|
setPhase("error");
|
|
}
|
|
});
|
|
}, [token, t]);
|
|
|
|
async function lookup(e: FormEvent) {
|
|
e.preventDefault();
|
|
if (!value.trim()) {
|
|
setError(t("RegContactRequired"));
|
|
return;
|
|
}
|
|
setBusy(true);
|
|
setError(null);
|
|
try {
|
|
const r = await lookupCheckin(token, value.trim());
|
|
if (r.result === "CHECKED_IN") {
|
|
setFirstName(r.firstName);
|
|
setPhase("welcome");
|
|
} else setPhase("form");
|
|
} catch (err) {
|
|
if (apiData(err).code === "CODE_INACTIVE") setPhase("inactive");
|
|
else setError(failMessage(t, err, "InviteTooMany"));
|
|
} finally {
|
|
setBusy(false);
|
|
}
|
|
}
|
|
|
|
const open = state?.state === "OPEN" ? state : null;
|
|
const alone = (icon: typeof Clock, heading: string, role: "status" | "alert", tone?: "error", iconClassName?: string) => (
|
|
<VisitorCard><VisitorState h1 icon={icon} heading={heading} role={role} tone={tone} iconClassName={iconClassName} /></VisitorCard>
|
|
);
|
|
if (phase === "loading") return alone(Loader2, t("UiLoading"), "status", undefined, "motion-safe:animate-spin");
|
|
if (phase === "inactive") return alone(AlertCircle, t("RegInactive"), "alert");
|
|
if (phase === "error" || !state) return alone(AlertCircle, error ?? t("RegLoadFailed"), "alert", "error");
|
|
if (!open) return alone(Clock, state.state === "NOT_YET" ? t("ChkNotYet", { date: state.startDate }) : t("ChkEnded"), "status");
|
|
|
|
let body;
|
|
if (phase === "welcome") body = <VisitorState icon={CheckCircle2} heading={firstName ? t("InviteWelcome", { name: firstName }) : t("InviteWelcomeAnon")} role="status" />;
|
|
else if (phase === "done") body = <VisitorState icon={CheckCircle2} heading={t("ChkDone", { event: open.eventName })} role="status" />;
|
|
else if (phase === "form") {
|
|
body = <RegistrationForm tooManyKey="InviteTooMany" info={open} initial={value.includes("@") ? { email: value.trim() } : { mobile: value.trim() }} submit={(b) => registerWalkIn(token, b)} onDone={() => setPhase("done")} onInactive={() => setPhase("inactive")} />;
|
|
} else {
|
|
body = (
|
|
<form onSubmit={lookup} className="space-y-4" noValidate>
|
|
{error && <p role="alert" className="text-sm text-destructive">{error}</p>}
|
|
<div className="space-y-1.5">
|
|
<Label htmlFor="chk-value">{t("ChkLookup")}</Label>
|
|
<Input id="chk-value" className="h-11" value={value} onChange={(e) => setValue(e.target.value)} disabled={busy} aria-invalid={!!error} />
|
|
</div>
|
|
<Button type="submit" className="h-11 w-full" disabled={busy}>{t("InviteCheckin")}</Button>
|
|
</form>
|
|
);
|
|
}
|
|
|
|
return <VisitorCard event={open}>{body}</VisitorCard>;
|
|
}
|