Compare commits
10
Commits
d4ae94fcc9
...
1458ea4aab
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1458ea4aab | ||
|
|
db9e218423 | ||
|
|
2c7729d139 | ||
|
|
282d2263f2 | ||
|
|
372cd7244e | ||
|
|
370c9f4ad0 | ||
|
|
ac69c34cf2 | ||
|
|
4a20e75f82 | ||
|
|
08617f87c0 | ||
|
|
5ac248cee7 |
No files matched your search
@@ -9,34 +9,34 @@ Verify for every task: `cd solvway-admin-portal && npx vitest run; echo VITEST=$
|
||||
- [x] 1.1 Header trail without repeats: `Breadcrumbs` shows nothing on a page whose URL is the matched leaf's own URL, and shows the leaf as a link on a sub-page.
|
||||
- Depends on: none
|
||||
- Scope: `solvway-admin-portal/app/components/app/Breadcrumbs*`
|
||||
- [ ] 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`.
|
||||
- [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.
|
||||
- [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*`
|
||||
- [ ] 3.2 Reset password uses the login page's two-column frame. Remove the stale brown and gold comments in login.
|
||||
- [x] 3.2 Reset password uses the login page's two-column frame. Remove the stale brown and gold comments in login.
|
||||
- Depends on: 3.1
|
||||
- Scope: `solvway-admin-portal/app/reset-password/**`, `solvway-admin-portal/app/login/**`
|
||||
|
||||
## 4. Release check
|
||||
|
||||
- [ ] 4.1 Playwright at 1280 and 360 px:
|
||||
- [x] 4.1 Playwright at 1280 and 360 px:
|
||||
- `/r`, `/i` and `/c` in each reachable state;
|
||||
- My QR, using a throwaway staff user that is reverted afterwards;
|
||||
- login and reset password;
|
||||
@@ -46,3 +46,11 @@ Verify for every task: `cd solvway-admin-portal && npx vitest run; echo VITEST=$
|
||||
|
||||
Run the full portal verify. Record the result here.
|
||||
- Depends on: 3.2
|
||||
- Done 2026-12-01 on the local stack (review server on port 3001), full portal verify green (vitest 1580 passed with exit 0, tsc 0, lint 0 errors).
|
||||
- Visitor pages at 360 and 1280 px: /r open form (company label, h1, dates, location, hint under mobile, fine-print notice in both languages before consent), the empty-submit errors shown on screen, an unknown code (no event details), /c lookup, /c not yet (heading balanced so the date stays whole), and /i already checked in. One h1 and one main in every state. Dark theme checked on /c. No registration was submitted (no records created).
|
||||
- Header: /events shows no trail, /events/new shows "Events" linking to /events.
|
||||
- Sidebar: Administration label and divider in the full sidebar, divider only in the rail.
|
||||
- Users table at 360 px: right fade at the start and gone at the end. The pinned first column hid the left fade, so it now carries a divider on its right edge (fix found in this check). Dark theme checked.
|
||||
- Reset password (throwaway CV staff user, reverted afterwards): same frame as login at 1280 and 360 px, and the policy error is shown.
|
||||
- My QR (same user, temporarily on the LC Live Check team, then removed and disabled): card layout at 360, 700, 1024 and 1280 px. At 1280 px a button overflowed the card, so the QR now stacks above the buttons (fix found in this check).
|
||||
|
||||
@@ -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(<CheckinPage />);
|
||||
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(<CheckinPage />);
|
||||
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(<CheckinPage />);
|
||||
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(<CheckinPage />);
|
||||
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(<CheckinPage />);
|
||||
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(<CheckinPage />);
|
||||
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(<CheckinPage />);
|
||||
await screen.findByRole("alert");
|
||||
expect(h1s().length).toBe(1);
|
||||
});
|
||||
});
|
||||
@@ -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") => (
|
||||
<VisitorCard><VisitorState h1 icon={icon} heading={heading} role={role} tone={tone} /></VisitorCard>
|
||||
);
|
||||
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 = <p role="status">{t("UiLoading")}</p>;
|
||||
else if (phase === "inactive") body = <p role="alert">{t("RegInactive")}</p>;
|
||||
else if (phase === "error" || !state) body = <p role="alert" className="text-sm text-destructive">{error}</p>;
|
||||
else if (!open) body = <p role="status">{state.state === "NOT_YET" ? t("ChkNotYet", { date: state.startDate }) : t("ChkEnded")}</p>;
|
||||
else if (phase === "welcome") body = <p role="status" className="text-lg font-medium">{firstName ? t("InviteWelcome", { name: firstName }) : t("InviteWelcomeAnon")}</p>;
|
||||
else if (phase === "done") body = <p role="status" className="text-lg font-medium">{t("ChkDone", { event: open.eventName })}</p>;
|
||||
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} submit={(b) => registerWalkIn(token, b)} onDone={() => setPhase("done")} onInactive={() => setPhase("inactive")} />;
|
||||
} else {
|
||||
body = (
|
||||
<form onSubmit={lookup} className="space-y-4" noValidate>
|
||||
<h1 className="text-2xl font-semibold">{open.eventName}</h1>
|
||||
{error && <p role="alert" className="text-sm text-destructive">{error}</p>}
|
||||
<div className="space-y-1.5">
|
||||
<Label htmlFor="chk-value">{t("ChkLookup")}</Label>
|
||||
@@ -80,5 +85,5 @@ export default function CheckinPage() {
|
||||
);
|
||||
}
|
||||
|
||||
return <main className="mx-auto w-full max-w-md px-4 py-6">{body}</main>;
|
||||
return <VisitorCard event={open}>{body}</VisitorCard>;
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import type { SidebarLink } from "@/app/lib/aclSidebar";
|
||||
|
||||
// refine-visitor-pages-and-shell: no trail on a leaf's own page (the page title says it already).
|
||||
|
||||
const state = vi.hoisted(() => ({ links: [] as SidebarLink[], pathname: "/" }));
|
||||
|
||||
vi.mock("next/navigation", () => ({ usePathname: () => state.pathname }));
|
||||
vi.mock("@/app/lib/useAclSidebar", () => ({ useAclSidebar: () => state.links }));
|
||||
|
||||
import Breadcrumbs from "./Breadcrumbs";
|
||||
|
||||
const LINKS: SidebarLink[] = [
|
||||
{
|
||||
name: "Event",
|
||||
url: "",
|
||||
children: [{ name: "Events", url: "/events", children: [] }],
|
||||
},
|
||||
];
|
||||
|
||||
afterEach(() => {
|
||||
state.pathname = "/";
|
||||
});
|
||||
|
||||
describe("Breadcrumbs trail without repeats", () => {
|
||||
it("shows no trail on the Events list", () => {
|
||||
state.links = LINKS;
|
||||
state.pathname = "/events";
|
||||
|
||||
const { container } = render(<Breadcrumbs />);
|
||||
|
||||
expect(container).toBeEmptyDOMElement();
|
||||
});
|
||||
|
||||
it("shows Events as a link to the list on the new event page", () => {
|
||||
state.links = LINKS;
|
||||
state.pathname = "/events/new";
|
||||
|
||||
render(<Breadcrumbs />);
|
||||
|
||||
expect(screen.getByRole("link", { name: "Events" })).toHaveAttribute("href", "/events");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,54 @@
|
||||
import { render, screen, within } from "@testing-library/react";
|
||||
import { describe, it, expect, vi } from "vitest";
|
||||
import type { SidebarLink } from "@/app/lib/aclSidebar";
|
||||
|
||||
const state = vi.hoisted(() => ({ links: [] as SidebarLink[] }));
|
||||
|
||||
vi.mock("next/navigation", () => ({ usePathname: () => "/" }));
|
||||
vi.mock("@/app/lib/useAclSidebar", () => ({ useAclSidebar: () => state.links }));
|
||||
|
||||
import { SidebarNav } from "./Sidebar";
|
||||
|
||||
const link = (name: string): SidebarLink => ({ name, url: `/${name}`, children: [] });
|
||||
const names = (...n: string[]) => n.map(link);
|
||||
|
||||
const ALL = names(
|
||||
"BO_DASHBOARD", "BO_EVENTS", "BO_EVENT_LEADS", "BO_INTERESTS", "BO_LEADS",
|
||||
"BO_USERS", "BO_ROLES", "BO_EMAILS", "BO_LOGIN_SECURITY", "BO_AUDIT_LOG", "BO_COMPANIES",
|
||||
);
|
||||
|
||||
describe("Sidebar sections", () => {
|
||||
it("lists work pages above the Administration label and admin pages below it", () => {
|
||||
state.links = ALL;
|
||||
render(<SidebarNav />);
|
||||
const label = screen.getByText("Administration");
|
||||
const before = (el: HTMLElement) => label.compareDocumentPosition(el) & Node.DOCUMENT_POSITION_PRECEDING;
|
||||
const after = (el: HTMLElement) => label.compareDocumentPosition(el) & Node.DOCUMENT_POSITION_FOLLOWING;
|
||||
const hrefs = (re: RegExp) => screen.getAllByRole("link").filter((a) => re.test(a.getAttribute("href") ?? ""));
|
||||
for (const a of hrefs(/DASHBOARD|EVENTS|EVENT_LEADS|INTERESTS|LEADS/)) expect(before(a)).toBeTruthy();
|
||||
for (const a of hrefs(/USERS|ROLES|EMAILS|LOGIN_SECURITY|AUDIT_LOG|COMPANIES/)) expect(after(a)).toBeTruthy();
|
||||
expect(screen.getAllByRole("link")).toHaveLength(11);
|
||||
});
|
||||
|
||||
it("names the admin list by the label", () => {
|
||||
state.links = ALL;
|
||||
render(<SidebarNav />);
|
||||
const list = screen.getByRole("list", { name: "Administration" });
|
||||
expect(within(list).getAllByRole("link")).toHaveLength(6);
|
||||
});
|
||||
|
||||
it("shows no Administration label or divider when no admin module is available", () => {
|
||||
state.links = names("BO_EVENTS", "BO_EVENT_LEADS");
|
||||
const { container } = render(<SidebarNav />);
|
||||
expect(screen.queryByText("Administration")).toBeNull();
|
||||
expect(container.querySelector("[data-slot='sidebar-divider']")).toBeNull();
|
||||
});
|
||||
|
||||
it("shows only the divider in the collapsed rail", () => {
|
||||
state.links = ALL;
|
||||
const { container } = render(<SidebarNav collapsed />);
|
||||
expect(screen.queryByText("Administration")).toBeNull();
|
||||
expect(container.querySelector("[data-slot='sidebar-divider']")).not.toBeNull();
|
||||
expect(screen.getAllByRole("link")).toHaveLength(11);
|
||||
});
|
||||
});
|
||||
@@ -5,7 +5,7 @@ import Link from "next/link";
|
||||
import { usePathname } from "next/navigation";
|
||||
import { ChevronDown, PanelLeftClose, PanelLeftOpen } from "lucide-react";
|
||||
import { useAclSidebar } from "@/app/lib/useAclSidebar";
|
||||
import { currentTrail, type SidebarLink } from "@/app/lib/aclSidebar";
|
||||
import { ADMIN_MODULES, currentTrail, type SidebarLink } from "@/app/lib/aclSidebar";
|
||||
import { useT } from "@/app/lib/i18n/MessagesProvider";
|
||||
import { iconFor } from "./icon-map";
|
||||
import { cn } from "@/app/lib/utils";
|
||||
@@ -216,18 +216,38 @@ export function SidebarNav({ onNavigate, collapsed = false }: { onNavigate?: ()
|
||||
const t = useT();
|
||||
const links = useAclSidebar();
|
||||
const trail = currentTrail(links, usePathname());
|
||||
const adminLabelId = useId();
|
||||
|
||||
const work = links.filter((l) => !ADMIN_MODULES.includes(l.name));
|
||||
const admin = links.filter((l) => ADMIN_MODULES.includes(l.name));
|
||||
const render = (link: SidebarLink) =>
|
||||
collapsed ? (
|
||||
<RailNode key={link.url || link.name} link={link} trail={trail} />
|
||||
) : (
|
||||
<NavNode key={link.url || link.name} link={link} depth={0} trail={trail} onNavigate={onNavigate} />
|
||||
);
|
||||
const listClass = cn("space-y-1", collapsed ? "px-2 py-3" : "p-3");
|
||||
|
||||
return (
|
||||
<nav aria-label={t("SidebarMainNav")} className="scrollable flex-1 overflow-x-hidden overflow-y-auto">
|
||||
<ul className={cn("space-y-1", collapsed ? "px-2 py-3" : "p-3")}>
|
||||
{links.map((link) =>
|
||||
collapsed ? (
|
||||
<RailNode key={link.url || link.name} link={link} trail={trail} />
|
||||
) : (
|
||||
<NavNode key={link.url || link.name} link={link} depth={0} trail={trail} onNavigate={onNavigate} />
|
||||
),
|
||||
)}
|
||||
</ul>
|
||||
{work.length > 0 && <ul className={cn(listClass, admin.length > 0 && "pb-0")}>{work.map(render)}</ul>}
|
||||
{admin.length > 0 && (
|
||||
<>
|
||||
<div data-slot="sidebar-divider" className={cn("mt-3 border-t border-border", collapsed ? "mx-3" : "mx-4")} />
|
||||
{/* The visible label names the list; the rail has no label, so the list carries the name itself. */}
|
||||
{!collapsed && (
|
||||
<p id={adminLabelId} className="px-6 pt-3 text-xs font-semibold text-muted-foreground">
|
||||
{t("SidebarAdministration")}
|
||||
</p>
|
||||
)}
|
||||
<ul
|
||||
aria-labelledby={collapsed ? undefined : adminLabelId}
|
||||
aria-label={collapsed ? t("SidebarAdministration") : undefined}
|
||||
className={cn(listClass, collapsed ? "pt-3" : "pt-2")}>
|
||||
{admin.map(render)}
|
||||
</ul>
|
||||
</>
|
||||
)}
|
||||
</nav>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import { Copy, Download, Maximize2, Share2 } from "lucide-react";
|
||||
import { Button } from "@/app/components/ui/button";
|
||||
import { Dialog, DialogContent } from "@/app/components/ui/dialog";
|
||||
import { Switch } from "@/app/components/ui/switch";
|
||||
import { cn } from "@/app/lib/utils";
|
||||
import { useT } from "@/app/lib/i18n/MessagesProvider";
|
||||
|
||||
const slug = (s: string) => s.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
|
||||
@@ -13,6 +14,7 @@ const slug = (s: string) => s.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(
|
||||
/** One registration code: QR, link, copy, PNG download and (when onToggle is given) an on/off switch. */
|
||||
export function QrCodeItem({
|
||||
label,
|
||||
className,
|
||||
eventName,
|
||||
fileLabel,
|
||||
token,
|
||||
@@ -21,7 +23,9 @@ export function QrCodeItem({
|
||||
prefix = "r",
|
||||
personal = false,
|
||||
}: {
|
||||
label: string;
|
||||
/** Heading above the link; omit when the surrounding card already names the event. */
|
||||
label?: string;
|
||||
className?: string;
|
||||
eventName: string;
|
||||
/** Member name for the download file name; omit for the event code. */
|
||||
fileLabel?: string;
|
||||
@@ -71,11 +75,11 @@ export function QrCodeItem({
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-3 rounded-lg border p-4 sm:flex-row sm:items-center">
|
||||
<div className={cn("flex flex-col gap-3 rounded-lg border p-4 sm:flex-row sm:items-center", className)}>
|
||||
<QRCodeSVG value={link} size={128} className="shrink-0" />
|
||||
<QRCodeCanvas ref={canvas} value={link} size={512} className="hidden" />
|
||||
<div className="min-w-0 flex-1 space-y-2">
|
||||
<p className="text-sm font-medium">{label}</p>
|
||||
{label && <p className="text-sm font-medium">{label}</p>}
|
||||
<p className="break-all text-xs text-muted-foreground">{link}</p>
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<Button variant="outline" size="sm" onClick={copy}>
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
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("renders no heading of its own: the visitor card carries the event header", () => {
|
||||
wrap(<RegistrationForm {...props} />);
|
||||
expect(screen.queryByRole("heading", { level: 1 })).toBeNull();
|
||||
});
|
||||
it("links a contact hint to the mobile field", () => {
|
||||
wrap(<RegistrationForm {...props} />);
|
||||
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} />);
|
||||
expect(screen.getByText("English text").parentElement?.className).toContain("text-muted-foreground");
|
||||
expect(screen.getByText("Teks Melayu")).toBeTruthy();
|
||||
});
|
||||
|
||||
it("sets the consent sentences in regular weight", () => {
|
||||
wrap(<RegistrationForm {...props} />);
|
||||
expect(screen.getByText(/I agree to INS/).closest("span[class*=space-y]")).toHaveClass("font-normal");
|
||||
});
|
||||
});
|
||||
@@ -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 } {
|
||||
@@ -29,8 +30,6 @@ export function failMessage(t: (k: string) => string, err: unknown, tooMany = "R
|
||||
}
|
||||
|
||||
interface Props {
|
||||
/** Heading text; the event name when omitted. */
|
||||
title?: string;
|
||||
/** i18n key for the too-many message (default RegTooMany, the /r wording). */
|
||||
tooManyKey?: string;
|
||||
info: RegistrationInfo;
|
||||
@@ -43,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, 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<RegistrationBody>({ ...EMPTY, ...initial });
|
||||
const [errors, setErrors] = useState<Record<string, string>>({});
|
||||
@@ -82,25 +82,23 @@ 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>
|
||||
{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 +118,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 font-normal">
|
||||
<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,58 @@
|
||||
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";
|
||||
/** 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). 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 (
|
||||
<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>
|
||||
<Heading className="text-lg font-semibold text-balance">{heading}</Heading>
|
||||
{text && <p className="text-sm text-muted-foreground">{text}</p>}
|
||||
{action}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
// refine-visitor-pages-and-shell: the pinned first column hides the left scroll cue, so it carries
|
||||
// a divider on its right edge that shows where scrolled columns slide under it.
|
||||
describe("pinned first column", () => {
|
||||
const src = readFileSync(join(__dirname, "data-table.tsx"), "utf8");
|
||||
it("draws a token-coloured divider on the right edge of pinned head and body cells", () => {
|
||||
for (const name of ["PINNED_HEAD", "PINNED_CELL"]) {
|
||||
const value = src.match(new RegExp(`const ${name}\\s*=\\s*\\n?\\s*'([^']*)'`))?.[1] ?? "";
|
||||
expect(value, name).toContain("shadow-[inset_-1px_0_0_var(--border)]");
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -42,12 +42,13 @@ declare module '@tanstack/react-table' {
|
||||
|
||||
// The first column stays visible while a wide table scrolls sideways. Its cells need an opaque
|
||||
// background that follows the row's hover/focus/selected state, or scrolled cells show through.
|
||||
const PINNED_HEAD = 'sticky left-0 z-[1] bg-table-head'
|
||||
// The inset right divider stands in for the left scroll cue, which the opaque column covers.
|
||||
const PINNED_HEAD = 'sticky left-0 z-[1] bg-table-head shadow-[inset_-1px_0_0_var(--border)]'
|
||||
// Clicks on these inside a row act on the control, not the row.
|
||||
const ROW_CONTROLS = 'a, button, input, select, textarea, label, [role="checkbox"]'
|
||||
|
||||
const PINNED_CELL =
|
||||
'sticky left-0 z-[1] bg-card group-hover:bg-muted group-focus-visible:bg-muted group-aria-selected:bg-accent'
|
||||
'sticky left-0 z-[1] bg-card shadow-[inset_-1px_0_0_var(--border)] group-hover:bg-muted group-focus-visible:bg-muted group-aria-selected:bg-accent'
|
||||
|
||||
/**
|
||||
* Data table for server-paginated, server-sorted result sets — which is what
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
// refine-visitor-pages-and-shell: wide tables show a visible fade on an edge that can still scroll.
|
||||
// The old 10px shadow at 12% was too faint to notice at 360px.
|
||||
describe("table scroll cue", () => {
|
||||
const css = readFileSync(join(__dirname, "../../globals.css"), "utf8");
|
||||
const rule = css.match(/\[data-slot="table-container"\]\s*\{([\s\S]*?)\n\}/)?.[1] ?? "";
|
||||
|
||||
it("uses local covers over scroll shadows", () => {
|
||||
expect(rule.match(/ local/g)).toHaveLength(2);
|
||||
expect(rule.match(/ scroll/g)).toHaveLength(2);
|
||||
});
|
||||
|
||||
it("draws a shadow wide and strong enough to see, from theme tokens only", () => {
|
||||
const shadow = [...rule.matchAll(/var\(--foreground\) (\d+)%[^/]*\/ (\d+)px/g)];
|
||||
expect(shadow).toHaveLength(2);
|
||||
for (const [, pct, px] of shadow) {
|
||||
expect(Number(pct)).toBeGreaterThanOrEqual(18);
|
||||
expect(Number(px)).toBeGreaterThanOrEqual(16);
|
||||
}
|
||||
expect(rule).not.toMatch(/#[0-9a-f]{3,8}\b|rgb\(|hsl\(/i);
|
||||
});
|
||||
|
||||
it("makes each cover wider than its shadow, so the fade is gone at that end", () => {
|
||||
const covers = [...rule.matchAll(/var\(--card\)[^/]*\/ (\d+)px/g)].map((m) => Number(m[1]));
|
||||
const shadows = [...rule.matchAll(/var\(--foreground\)[^/]*\/ (\d+)px/g)].map((m) => Number(m[1]));
|
||||
expect(covers).toHaveLength(2);
|
||||
expect(Math.min(...covers)).toBeGreaterThan(Math.max(...shadows));
|
||||
});
|
||||
});
|
||||
@@ -248,13 +248,15 @@ h4 {
|
||||
}
|
||||
}
|
||||
|
||||
/* Scroll-edge cue: a soft shadow on a side only while more content is scrollable there. */
|
||||
/* Scroll-edge cue: a shadow on a side only while more content is scrollable there. The covers
|
||||
(local) scroll with the content and hide the shadows (scroll) at each end. Covers assume a card
|
||||
backdrop; on the page ground they read as a faint lighter strip. */
|
||||
[data-slot="table-container"] {
|
||||
background:
|
||||
linear-gradient(to right, var(--card) 30%, transparent) left center / 24px 100% no-repeat local,
|
||||
linear-gradient(to left, var(--card) 30%, transparent) right center / 24px 100% no-repeat local,
|
||||
linear-gradient(to right, color-mix(in srgb, var(--foreground) 12%, transparent), transparent) left center / 10px 100% no-repeat scroll,
|
||||
linear-gradient(to left, color-mix(in srgb, var(--foreground) 12%, transparent), transparent) right center / 10px 100% no-repeat scroll;
|
||||
linear-gradient(to right, var(--card) 40%, transparent) left center / 40px 100% no-repeat local,
|
||||
linear-gradient(to left, var(--card) 40%, transparent) right center / 40px 100% no-repeat local,
|
||||
linear-gradient(to right, color-mix(in srgb, var(--foreground) 18%, transparent), transparent) left center / 20px 100% no-repeat scroll,
|
||||
linear-gradient(to left, color-mix(in srgb, var(--foreground) 18%, transparent), transparent) right center / 20px 100% no-repeat scroll;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -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(<InvitePage />);
|
||||
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(<InvitePage />);
|
||||
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(<InvitePage />);
|
||||
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(<InvitePage />);
|
||||
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(<InvitePage />);
|
||||
await screen.findByRole("alert");
|
||||
expect(h1s().length).toBe(1);
|
||||
});
|
||||
});
|
||||
@@ -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");
|
||||
});
|
||||
|
||||
@@ -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) => <VisitorState icon={CheckCircle2} heading={text} role="status" />;
|
||||
if (phase === "loading") return <VisitorCard><VisitorState h1 icon={Loader2} heading={t("UiLoading")} role="status" /></VisitorCard>;
|
||||
if (phase === "inactive") return <VisitorCard><VisitorState h1 icon={AlertCircle} heading={t("InviteInactive")} role="alert" /></VisitorCard>;
|
||||
if (phase === "error" || !info) return <VisitorCard><VisitorState h1 icon={AlertCircle} heading={error ?? ""} role="alert" tone="error" /></VisitorCard>;
|
||||
|
||||
let body;
|
||||
if (phase === "loading") body = <p role="status">{t("UiLoading")}</p>;
|
||||
else if (phase === "inactive") body = <p role="alert">{t("InviteInactive")}</p>;
|
||||
else if (phase === "error" || !info) body = <p role="alert" className="text-sm text-destructive">{error}</p>;
|
||||
else if (welcome !== null) body = <p role="status" className="text-lg font-medium">{welcome ? t("InviteWelcome", { name: welcome }) : t("InviteWelcomeAnon")}</p>;
|
||||
else if (info.state === "CHECKED_IN") body = <p role="status" className="text-lg font-medium">{t("InviteCheckedIn", { event })}</p>;
|
||||
else if (thanks) body = <p role="status" className="text-lg font-medium">{t("RegThanks", { event })}</p>;
|
||||
else if (info.state === "REGISTERED") body = <p role="status" className="text-lg font-medium">{t("InviteRegistered", { event })}</p>;
|
||||
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 = (
|
||||
<div className="space-y-4">
|
||||
<h1 className="text-2xl font-semibold">{event}</h1>
|
||||
{error && <p role="alert" className="text-sm text-destructive">{error}</p>}
|
||||
<Button className="h-11 w-full" onClick={checkIn}>{t("InviteCheckin")}</Button>
|
||||
</div>
|
||||
@@ -66,7 +69,6 @@ export default function InvitePage() {
|
||||
body = (
|
||||
<RegistrationForm
|
||||
info={info}
|
||||
title={t("InviteTitle", { event })}
|
||||
tooManyKey="InviteTooMany"
|
||||
initial={{ name: info.guest.name ?? "", mobile: info.guest.mobile ?? "", email: info.guest.email ?? "", companyName: info.guest.companyName ?? "" }}
|
||||
submit={(b) => submitInvite(token, b)}
|
||||
@@ -76,5 +78,5 @@ export default function InvitePage() {
|
||||
);
|
||||
}
|
||||
|
||||
return <main className="mx-auto w-full max-w-md px-4 py-6">{body}</main>;
|
||||
return <VisitorCard event={info} title={info.state === "OPEN" && welcome === null && !thanks ? t("InviteTitle", { event }) : undefined}>{body}</VisitorCard>;
|
||||
}
|
||||
@@ -12,6 +12,9 @@ export interface SidebarLink {
|
||||
children: SidebarLink[];
|
||||
}
|
||||
|
||||
// ponytail: fixed list; a new admin module falls into the work section until added here.
|
||||
export const ADMIN_MODULES = ["BO_USERS", "BO_ROLES", "BO_EMAILS", "BO_LOGIN_SECURITY", "BO_AUDIT_LOG", "BO_COMPANIES"];
|
||||
|
||||
const byId = (nodes: AdminModule[] | undefined) => [...(nodes ?? [])].sort((a, b) => (a.id ?? 0) - (b.id ?? 0));
|
||||
|
||||
/**
|
||||
|
||||
@@ -86,6 +86,7 @@ export const DEFAULT_MESSAGES: Record<string, string> = {
|
||||
HeaderSwitchToDark: "Switch to dark theme",
|
||||
LocaleSwitcherChange: "Change language",
|
||||
SidebarMainNav: "Main",
|
||||
SidebarAdministration: "Administration",
|
||||
UiBreadcrumb: "breadcrumb",
|
||||
UiMore: "More",
|
||||
UiColumns: "Columns",
|
||||
@@ -478,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)",
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
import { describe, it, expect, vi, beforeEach } from "vitest";
|
||||
import { render, screen, within } from "@testing-library/react";
|
||||
|
||||
const mocks = vi.hoisted(() => ({ getMyLinks: vi.fn() }));
|
||||
vi.mock("@/app/lib/services/adminRegistration", () => mocks);
|
||||
vi.mock("qrcode.react", () => ({
|
||||
QRCodeSVG: ({ value }: { value: string }) => <svg data-testid="qr-svg" data-value={value} />,
|
||||
QRCodeCanvas: () => <canvas />,
|
||||
}));
|
||||
|
||||
import MyQrPage from "./page";
|
||||
|
||||
const LINK = { eventUuid: "u1", eventName: "Expo 2026", startDate: "2026-12-01", endDate: "2026-12-02", location: "KLCC", token: "t1", enabled: true };
|
||||
beforeEach(() => mocks.getMyLinks.mockReset());
|
||||
|
||||
describe("My QR codes as cards", () => {
|
||||
it("shows the event name once, as the card title, with dates and location under it", async () => {
|
||||
mocks.getMyLinks.mockResolvedValue([LINK]);
|
||||
const { container } = render(<MyQrPage />);
|
||||
await screen.findByText("Expo 2026");
|
||||
expect(screen.getAllByText("Expo 2026")).toHaveLength(1);
|
||||
const card = container.querySelector("[data-slot=card]") as HTMLElement;
|
||||
expect(within(card).getByText("Expo 2026").closest("[data-slot=card-title]")).toBeTruthy();
|
||||
expect(within(card).getByText("2026-12-01 - 2026-12-02")).toBeTruthy();
|
||||
expect(within(card).getByText("KLCC")).toBeTruthy();
|
||||
expect(within(card).getByTestId("qr-svg")).toBeTruthy();
|
||||
expect(within(card).getByRole("button", { name: "Share" })).toBeTruthy();
|
||||
});
|
||||
|
||||
it("puts the Switched off badge in the card header", async () => {
|
||||
mocks.getMyLinks.mockResolvedValue([{ ...LINK, enabled: false }]);
|
||||
const { container } = render(<MyQrPage />);
|
||||
const badge = await screen.findByText("Switched off");
|
||||
expect(badge.closest("[data-slot=card-header]")).toBeTruthy();
|
||||
expect(container.querySelectorAll("[data-slot=card]")).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("stacks the QR above its buttons, so a narrow card never overflows", async () => {
|
||||
mocks.getMyLinks.mockResolvedValue([LINK]);
|
||||
const { container } = render(<MyQrPage />);
|
||||
await screen.findByText("Expo 2026");
|
||||
const item = container.querySelector("[data-slot=card-content] > div")!;
|
||||
expect(item).toHaveClass("sm:flex-col");
|
||||
expect(item).not.toHaveClass("sm:flex-row");
|
||||
});
|
||||
});
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import { PageHeader } from "@/app/components/ui/page-header";
|
||||
import { CalendarDays, MapPin } from "lucide-react";
|
||||
import { Card, CardAction, CardContent, CardDescription, CardHeader, CardTitle } from "@/app/components/ui/card";
|
||||
import { Badge } from "@/app/components/ui/badge";
|
||||
import { EmptyState, ErrorState } from "@/app/components/ui/states";
|
||||
import { QrCodeItem } from "@/app/components/registration/QrCodeItem";
|
||||
@@ -23,15 +25,31 @@ export default function MyQrPage() {
|
||||
<PageHeader title={t("QrMyTitle")} />
|
||||
{error && <ErrorState message={error} />}
|
||||
{links?.length === 0 && <EmptyState title={t("QrMyNone")} />}
|
||||
<div className="space-y-3">
|
||||
<div className="grid gap-4 md:grid-cols-2 xl:grid-cols-3">
|
||||
{links?.map((l) => (
|
||||
<div key={l.token} className="space-y-1">
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{l.startDate} - {l.endDate} | {l.location}
|
||||
</p>
|
||||
{!l.enabled && <Badge variant="warning">{t("QrSwitchedOff")}</Badge>}
|
||||
<QrCodeItem label={l.eventName} eventName={l.eventName} token={l.token} enabled={l.enabled} personal />
|
||||
</div>
|
||||
<Card key={l.token}>
|
||||
<CardHeader>
|
||||
<CardTitle>{l.eventName}</CardTitle>
|
||||
{!l.enabled && (
|
||||
<CardAction>
|
||||
<Badge variant="warning">{t("QrSwitchedOff")}</Badge>
|
||||
</CardAction>
|
||||
)}
|
||||
<CardDescription className="space-y-1">
|
||||
<p className="flex items-center gap-2">
|
||||
<CalendarDays aria-hidden="true" className="size-4 shrink-0" />
|
||||
<span>{l.startDate} - {l.endDate}</span>
|
||||
</p>
|
||||
<p className="flex items-center gap-2">
|
||||
<MapPin aria-hidden="true" className="size-4 shrink-0" />
|
||||
<span>{l.location}</span>
|
||||
</p>
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<QrCodeItem eventName={l.eventName} token={l.token} enabled={l.enabled} personal className="border-0 p-0 sm:flex-col sm:items-start" />
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
|
||||
@@ -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(<RegisterPage />);
|
||||
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(<RegisterPage />);
|
||||
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(<RegisterPage />);
|
||||
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(<RegisterPage />);
|
||||
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(<RegisterPage />);
|
||||
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();
|
||||
});
|
||||
});
|
||||
@@ -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 = <p role="status">{t("UiLoading")}</p>;
|
||||
else if (phase === "inactive") body = <p role="alert">{t("RegInactive")}</p>;
|
||||
else if (phase === "done") {
|
||||
body = (
|
||||
<div className="space-y-4">
|
||||
<p role="status" className="text-lg font-medium">{t("RegThanks", { event: info?.eventName ?? "" })}</p>
|
||||
<Button className="h-11" onClick={() => setPhase("form")}>{t("RegAnother")}</Button>
|
||||
</div>
|
||||
);
|
||||
} else if (info) {
|
||||
body = <RegistrationForm info={info} submit={(b) => submitRegistration(token, b)} onDone={() => setPhase("done")} onInactive={() => setPhase("inactive")} />;
|
||||
} else body = <p role="alert" className="text-sm text-destructive">{loadError}</p>;
|
||||
|
||||
return <main className="mx-auto w-full max-w-md px-4 py-6">{body}</main>;
|
||||
if (phase === "loading") return <VisitorCard><VisitorState h1 icon={Loader2} heading={t("UiLoading")} role="status" /></VisitorCard>;
|
||||
if (phase === "inactive") return <VisitorCard><VisitorState h1 icon={AlertCircle} heading={t("RegInactive")} role="alert" /></VisitorCard>;
|
||||
if (!info) return <VisitorCard><VisitorState h1 icon={AlertCircle} heading={loadError ?? ""} role="alert" tone="error" /></VisitorCard>;
|
||||
return (
|
||||
<VisitorCard event={info}>
|
||||
{phase === "done" ? (
|
||||
<VisitorState icon={CheckCircle2} heading={t("RegThanks", { event: info.eventName })} role="status" action={<Button className="h-11" onClick={() => setPhase("form")}>{t("RegAnother")}</Button>} />
|
||||
) : (
|
||||
<RegistrationForm info={info} submit={(b) => submitRegistration(token, b)} onDone={() => setPhase("done")} onInactive={() => setPhase("inactive")} />
|
||||
)}
|
||||
</VisitorCard>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user