From 370c9f4ad0f1e8fd75fde143f7daebbd058a10e1 Mon Sep 17 00:00:00 2001 From: ngqile Date: Tue, 1 Dec 2026 23:14:07 +0800 Subject: [PATCH] feat: visitor pages render every state in the visitor card Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM --- .../refine-visitor-pages-and-shell/tasks.md | 4 +- .../app/c/[token]/page.card.test.tsx | 83 +++++++++++++++++++ solvway-admin-portal/app/c/[token]/page.tsx | 21 +++-- .../RegistrationForm.look.test.tsx | 8 +- .../registration/RegistrationForm.tsx | 17 +--- .../components/registration/VisitorCard.tsx | 9 +- .../app/i/[token]/page.card.test.tsx | 72 ++++++++++++++++ .../app/i/[token]/page.test.tsx | 5 +- solvway-admin-portal/app/i/[token]/page.tsx | 22 ++--- .../app/r/[token]/page.card.test.tsx | 74 +++++++++++++++++ solvway-admin-portal/app/r/[token]/page.tsx | 29 ++++--- 11 files changed, 287 insertions(+), 57 deletions(-) create mode 100644 solvway-admin-portal/app/c/[token]/page.card.test.tsx create mode 100644 solvway-admin-portal/app/i/[token]/page.card.test.tsx create mode 100644 solvway-admin-portal/app/r/[token]/page.card.test.tsx diff --git a/openspec/changes/refine-visitor-pages-and-shell/tasks.md b/openspec/changes/refine-visitor-pages-and-shell/tasks.md index 389d6de..2a3e75f 100644 --- a/openspec/changes/refine-visitor-pages-and-shell/tasks.md +++ b/openspec/changes/refine-visitor-pages-and-shell/tasks.md @@ -21,13 +21,13 @@ Verify for every task: `cd solvway-admin-portal && npx vitest run; echo VITEST=$ - [x] 2.1 `VisitorCard` (ground, card, event header with the company label, the dates and location with icons, footer) and `VisitorState` (icon, heading, text, action). `RegistrationForm` drops its header, adds the "Mobile or email is required" hint (new key in `defaultMessages.ts`), sets the notice as fine print, and aligns the consent row. - Depends on: 1.3 - Scope: `solvway-admin-portal/app/components/registration/**` except `QrCodeItem*`, `solvway-admin-portal/app/lib/i18n/defaultMessages.ts` -- [ ] 2.2 `/r`, `/i` and `/c` render every state inside `VisitorCard`, with `VisitorState` for loading, inactive, error, too many, not yet, ended, thank you, welcome and checked in. Existing behaviour and text stay the same. +- [x] 2.2 `/r`, `/i` and `/c` render every state inside `VisitorCard`, with `VisitorState` for loading, inactive, error, too many, not yet, ended, thank you, welcome and checked in. Existing behaviour and text stay the same. - Depends on: 2.1 - Scope: `solvway-admin-portal/app/r/**`, `solvway-admin-portal/app/i/**`, `solvway-admin-portal/app/c/**` ## 3. Staff screens -- [ ] 3.1 My QR codes as cards: the event name as the title, dates and location, the switched-off badge in the card header, the QR and a wrapping button row. +- [x] 3.1 My QR codes as cards: the event name as the title, dates and location, the switched-off badge in the card header, the QR and a wrapping button row. - Depends on: 2.2 - Scope: `solvway-admin-portal/app/my-qr/**`, `solvway-admin-portal/app/components/registration/QrCodeItem*` - [x] 3.2 Reset password uses the login page's two-column frame. Remove the stale brown and gold comments in login. diff --git a/solvway-admin-portal/app/c/[token]/page.card.test.tsx b/solvway-admin-portal/app/c/[token]/page.card.test.tsx new file mode 100644 index 0000000..b8e673a --- /dev/null +++ b/solvway-admin-portal/app/c/[token]/page.card.test.tsx @@ -0,0 +1,83 @@ +import { describe, it, expect, vi, beforeEach } from "vitest"; +import { render, screen } from "@testing-library/react"; +import userEvent from "@testing-library/user-event"; + +const mocks = vi.hoisted(() => ({ getCheckin: vi.fn(), lookupCheckin: vi.fn(), registerWalkIn: vi.fn() })); +vi.mock("@/app/lib/services/publicInvite", () => mocks); +vi.mock("next/navigation", () => ({ useParams: () => ({ token: "chk1" }) })); + +import { ApiError } from "@/app/lib/clientApi"; +import CheckinPage from "./page"; + +const open = { + state: "OPEN", eventName: "Expo 2026", startDate: "2026-12-01", endDate: "2026-12-02", location: "KLCC", companyName: "INS", + notice: { id: 7, textEn: "We keep your data safe.", textMs: "Data anda selamat." }, interests: [], +}; + +beforeEach(() => { + mocks.getCheckin.mockReset().mockResolvedValue(open); + mocks.lookupCheckin.mockReset().mockResolvedValue({ result: "CHECKED_IN", firstName: "Aini" }); + mocks.registerWalkIn.mockReset().mockResolvedValue({}); +}); + +const h1s = () => screen.getAllByRole("heading", { level: 1 }); + +describe("/c visitor card", () => { + it("lookup sits in the card under the event header with one h1", async () => { + render(); + await screen.findByLabelText("Mobile number or email"); + expect(screen.getByText("INS", { selector: "p" })).toBeTruthy(); + expect(h1s().map((h) => h.textContent)).toEqual(["Expo 2026"]); + expect(screen.getByText("2026-12-01 - 2026-12-02")).toBeTruthy(); + expect(document.querySelectorAll("main").length).toBe(1); + }); + + it("walk-in form shows the notice before consent under one h1", async () => { + const user = userEvent.setup(); + mocks.lookupCheckin.mockResolvedValue({ result: "FORM" }); + render(); + await user.type(await screen.findByLabelText("Mobile number or email"), "0123456789"); + await user.click(screen.getByRole("button", { name: "Check in" })); + await screen.findByLabelText("Your name"); + const notice = screen.getByText("We keep your data safe."); + expect(notice.compareDocumentPosition(screen.getByLabelText(/I agree to INS/)) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy(); + expect(h1s().map((h) => h.textContent)).toEqual(["Expo 2026"]); + }); + + it("welcome shows an icon and heading under the event header", async () => { + const user = userEvent.setup(); + render(); + await user.type(await screen.findByLabelText("Mobile number or email"), "0123456789"); + await user.click(screen.getByRole("button", { name: "Check in" })); + const s = await screen.findByRole("status"); + expect(s.querySelector("svg")).toBeTruthy(); + expect(screen.getByRole("heading", { level: 2 }).textContent).toBe("Welcome, Aini. You're checked in."); + expect(h1s().map((h) => h.textContent)).toEqual(["Expo 2026"]); + }); + + it("not yet and ended have an icon and the heading as the only h1", async () => { + mocks.getCheckin.mockResolvedValue({ state: "NOT_YET", startDate: "2026-12-01" }); + const { unmount } = render(); + const s = await screen.findByRole("status"); + expect(s.querySelector("svg")).toBeTruthy(); + expect(h1s().map((h) => h.textContent)).toEqual(["Check-in opens on 2026-12-01."]); + unmount(); + mocks.getCheckin.mockResolvedValue({ state: "ENDED", startDate: "2026-12-01" }); + render(); + await screen.findByText("This event has ended."); + expect(h1s().length).toBe(1); + expect(document.querySelectorAll("main").length).toBe(1); + }); + + it("inactive and load error are alerts with one h1 and no event details", async () => { + mocks.getCheckin.mockRejectedValue(new ApiError("x", 404, { code: "CODE_INACTIVE" })); + const { unmount } = render(); + expect((await screen.findByRole("alert")).querySelector("svg")).toBeTruthy(); + expect(h1s().map((h) => h.textContent)).toEqual(["This code is no longer active."]); + unmount(); + mocks.getCheckin.mockRejectedValue(new ApiError("x", 500, {})); + render(); + await screen.findByRole("alert"); + expect(h1s().length).toBe(1); + }); +}); diff --git a/solvway-admin-portal/app/c/[token]/page.tsx b/solvway-admin-portal/app/c/[token]/page.tsx index 9e22938..d25d82d 100644 --- a/solvway-admin-portal/app/c/[token]/page.tsx +++ b/solvway-admin-portal/app/c/[token]/page.tsx @@ -2,9 +2,11 @@ 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"; @@ -57,19 +59,22 @@ export default function CheckinPage() { } const open = state?.state === "OPEN" ? state : null; + const alone = (icon: typeof Clock, heading: string, role: "status" | "alert", tone?: "error") => ( + + ); + if (phase === "loading") return alone(Loader2, t("UiLoading"), "status"); + if (phase === "inactive") return alone(AlertCircle, t("RegInactive"), "alert"); + if (phase === "error" || !state) return alone(AlertCircle, error ?? "", "alert", "error"); + if (!open) return alone(Clock, state.state === "NOT_YET" ? t("ChkNotYet", { date: state.startDate }) : t("ChkEnded"), "status"); + let body; - if (phase === "loading") body =

{t("UiLoading")}

; - else if (phase === "inactive") body =

{t("RegInactive")}

; - else if (phase === "error" || !state) body =

{error}

; - else if (!open) body =

{state.state === "NOT_YET" ? t("ChkNotYet", { date: state.startDate }) : t("ChkEnded")}

; - else if (phase === "welcome") body =

{firstName ? t("InviteWelcome", { name: firstName }) : t("InviteWelcomeAnon")}

; - else if (phase === "done") body =

{t("ChkDone", { event: open.eventName })}

; + if (phase === "welcome") body = ; + else if (phase === "done") body = ; else if (phase === "form") { body = registerWalkIn(token, b)} onDone={() => setPhase("done")} onInactive={() => setPhase("inactive")} />; } else { body = (
-

{open.eventName}

{error &&

{error}

}
@@ -80,5 +85,5 @@ export default function CheckinPage() { ); } - return
{body}
; + return {body}; } diff --git a/solvway-admin-portal/app/components/registration/RegistrationForm.look.test.tsx b/solvway-admin-portal/app/components/registration/RegistrationForm.look.test.tsx index 8f6461f..c2bd917 100644 --- a/solvway-admin-portal/app/components/registration/RegistrationForm.look.test.tsx +++ b/solvway-admin-portal/app/components/registration/RegistrationForm.look.test.tsx @@ -10,17 +10,17 @@ const props = { info, submit: async () => undefined, onDone: () => {}, onInactiv const wrap = (ui: React.ReactElement) => render(ui); describe("RegistrationForm look", () => { - it("hides its own header when header is false", () => { - wrap(); + it("renders no heading of its own: the visitor card carries the event header", () => { + wrap(); expect(screen.queryByRole("heading", { level: 1 })).toBeNull(); }); it("links a contact hint to the mobile field", () => { - wrap(); + wrap(); const hint = screen.getByText("Mobile or email is required"); expect(screen.getByLabelText("Mobile number").getAttribute("aria-describedby")).toBe(hint.id); }); it("shows the notice as fine print in both languages", () => { - wrap(); + wrap(); expect(screen.getByText("English text").parentElement?.className).toContain("text-muted-foreground"); expect(screen.getByText("Teks Melayu")).toBeTruthy(); }); diff --git a/solvway-admin-portal/app/components/registration/RegistrationForm.tsx b/solvway-admin-portal/app/components/registration/RegistrationForm.tsx index e39068b..102bcb6 100644 --- a/solvway-admin-portal/app/components/registration/RegistrationForm.tsx +++ b/solvway-admin-portal/app/components/registration/RegistrationForm.tsx @@ -30,10 +30,6 @@ export function failMessage(t: (k: string) => string, err: unknown, tooMany = "R } interface Props { - /** Heading text; the event name when omitted. */ - title?: string; - /** Render the event header (default). Pages inside a VisitorCard pass false: the card shows it. */ - header?: boolean; /** i18n key for the too-many message (default RegTooMany, the /r wording). */ tooManyKey?: string; info: RegistrationInfo; @@ -46,8 +42,9 @@ interface Props { onInactive: () => void; } -// The visitor registration form shared by /r, /i and /c: event header, fields, bilingual privacy notice and consent. -export function RegistrationForm({ title, header = true, tooManyKey, info, initial, submit, onDone, onInactive }: Props) { +// The visitor registration form shared by /r, /i and /c: fields, bilingual privacy notice and consent. +// The event header comes from the VisitorCard around it. +export function RegistrationForm({ tooManyKey, info, initial, submit, onDone, onInactive }: Props) { const t = useT(); const [form, setForm] = useState({ ...EMPTY, ...initial }); const [errors, setErrors] = useState>({}); @@ -99,14 +96,6 @@ export function RegistrationForm({ title, header = true, tooManyKey, info, initi return ( - {header && ( -
-

{title ?? info.eventName}

-

- {info.companyName} | {info.startDate} - {info.endDate} | {info.location} -

-
- )} {formError &&

{formError}

} {field("name", t("RegName"))} {field("mobile", t("RegMobile"), "tel", t("RegContactHint"))} diff --git a/solvway-admin-portal/app/components/registration/VisitorCard.tsx b/solvway-admin-portal/app/components/registration/VisitorCard.tsx index 9da60cc..06701d3 100644 --- a/solvway-admin-portal/app/components/registration/VisitorCard.tsx +++ b/solvway-admin-portal/app/components/registration/VisitorCard.tsx @@ -38,16 +38,19 @@ interface StateProps { action?: ReactNode; role?: "status" | "alert"; tone?: "default" | "error"; + /** The heading is the page's h1: for states shown without the card's event header. */ + h1?: boolean; } -// A message inside the card (thanks, inactive, closed). Always h2: the card's event header carries the h1. -export function VisitorState({ icon: Icon, heading, text, action, role, tone = "default" }: StateProps) { +// A message inside the card (thanks, inactive, closed). h2 under the event header's h1; h1 when the card has no event header. +export function VisitorState({ icon: Icon, heading, text, action, role, tone = "default", h1 }: StateProps) { + const Heading = h1 ? "h1" : "h2"; return (
-

{heading}

+ {heading} {text &&

{text}

} {action}
diff --git a/solvway-admin-portal/app/i/[token]/page.card.test.tsx b/solvway-admin-portal/app/i/[token]/page.card.test.tsx new file mode 100644 index 0000000..20a064e --- /dev/null +++ b/solvway-admin-portal/app/i/[token]/page.card.test.tsx @@ -0,0 +1,72 @@ +import { describe, it, expect, vi, beforeEach } from "vitest"; +import { render, screen } from "@testing-library/react"; +import userEvent from "@testing-library/user-event"; + +const mocks = vi.hoisted(() => ({ getInvite: vi.fn(), submitInvite: vi.fn(), inviteCheckin: vi.fn() })); +vi.mock("@/app/lib/services/publicInvite", () => mocks); +vi.mock("next/navigation", () => ({ useParams: () => ({ token: "inv1" }) })); + +import { ApiError } from "@/app/lib/clientApi"; +import InvitePage from "./page"; + +const info = { + eventName: "Expo 2026", startDate: "2026-12-01", endDate: "2026-12-02", location: "KLCC", companyName: "INS", + notice: { id: 7, textEn: "We keep your data safe.", textMs: "Data anda selamat." }, interests: [], + guest: { name: "Aini Binti", mobile: "", email: "aini@b.co", companyName: "Acme" }, state: "OPEN", +}; + +beforeEach(() => { + mocks.getInvite.mockReset().mockResolvedValue(info); + mocks.submitInvite.mockReset().mockResolvedValue({}); + mocks.inviteCheckin.mockReset().mockResolvedValue({ firstName: "Aini" }); +}); + +const h1s = () => screen.getAllByRole("heading", { level: 1 }); + +describe("/i visitor card", () => { + it("form shows the invited title as the only h1 with the event header and notice before consent", async () => { + render(); + await screen.findByLabelText("Your name"); + expect(h1s().map((h) => h.textContent)).toEqual(["You're invited to Expo 2026"]); + expect(screen.getByText("INS", { selector: "p" })).toBeTruthy(); + expect(screen.getByText("2026-12-01 - 2026-12-02")).toBeTruthy(); + expect(screen.getByText("KLCC")).toBeTruthy(); + const notice = screen.getByText("We keep your data safe."); + expect(notice.compareDocumentPosition(screen.getByLabelText(/I agree to INS/)) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy(); + expect(document.querySelectorAll("main").length).toBe(1); + }); + + it("thank you, registered and checked in show an icon and heading under one h1", async () => { + const user = userEvent.setup(); + render(); + await user.click(await screen.findByRole("button", { name: "Register" })); + const s = await screen.findByRole("status"); + expect(s.querySelector("svg")).toBeTruthy(); + expect(screen.getByRole("heading", { level: 2 }).textContent).toContain("Thank you"); + expect(h1s().length).toBe(1); + }); + + it("check-in day offers the button and welcomes with an icon under one h1", async () => { + const user = userEvent.setup(); + mocks.getInvite.mockResolvedValue({ ...info, state: "CHECKIN" }); + render(); + await user.click(await screen.findByRole("button", { name: "Check in" })); + const s = await screen.findByRole("status"); + expect(s.querySelector("svg")).toBeTruthy(); + expect(screen.getByRole("heading", { level: 2 }).textContent).toBe("Welcome, Aini. You're checked in."); + expect(h1s().map((h) => h.textContent)).toEqual(["Expo 2026"]); + }); + + it("inactive and error have an alert icon, one h1 and no event details", async () => { + mocks.getInvite.mockRejectedValue(new ApiError("x", 404, { code: "INVITE_INACTIVE" })); + const { unmount } = render(); + expect((await screen.findByRole("alert")).querySelector("svg")).toBeTruthy(); + expect(h1s().map((h) => h.textContent)).toEqual(["This invitation is no longer active."]); + expect(screen.queryByText("Expo 2026")).toBeNull(); + unmount(); + mocks.getInvite.mockRejectedValue(new ApiError("x", 500, {})); + render(); + await screen.findByRole("alert"); + expect(h1s().length).toBe(1); + }); +}); diff --git a/solvway-admin-portal/app/i/[token]/page.test.tsx b/solvway-admin-portal/app/i/[token]/page.test.tsx index 3b65f66..6e1b215 100644 --- a/solvway-admin-portal/app/i/[token]/page.test.tsx +++ b/solvway-admin-portal/app/i/[token]/page.test.tsx @@ -33,7 +33,10 @@ describe("/i/[token] invite page", () => { expect((screen.getByLabelText("Company") as HTMLInputElement).value).toBe("Acme"); expect(screen.getByText("Data anda selamat.")).toBeTruthy(); expect(screen.getByRole("heading", { level: 1 }).textContent).toBe("You're invited to Expo 2026"); - expect(screen.getByText(/INS \| 2026-12-01 - 2026-12-02 \| KLCC/)).toBeTruthy(); + // refine-visitor-pages-and-shell: the card header shows company, dates and location on their own lines. + expect(screen.getByText("INS")).toBeTruthy(); + expect(screen.getByText("2026-12-01 - 2026-12-02")).toBeTruthy(); + expect(screen.getByText("KLCC")).toBeTruthy(); expect(screen.getByLabelText(/I agree to INS using my details/).getAttribute("aria-checked")).toBe("false"); expect(mocks.getInvite).toHaveBeenCalledWith("inv1"); }); diff --git a/solvway-admin-portal/app/i/[token]/page.tsx b/solvway-admin-portal/app/i/[token]/page.tsx index 43bb31b..8c51b4a 100644 --- a/solvway-admin-portal/app/i/[token]/page.tsx +++ b/solvway-admin-portal/app/i/[token]/page.tsx @@ -2,7 +2,9 @@ import { useEffect, useState } from "react"; import { useParams } from "next/navigation"; +import { AlertCircle, CheckCircle2, Loader2 } from "lucide-react"; import { Button } from "@/app/components/ui/button"; +import { VisitorCard, VisitorState } from "@/app/components/registration/VisitorCard"; import { RegistrationForm, apiData, failMessage } from "@/app/components/registration/RegistrationForm"; import { getInvite, inviteCheckin, submitInvite, type InviteInfo } from "@/app/lib/services/publicInvite"; import { useT } from "@/app/lib/i18n/MessagesProvider"; @@ -46,18 +48,19 @@ export default function InvitePage() { } const event = info?.eventName ?? ""; + const done = (text: string) => ; + if (phase === "loading") return ; + if (phase === "inactive") return ; + if (phase === "error" || !info) return ; + let body; - if (phase === "loading") body =

{t("UiLoading")}

; - else if (phase === "inactive") body =

{t("InviteInactive")}

; - else if (phase === "error" || !info) body =

{error}

; - else if (welcome !== null) body =

{welcome ? t("InviteWelcome", { name: welcome }) : t("InviteWelcomeAnon")}

; - else if (info.state === "CHECKED_IN") body =

{t("InviteCheckedIn", { event })}

; - else if (thanks) body =

{t("RegThanks", { event })}

; - else if (info.state === "REGISTERED") body =

{t("InviteRegistered", { event })}

; + if (welcome !== null) body = done(welcome ? t("InviteWelcome", { name: welcome }) : t("InviteWelcomeAnon")); + else if (info.state === "CHECKED_IN") body = done(t("InviteCheckedIn", { event })); + else if (thanks) body = done(t("RegThanks", { event })); + else if (info.state === "REGISTERED") body = done(t("InviteRegistered", { event })); else if (info.state === "CHECKIN") { body = (
-

{event}

{error &&

{error}

}
@@ -66,7 +69,6 @@ export default function InvitePage() { body = ( submitInvite(token, b)} @@ -76,5 +78,5 @@ export default function InvitePage() { ); } - return
{body}
; + return {body}; } diff --git a/solvway-admin-portal/app/r/[token]/page.card.test.tsx b/solvway-admin-portal/app/r/[token]/page.card.test.tsx new file mode 100644 index 0000000..9cb9eca --- /dev/null +++ b/solvway-admin-portal/app/r/[token]/page.card.test.tsx @@ -0,0 +1,74 @@ +import { describe, it, expect, vi, beforeEach } from "vitest"; +import { render, screen } from "@testing-library/react"; +import userEvent from "@testing-library/user-event"; + +const mocks = vi.hoisted(() => ({ getRegistration: vi.fn(), submitRegistration: vi.fn() })); +vi.mock("@/app/lib/services/publicRegistration", () => mocks); +vi.mock("next/navigation", () => ({ useParams: () => ({ token: "tok1" }) })); + +import { ApiError } from "@/app/lib/clientApi"; +import RegisterPage from "./page"; + +const info = { + eventName: "Expo 2026", startDate: "2026-12-01", endDate: "2026-12-02", location: "KLCC", companyName: "INS", + notice: { id: 7, textEn: "We keep your data safe.", textMs: "Data anda selamat." }, interests: [], +}; + +beforeEach(() => { + mocks.getRegistration.mockReset().mockResolvedValue(info); + mocks.submitRegistration.mockReset().mockResolvedValue({}); +}); + +const h1s = () => screen.getAllByRole("heading", { level: 1 }); + +describe("/r visitor card", () => { + it("shows the company label, one h1, dates and location, with the notice before consent", async () => { + render(); + await screen.findByLabelText("Your name"); + expect(screen.getByText("INS", { selector: "p" })).toBeTruthy(); + expect(h1s().map((h) => h.textContent)).toEqual(["Expo 2026"]); + expect(screen.getByText("2026-12-01 - 2026-12-02")).toBeTruthy(); + expect(screen.getByText("KLCC")).toBeTruthy(); + const notice = screen.getByText("We keep your data safe."); + const consent = screen.getByLabelText(/I agree to INS/); + expect(notice.compareDocumentPosition(consent) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy(); + expect(document.querySelectorAll("main").length).toBe(1); + }); + + it("loading has a status and its heading as the only h1", () => { + render(); + expect(screen.getByRole("status")).toBeTruthy(); + expect(h1s().length).toBe(1); + expect(document.querySelectorAll("main").length).toBe(1); + }); + + it("inactive shows an alert heading as the only h1, no event details", async () => { + mocks.getRegistration.mockRejectedValue(new ApiError("x", 404, { code: "CODE_INACTIVE" })); + render(); + await screen.findByRole("alert"); + expect(h1s().map((h) => h.textContent)).toEqual(["This code is no longer active."]); + expect(screen.queryByText("Expo 2026")).toBeNull(); + expect(document.querySelector("svg")).toBeTruthy(); + }); + + it("load error is an alert with one h1", async () => { + mocks.getRegistration.mockRejectedValue(new ApiError("x", 429, { code: "TOO_MANY" })); + render(); + await screen.findByRole("alert"); + expect(h1s().length).toBe(1); + }); + + it("thank you keeps the event header with an icon, one h1 and the register-another button", async () => { + const user = userEvent.setup(); + render(); + await user.type(await screen.findByLabelText("Your name"), "Aini"); + await user.type(screen.getByLabelText("Email"), "a@b.co"); + await user.click(screen.getByRole("button", { name: "Register" })); + const done = await screen.findByRole("status"); + expect(done.textContent).toContain("Thank you, you're registered for Expo 2026"); + expect(done.querySelector("svg")).toBeTruthy(); + expect(screen.getByRole("heading", { level: 2 }).textContent).toContain("Thank you"); + expect(h1s().map((h) => h.textContent)).toEqual(["Expo 2026"]); + expect(screen.getByRole("button", { name: "Register another person" })).toBeTruthy(); + }); +}); diff --git a/solvway-admin-portal/app/r/[token]/page.tsx b/solvway-admin-portal/app/r/[token]/page.tsx index 7b37ea1..8785cd4 100644 --- a/solvway-admin-portal/app/r/[token]/page.tsx +++ b/solvway-admin-portal/app/r/[token]/page.tsx @@ -2,7 +2,9 @@ import { useEffect, useState } from "react"; import { useParams } from "next/navigation"; +import { AlertCircle, CheckCircle2, Loader2 } from "lucide-react"; import { Button } from "@/app/components/ui/button"; +import { VisitorCard, VisitorState } from "@/app/components/registration/VisitorCard"; import { RegistrationForm, apiData } from "@/app/components/registration/RegistrationForm"; import { getRegistration, submitRegistration, type RegistrationInfo } from "@/app/lib/services/publicRegistration"; import { useT } from "@/app/lib/i18n/MessagesProvider"; @@ -32,19 +34,16 @@ export default function RegisterPage() { }); }, [token, t]); - let body; - if (phase === "loading") body =

{t("UiLoading")}

; - else if (phase === "inactive") body =

{t("RegInactive")}

; - else if (phase === "done") { - body = ( -
-

{t("RegThanks", { event: info?.eventName ?? "" })}

- -
- ); - } else if (info) { - body = submitRegistration(token, b)} onDone={() => setPhase("done")} onInactive={() => setPhase("inactive")} />; - } else body =

{loadError}

; - - return
{body}
; + if (phase === "loading") return ; + if (phase === "inactive") return ; + if (!info) return ; + return ( + + {phase === "done" ? ( + setPhase("form")}>{t("RegAnother")}} /> + ) : ( + submitRegistration(token, b)} onDone={() => setPhase("done")} onInactive={() => setPhase("inactive")} /> + )} + + ); }