feat: visitor pages, My QR, sign-in frame and shell refinements #39
No files matched your search
@@ -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.
|
||||
|
||||
@@ -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(<RegistrationForm {...props} header={false} />);
|
||||
expect(screen.queryByRole("heading", { level: 1 })).toBeNull();
|
||||
});
|
||||
it("links a contact hint to the mobile field", () => {
|
||||
wrap(<RegistrationForm {...props} header={false} />);
|
||||
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(<RegistrationForm {...props} header={false} />);
|
||||
expect(screen.getByText("English text").parentElement?.className).toContain("text-muted-foreground");
|
||||
expect(screen.getByText("Teks Melayu")).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -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<RegistrationBody>({ ...EMPTY, ...initial });
|
||||
const [errors, setErrors] = useState<Record<string, string>>({});
|
||||
@@ -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 (
|
||||
<div className="space-y-1.5">
|
||||
<Label htmlFor={`reg-${id}`}>{label}</Label>
|
||||
<Input id={`reg-${id}`} className="h-11" type={type} value={form[id]} onChange={(e) => set({ [id]: e.target.value })} disabled={saving} aria-invalid={!!errors[id]} aria-describedby={errors[id] ? `reg-${id}-error` : undefined} />
|
||||
<Input id={`reg-${id}`} className="h-11" type={type} value={form[id]} onChange={(e) => set({ [id]: e.target.value })} disabled={saving} aria-invalid={!!errors[id]} aria-describedby={describedBy} />
|
||||
{hint && <p id={`reg-${id}-hint`} className="text-xs text-muted-foreground">{hint}</p>}
|
||||
{errors[id] && <p id={`reg-${id}-error`} className="text-sm text-destructive">{errors[id]}</p>}
|
||||
</div>
|
||||
);
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<form onSubmit={onSubmit} className="space-y-4" noValidate>
|
||||
<div>
|
||||
<h1 className="text-2xl font-semibold">{title ?? info.eventName}</h1>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{info.companyName} | {info.startDate} - {info.endDate} | {info.location}
|
||||
</p>
|
||||
</div>
|
||||
{header && (
|
||||
<div>
|
||||
<h1 className="text-2xl font-semibold">{title ?? info.eventName}</h1>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{info.companyName} | {info.startDate} - {info.endDate} | {info.location}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
{formError && <p role="alert" className="text-sm text-destructive">{formError}</p>}
|
||||
{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
|
||||
))}
|
||||
</fieldset>
|
||||
)}
|
||||
<div className="space-y-2 rounded-md border p-3 text-sm">
|
||||
<h2 className="font-medium">{t("RegNoticeEn")}</h2>
|
||||
<div className="space-y-2 rounded-md bg-muted p-3 text-xs text-muted-foreground">
|
||||
<h2 className="font-semibold text-foreground">{t("RegNoticeEn")}</h2>
|
||||
<p className="whitespace-pre-line">{info.notice.textEn}</p>
|
||||
<h2 className="font-medium">{t("RegNoticeMs")}</h2>
|
||||
<h2 className="font-semibold text-foreground">{t("RegNoticeMs")}</h2>
|
||||
<p className="whitespace-pre-line">{info.notice.textMs}</p>
|
||||
</div>
|
||||
<Label htmlFor="reg-consent" className={ROW}>
|
||||
<Checkbox id="reg-consent" className={BOX} checked={form.consent} onCheckedChange={(on) => set({ consent: on === true })} aria-invalid={!!errors.consent} aria-describedby={errors.consent ? "reg-consent-error" : undefined} />
|
||||
<span>
|
||||
<Label htmlFor="reg-consent" className={CONSENT_ROW}>
|
||||
<Checkbox id="reg-consent" className={`${BOX} mt-0.5`} checked={form.consent} onCheckedChange={(on) => set({ consent: on === true })} aria-invalid={!!errors.consent} aria-describedby={errors.consent ? "reg-consent-error" : undefined} />
|
||||
<span className="space-y-1">
|
||||
<span className="block">{t("RegConsentEn", { company: info.companyName })}</span>
|
||||
<span className="block">{t("RegConsentMs", { company: info.companyName })}</span>
|
||||
</span>
|
||||
|
||||
@@ -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(<VisitorCard event={event}><p>body</p></VisitorCard>);
|
||||
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(<VisitorCard event={event} title="You're invited to Expo 2026" />);
|
||||
expect(screen.getByRole("heading", { level: 1 }).textContent).toBe("You're invited to Expo 2026");
|
||||
});
|
||||
it("renders without event data", () => {
|
||||
render(<VisitorCard><p>x</p></VisitorCard>);
|
||||
expect(screen.queryByRole("heading", { level: 1 })).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("VisitorState", () => {
|
||||
it("renders heading, text, action and role", () => {
|
||||
render(<VisitorState icon={Inbox} heading="Gone" text="Not active" role="alert" tone="error" action={<button>Go</button>} />);
|
||||
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();
|
||||
});
|
||||
});
|
||||
@@ -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<RegistrationInfo, "companyName" | "eventName" | "startDate" | "endDate" | "location">;
|
||||
|
||||
// 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 (
|
||||
<div className="flex min-h-screen flex-col items-center bg-background px-4 py-8">
|
||||
<main className="w-full max-w-md space-y-6 rounded-lg border bg-card p-6 shadow-card">
|
||||
{event && (
|
||||
<header className="space-y-2">
|
||||
<p className="text-xs font-semibold tracking-wide text-primary uppercase">{event.companyName}</p>
|
||||
<h1 className="text-2xl font-semibold">{title ?? event.eventName}</h1>
|
||||
<p className="flex items-center gap-2 text-sm text-muted-foreground">
|
||||
<CalendarDays className="size-4 shrink-0" aria-hidden="true" />
|
||||
<span>{event.startDate} - {event.endDate}</span>
|
||||
</p>
|
||||
<p className="flex items-center gap-2 text-sm text-muted-foreground">
|
||||
<MapPin className="size-4 shrink-0" aria-hidden="true" />
|
||||
<span>{event.location}</span>
|
||||
</p>
|
||||
</header>
|
||||
)}
|
||||
{children}
|
||||
</main>
|
||||
<div className="mt-4"><PoweredBy /></div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
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 (
|
||||
<div role={role} className="flex flex-col items-center gap-3 text-center">
|
||||
<span className={`flex size-12 items-center justify-center rounded-full ${tone === "error" ? "bg-destructive/10 text-destructive" : "bg-accent text-accent-foreground"}`}>
|
||||
<Icon className="size-6" aria-hidden="true" />
|
||||
</span>
|
||||
<h2 className="text-lg font-semibold">{heading}</h2>
|
||||
{text && <p className="text-sm text-muted-foreground">{text}</p>}
|
||||
{action}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -479,6 +479,7 @@ export const DEFAULT_MESSAGES: Record<string, string> = {
|
||||
RegName: "Your name",
|
||||
RegMobile: "Mobile number",
|
||||
RegEmail: "Email",
|
||||
RegContactHint: "Mobile or email is required",
|
||||
RegCompany: "Company",
|
||||
RegJobTitle: "Job title",
|
||||
RegInterests: "Interests (optional)",
|
||||
|
||||
Reference in new issue
Block a user