From 0027f294f29c0df257def821ddaf31c0c9be4f8b Mon Sep 17 00:00:00 2001 From: ngqile Date: Tue, 1 Dec 2026 21:13:24 +0800 Subject: [PATCH] feat: event guests, numbers, limits, check-in code and print cards in the portal Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM --- .../changes/add-event-invitations/design.md | 6 + .../changes/add-event-invitations/tasks.md | 2 +- .../app/api/eventGuestsRoutes.test.ts | 75 ++++ .../app/api/events/[uuid]/[...path]/route.ts | 34 ++ .../app/companyScope.forms.test.tsx | 6 +- .../app/components/app/AppShell.tsx | 2 +- .../app/components/app/Header.tsx | 2 +- .../app/components/app/Sidebar.tsx | 2 +- .../events/EventForm.limits.test.tsx | 76 ++++ .../app/components/events/EventForm.tsx | 58 ++- .../app/components/events/GuestsCard.test.tsx | 293 +++++++++++++++ .../app/components/events/GuestsCard.tsx | 345 ++++++++++++++++++ .../RegistrationQrCard.checkin.test.tsx | 76 ++++ .../components/events/RegistrationQrCard.tsx | 48 ++- .../components/registration/QrCodeItem.tsx | 5 +- .../app/events/[uuid]/page.tsx | 3 + .../app/events/[uuid]/print/page.test.tsx | 81 ++++ .../app/events/[uuid]/print/page.tsx | 85 +++++ .../app/lib/i18n/defaultMessages.ts | 42 +++ .../app/lib/services/adminGuests.test.ts | 28 ++ .../app/lib/services/adminGuests.ts | 55 +++ solvway-admin-portal/app/lib/types.ts | 5 + 22 files changed, 1317 insertions(+), 12 deletions(-) create mode 100644 solvway-admin-portal/app/api/eventGuestsRoutes.test.ts create mode 100644 solvway-admin-portal/app/api/events/[uuid]/[...path]/route.ts create mode 100644 solvway-admin-portal/app/components/events/EventForm.limits.test.tsx create mode 100644 solvway-admin-portal/app/components/events/GuestsCard.test.tsx create mode 100644 solvway-admin-portal/app/components/events/GuestsCard.tsx create mode 100644 solvway-admin-portal/app/components/events/RegistrationQrCard.checkin.test.tsx create mode 100644 solvway-admin-portal/app/events/[uuid]/print/page.test.tsx create mode 100644 solvway-admin-portal/app/events/[uuid]/print/page.tsx create mode 100644 solvway-admin-portal/app/lib/services/adminGuests.test.ts create mode 100644 solvway-admin-portal/app/lib/services/adminGuests.ts diff --git a/openspec/changes/add-event-invitations/design.md b/openspec/changes/add-event-invitations/design.md index 3e44eb6..67a6f92 100644 --- a/openspec/changes/add-event-invitations/design.md +++ b/openspec/changes/add-event-invitations/design.md @@ -194,3 +194,9 @@ Add these anchored method and path pairs: 4. A super admin grants Event guests to the admin roles under Roles. Rollback: `sql/99-rollback.sql` drops the table and columns and deletes the module, losing guests and attendance marks. Redeploy the previous images. + +## Build notes (portal) + +- Add guest and Paste list are inline forms in the Guests section, not dialogs. +- A pasted line has no salesperson column; set one with Add guest. The counter refuses a salesperson who is not on the event team (`NOT_ON_TEAM`). +- The print page is gated like the other event sub-pages (`RequireModule pathname="/events"`, BO_EVENTS); ROUTE_MODULES has no per-sub-page entries. diff --git a/openspec/changes/add-event-invitations/tasks.md b/openspec/changes/add-event-invitations/tasks.md index 3be85e3..da6b9b6 100644 --- a/openspec/changes/add-event-invitations/tasks.md +++ b/openspec/changes/add-event-invitations/tasks.md @@ -140,7 +140,7 @@ Every portal verify must report the exit codes of lint, tsc and vitest. Vitest e - **`/r/`:** works unchanged. - Scope: `solvway-admin-portal/app/**`, `solvway-admin-portal/middleware*.test.ts` - Verify: `cd solvway-admin-portal && npm run lint && npx tsc --noEmit && npx vitest run` -- [ ] 5.2 Event page: the Guests section, the numbers strip, the capacity and cap fields, the check-in code in the QR card, Print cards (`/events/[uuid]/print`), and Copy all links. +- [x] 5.2 Event page: the Guests section, the numbers strip, the capacity and cap fields, the check-in code in the QR card, Print cards (`/events/[uuid]/print`), and Copy all links. - Depends on: 3.1, 5.1 - Tests first: - **Guest actions:** shown only with `BO_EVENT_GUESTS`. diff --git a/solvway-admin-portal/app/api/eventGuestsRoutes.test.ts b/solvway-admin-portal/app/api/eventGuestsRoutes.test.ts new file mode 100644 index 0000000..7921544 --- /dev/null +++ b/solvway-admin-portal/app/api/eventGuestsRoutes.test.ts @@ -0,0 +1,75 @@ +import { describe, it, expect, vi, beforeEach } from "vitest"; + +const mocks = vi.hoisted(() => ({ callMobileApi: vi.fn(), getToken: vi.fn() })); +vi.mock("@/app/lib/server/mobileApi", () => ({ callMobileApi: mocks.callMobileApi })); +vi.mock("@/app/lib/server/session", () => ({ getToken: mocks.getToken })); + +import { GET, POST, DELETE } from "./events/[uuid]/[...path]/route"; + +const req = (url = "http://localhost/x", init?: RequestInit) => new Request(url, init) as never; +const p = (uuid: string, ...path: string[]) => ({ params: Promise.resolve({ uuid, path }) }); + +beforeEach(() => { + mocks.callMobileApi.mockReset().mockResolvedValue({ ok: true, data: { ok: 1 } }); + mocks.getToken.mockReset().mockResolvedValue("jwt"); +}); + +describe("event guest proxies", () => { + it("require a session", async () => { + mocks.getToken.mockResolvedValue(null); + expect((await GET(req(), p("e", "guests"))).status).toBe(401); + expect((await POST(req(), p("e", "guests"))).status).toBe(401); + expect((await DELETE(req(), p("e", "guests", "3"))).status).toBe(401); + expect(mocks.callMobileApi).not.toHaveBeenCalled(); + }); + + it("forward guests, check-in, attendance, preview, send and delete with the token", async () => { + await GET(req(), p("e1", "guests")); + await GET(req(), p("e1", "checkin")); + await GET(req(), p("e1", "attendance")); + await POST(req("http://localhost/x?preview=true", { method: "POST", body: '{"guests":[]}' }), p("e1", "guests")); + await POST(req("http://localhost/x", { method: "POST", body: '{"guests":[]}' }), p("e1", "guests")); + await POST(req("http://localhost/x", { method: "POST", body: '{"allUnsent":true}' }), p("e1", "guests", "send")); + await DELETE(req(), p("e1", "guests", "7")); + expect(mocks.callMobileApi.mock.calls).toEqual([ + ["/api/admin/events/e1/guests", { token: "jwt" }], + ["/api/admin/events/e1/checkin", { token: "jwt" }], + ["/api/admin/events/e1/attendance", { token: "jwt" }], + ["/api/admin/events/e1/guests?preview=true", { method: "POST", body: { guests: [] }, token: "jwt" }], + ["/api/admin/events/e1/guests", { method: "POST", body: { guests: [] }, token: "jwt" }], + ["/api/admin/events/e1/guests/send", { method: "POST", body: { allUnsent: true }, token: "jwt" }], + ["/api/admin/events/e1/guests/7", { method: "DELETE", token: "jwt" }], + ]); + }); + + it("answers a delete with an empty success body", async () => { + mocks.callMobileApi.mockResolvedValue({ ok: true, data: undefined }); + const res = await DELETE(req(), p("e1", "guests", "7")); + expect(res.status).toBe(200); + expect(await res.json()).toEqual({}); + }); + + it("passes the upstream error code and status through", async () => { + mocks.callMobileApi.mockResolvedValue({ ok: false, error: "Registered", status: 409, code: "GUEST_REGISTERED" }); + const res = await DELETE(req(), p("e1", "guests", "7")); + expect(res.status).toBe(409); + expect(await res.json()).toEqual({ error: "Registered", code: "GUEST_REGISTERED" }); + }); + + it("refuse paths other than guests, checkin and attendance", async () => { + for (const path of [["registration-links"], ["guests", ".."], []]) { + expect((await GET(req(), p("e1", ...path))).status).toBe(400); + } + expect(mocks.callMobileApi).not.toHaveBeenCalled(); + }); + + it("refuse an event id with path characters before forwarding", async () => { + for (const uuid of ["..", "a/b", "a%2Fb", "a b", "a?x=1", ""]) { + expect((await GET(req(), p(uuid, "guests"))).status).toBe(400); + expect((await DELETE(req(), p(uuid, "guests", "3"))).status).toBe(400); + } + expect(mocks.callMobileApi).not.toHaveBeenCalled(); + await GET(req(), p("3f2a-9c", "guests")); + expect(mocks.callMobileApi).toHaveBeenCalledTimes(1); + }); +}); diff --git a/solvway-admin-portal/app/api/events/[uuid]/[...path]/route.ts b/solvway-admin-portal/app/api/events/[uuid]/[...path]/route.ts new file mode 100644 index 0000000..b0dfd9b --- /dev/null +++ b/solvway-admin-portal/app/api/events/[uuid]/[...path]/route.ts @@ -0,0 +1,34 @@ +import { NextResponse, type NextRequest } from "next/server"; +import { callMobileApi } from "@/app/lib/server/mobileApi"; +import { getToken } from "@/app/lib/server/session"; +import { badRequest, errorResponse, unauthorized } from "@/app/lib/server/apiRoute"; + +// One proxy for the event guest, check-in and attendance endpoints; mobile-api owns validation and the BO_EVENTS / BO_EVENT_GUESTS guards. +type Ctx = { params: Promise<{ uuid: string; path: string[] }> }; + +const ALLOWED = /^(guests(\/(send|\d+))?|checkin|attendance)$/; +// Event uuids are strings, not numbers; word characters and hyphens cover them and nothing that can alter the upstream path. +const EVENT_ID = /^[\w-]+$/; + +async function forward(req: NextRequest, { params }: Ctx, method?: "POST" | "DELETE") { + const token = await getToken(); + if (!token) return unauthorized(); + const { uuid, path } = await params; + if (!EVENT_ID.test(uuid) || !ALLOWED.test(path.join("/"))) return badRequest("Invalid path."); + // Only the preview flag is forwarded; nothing else from the browser's query string. + const preview = new URL(req.url).searchParams.getAll("preview").includes("true") ? "?preview=true" : ""; + const target = `/api/admin/events/${encodeURIComponent(uuid)}/${path.map(encodeURIComponent).join("/")}${preview}`; + const result = + method === "POST" + ? await callMobileApi(target, { method, body: await req.json().catch(() => ({})), token }) + : method + ? await callMobileApi(target, { method, token }) + : await callMobileApi(target, { token }); + if (!result.ok) return errorResponse(result); + // A delete answers 204 with no body. + return NextResponse.json(result.data ?? {}); +} + +export const GET = (req: NextRequest, ctx: Ctx) => forward(req, ctx); +export const POST = (req: NextRequest, ctx: Ctx) => forward(req, ctx, "POST"); +export const DELETE = (req: NextRequest, ctx: Ctx) => forward(req, ctx, "DELETE"); diff --git a/solvway-admin-portal/app/companyScope.forms.test.tsx b/solvway-admin-portal/app/companyScope.forms.test.tsx index 35ab904..d6c78dc 100644 --- a/solvway-admin-portal/app/companyScope.forms.test.tsx +++ b/solvway-admin-portal/app/companyScope.forms.test.tsx @@ -31,7 +31,7 @@ const ROLES = [ beforeEach(() => { mocks.listAdminRoles.mockReset().mockResolvedValue(ROLES); mocks.listSalespersonOptions.mockReset().mockResolvedValue([{ id: 1, name: "Alice", username: "alice" }]); - mocks.useAdminAuth.mockReset().mockReturnValue({ id: 9, isSuper: true }); + mocks.useAdminAuth.mockReset().mockReturnValue({ id: 9, isSuper: true, hasModule: () => false }); mocks.useCompanyScope.mockReset().mockReturnValue(scope(2)); }); @@ -85,7 +85,7 @@ describe("UserForm company", () => { }); it("does not show Company to staff or send it", async () => { - mocks.useAdminAuth.mockReturnValue({ id: 9, isSuper: false }); + mocks.useAdminAuth.mockReturnValue({ id: 9, isSuper: false, hasModule: () => false }); const onSubmit = vi.fn().mockResolvedValue(undefined); const user = userEvent.setup(); render(); @@ -131,7 +131,7 @@ describe("EventForm company", () => { }); it("does not show Company to staff", async () => { - mocks.useAdminAuth.mockReturnValue({ id: 9, isSuper: false }); + mocks.useAdminAuth.mockReturnValue({ id: 9, isSuper: false, hasModule: () => false }); render(); await waitFor(() => expect(mocks.listSalespersonOptions).toHaveBeenCalled()); expect(screen.queryByRole("combobox", { name: "Company" })).not.toBeInTheDocument(); diff --git a/solvway-admin-portal/app/components/app/AppShell.tsx b/solvway-admin-portal/app/components/app/AppShell.tsx index 971dd2f..b4f53f1 100644 --- a/solvway-admin-portal/app/components/app/AppShell.tsx +++ b/solvway-admin-portal/app/components/app/AppShell.tsx @@ -60,7 +60,7 @@ export default function AppShell({ children }: { children: React.ReactNode }) {
{children}
{/* The sidebar (and its credit) is hidden below lg, so repeat the credit under the content there. */} -
+
diff --git a/solvway-admin-portal/app/components/app/Header.tsx b/solvway-admin-portal/app/components/app/Header.tsx index 5a580ec..fad4c57 100644 --- a/solvway-admin-portal/app/components/app/Header.tsx +++ b/solvway-admin-portal/app/components/app/Header.tsx @@ -55,7 +55,7 @@ export default function Header() { const initial = (name ?? "?").slice(0, 1).toUpperCase(); return ( -
+
+ + +
+ +