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 ( {label} - 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} - - set({ consent: on === true })} aria-invalid={!!errors.consent} aria-describedby={errors.consent ? "reg-consent-error" : undefined} /> - + + set({ consent: on === true })} aria-invalid={!!errors.consent} aria-describedby={errors.consent ? "reg-consent-error" : undefined} /> + {t("RegConsentEn", { company: info.companyName })} {t("RegConsentMs", { company: info.companyName })} diff --git a/solvway-admin-portal/app/components/registration/VisitorCard.test.tsx b/solvway-admin-portal/app/components/registration/VisitorCard.test.tsx new file mode 100644 index 0000000..d8551e3 --- /dev/null +++ b/solvway-admin-portal/app/components/registration/VisitorCard.test.tsx @@ -0,0 +1,37 @@ +import { describe, it, expect } from "vitest"; +import { render, screen } from "@testing-library/react"; +import { Inbox } from "lucide-react"; +import { VisitorCard, VisitorState } from "./VisitorCard"; + +const event = { companyName: "INS", eventName: "Expo 2026", startDate: "2026-12-01", endDate: "2026-12-02", location: "KLCC" }; + +describe("VisitorCard", () => { + it("shows the event header in one card with one h1", () => { + render(body); + expect(screen.getByRole("main")).toBeTruthy(); + expect(screen.getByText("INS").className).toContain("uppercase"); + expect(screen.getByRole("heading", { level: 1 }).textContent).toBe("Expo 2026"); + expect(screen.getByText("2026-12-01 - 2026-12-02")).toBeTruthy(); + expect(screen.getByText("KLCC")).toBeTruthy(); + expect(screen.getByText("body")).toBeTruthy(); + expect(screen.getByText(/Powered by/)).toBeTruthy(); + }); + it("title overrides the h1", () => { + render(); + expect(screen.getByRole("heading", { level: 1 }).textContent).toBe("You're invited to Expo 2026"); + }); + it("renders without event data", () => { + render(x); + expect(screen.queryByRole("heading", { level: 1 })).toBeNull(); + }); +}); + +describe("VisitorState", () => { + it("renders heading, text, action and role", () => { + render(Go} />); + expect(screen.getByRole("alert")).toBeTruthy(); + expect(screen.getByRole("heading", { level: 2 }).textContent).toBe("Gone"); + expect(screen.getByText("Not active")).toBeTruthy(); + expect(screen.getByRole("button", { name: "Go" })).toBeTruthy(); + }); +}); diff --git a/solvway-admin-portal/app/components/registration/VisitorCard.tsx b/solvway-admin-portal/app/components/registration/VisitorCard.tsx new file mode 100644 index 0000000..9da60cc --- /dev/null +++ b/solvway-admin-portal/app/components/registration/VisitorCard.tsx @@ -0,0 +1,55 @@ +import type { ReactNode } from "react"; +import { CalendarDays, MapPin, type LucideIcon } from "lucide-react"; +import PoweredBy from "@/app/components/app/PoweredBy"; +import type { RegistrationInfo } from "@/app/lib/services/publicRegistration"; + +type EventHeader = Pick; + +// The public visitor page frame: one card on the page ground, event header first, PoweredBy under it. +export function VisitorCard({ event, title, children }: { event?: EventHeader; title?: string; children?: ReactNode }) { + return ( + + + {event && ( + + {event.companyName} + {title ?? event.eventName} + + + {event.startDate} - {event.endDate} + + + + {event.location} + + + )} + {children} + + + + ); +} + +interface StateProps { + icon: LucideIcon; + heading: string; + text?: string; + action?: ReactNode; + role?: "status" | "alert"; + tone?: "default" | "error"; +} + +// 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) { + return ( + + + + + {heading} + {text && {text}} + {action} + + ); +} diff --git a/solvway-admin-portal/app/lib/i18n/defaultMessages.ts b/solvway-admin-portal/app/lib/i18n/defaultMessages.ts index 90b9051..52611f4 100644 --- a/solvway-admin-portal/app/lib/i18n/defaultMessages.ts +++ b/solvway-admin-portal/app/lib/i18n/defaultMessages.ts @@ -479,6 +479,7 @@ export const DEFAULT_MESSAGES: Record = { RegName: "Your name", RegMobile: "Mobile number", RegEmail: "Email", + RegContactHint: "Mobile or email is required", RegCompany: "Company", RegJobTitle: "Job title", RegInterests: "Interests (optional)",
{hint}
{errors[id]}
- {info.companyName} | {info.startDate} - {info.endDate} | {info.location} -
+ {info.companyName} | {info.startDate} - {info.endDate} | {info.location} +
{formError}
{info.notice.textEn}
{info.notice.textMs}
body
x
{event.companyName}
+ + {event.startDate} - {event.endDate} +
+ + {event.location} +
{text}