From 4a20e75f82abbe24bb48d6ff8e3bf80d916894fd Mon Sep 17 00:00:00 2001 From: ngqile Date: Tue, 1 Dec 2026 23:01:17 +0800 Subject: [PATCH] feat: visitor card, visitor states and a calmer registration form Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM --- .../refine-visitor-pages-and-shell/tasks.md | 4 +- .../RegistrationForm.look.test.tsx | 27 +++++++++ .../registration/RegistrationForm.tsx | 43 +++++++++------ .../registration/VisitorCard.test.tsx | 37 +++++++++++++ .../components/registration/VisitorCard.tsx | 55 +++++++++++++++++++ .../app/lib/i18n/defaultMessages.ts | 1 + 6 files changed, 148 insertions(+), 19 deletions(-) create mode 100644 solvway-admin-portal/app/components/registration/RegistrationForm.look.test.tsx create mode 100644 solvway-admin-portal/app/components/registration/VisitorCard.test.tsx create mode 100644 solvway-admin-portal/app/components/registration/VisitorCard.tsx diff --git a/openspec/changes/refine-visitor-pages-and-shell/tasks.md b/openspec/changes/refine-visitor-pages-and-shell/tasks.md index 30b51d2..389d6de 100644 --- a/openspec/changes/refine-visitor-pages-and-shell/tasks.md +++ b/openspec/changes/refine-visitor-pages-and-shell/tasks.md @@ -12,13 +12,13 @@ Verify for every task: `cd solvway-admin-portal && npx vitest run; echo VITEST=$ - [x] 1.2 Sidebar sections: an `ADMIN_MODULES` list in `aclSidebar.ts`, the work and Administration split in `Sidebar` (full sidebar and drawer: divider and label; rail: divider only; no section when it has no items), and the "Administration" label in `defaultMessages.ts`. - Depends on: 1.1 - Scope: `solvway-admin-portal/app/lib/aclSidebar*`, `solvway-admin-portal/app/components/app/Sidebar*`, `solvway-admin-portal/app/lib/i18n/defaultMessages.ts` -- [ ] 1.3 Table scroll cue: a scroll-shadow utility in `globals.css` applied to the `table-container`, with colours from tokens only (the design-tokens test stays green). +- [x] 1.3 Table scroll cue: a scroll-shadow utility in `globals.css` applied to the `table-container`, with colours from tokens only (the design-tokens test stays green). - Depends on: 1.2 - Scope: `solvway-admin-portal/app/components/ui/table*`, `solvway-admin-portal/app/globals.css`, `solvway-admin-portal/app/globals.test.ts` ## 2. Visitor pages -- [ ] 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. +- [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. diff --git a/solvway-admin-portal/app/components/registration/RegistrationForm.look.test.tsx b/solvway-admin-portal/app/components/registration/RegistrationForm.look.test.tsx new file mode 100644 index 0000000..8f6461f --- /dev/null +++ b/solvway-admin-portal/app/components/registration/RegistrationForm.look.test.tsx @@ -0,0 +1,27 @@ +import { describe, it, expect } from "vitest"; +import { render, screen } from "@testing-library/react"; +import { RegistrationForm } from "./RegistrationForm"; + +const info = { + eventName: "Expo 2026", startDate: "2026-12-01", endDate: "2026-12-02", location: "KLCC", companyName: "INS", + notice: { id: 1, textEn: "English text", textMs: "Teks Melayu" }, interests: [], +}; +const props = { info, submit: async () => undefined, onDone: () => {}, onInactive: () => {} }; +const wrap = (ui: React.ReactElement) => render(ui); + +describe("RegistrationForm look", () => { + it("hides its own header when header is false", () => { + wrap(); + expect(screen.queryByRole("heading", { level: 1 })).toBeNull(); + }); + it("links a contact hint to the mobile field", () => { + 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(); + 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 efb9aec..e39068b 100644 --- a/solvway-admin-portal/app/components/registration/RegistrationForm.tsx +++ b/solvway-admin-portal/app/components/registration/RegistrationForm.tsx @@ -13,6 +13,7 @@ const EMPTY: RegistrationBody = { name: "", mobile: "", email: "", companyName: // Fields the form renders; a server error for any other field goes to the form-level alert. const FIELDS = ["name", "mobile", "email", "companyName", "jobTitle", "consent"]; const ROW = "flex min-h-11 w-full cursor-pointer items-center gap-3 rounded-md border p-3"; +const CONSENT_ROW = "flex min-h-11 w-full cursor-pointer items-start gap-3 rounded-md border p-3 leading-normal"; const BOX = "size-6"; export function apiData(err: unknown): { status?: number; code?: string; error?: string; field?: string } { @@ -31,6 +32,8 @@ 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; @@ -44,7 +47,7 @@ interface Props { } // The visitor registration form shared by /r, /i and /c: event header, fields, bilingual privacy notice and consent. -export function RegistrationForm({ title, tooManyKey, info, initial, submit, onDone, onInactive }: Props) { +export function RegistrationForm({ title, header = true, tooManyKey, info, initial, submit, onDone, onInactive }: Props) { const t = useT(); const [form, setForm] = useState({ ...EMPTY, ...initial }); const [errors, setErrors] = useState>({}); @@ -82,25 +85,31 @@ export function RegistrationForm({ title, tooManyKey, info, initial, submit, onD } } - const field = (id: "name" | "mobile" | "email" | "companyName" | "jobTitle", label: string, type = "text") => ( + const field = (id: "name" | "mobile" | "email" | "companyName" | "jobTitle", label: string, type = "text", hint?: string) => { + const describedBy = [hint && `reg-${id}-hint`, errors[id] && `reg-${id}-error`].filter(Boolean).join(" ") || undefined; + return (
- set({ [id]: e.target.value })} disabled={saving} aria-invalid={!!errors[id]} aria-describedby={errors[id] ? `reg-${id}-error` : undefined} /> + set({ [id]: e.target.value })} disabled={saving} aria-invalid={!!errors[id]} aria-describedby={describedBy} /> + {hint &&

{hint}

} {errors[id] &&

{errors[id]}

}
- ); + ); + }; return (
-
-

{title ?? info.eventName}

-

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

-
+ {header && ( +
+

{title ?? info.eventName}

+

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

+
+ )} {formError &&

{formError}

} {field("name", t("RegName"))} - {field("mobile", t("RegMobile"), "tel")} + {field("mobile", t("RegMobile"), "tel", t("RegContactHint"))} {field("email", t("RegEmail"), "email")} {field("companyName", t("RegCompany"))} {field("jobTitle", t("RegJobTitle"))} @@ -120,15 +129,15 @@ export function RegistrationForm({ title, tooManyKey, info, initial, submit, onD ))} )} -
-

{t("RegNoticeEn")}

+
+

{t("RegNoticeEn")}

{info.notice.textEn}

-

{t("RegNoticeMs")}

+

{t("RegNoticeMs")}

{info.notice.textMs}

-