feat: My QR share and full screen, new-code notice, attended and source on event leads
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
This commit is contained in:
1 parent
3af5cccd59
commit
5ef139f81f
18 files changed
+369
-11
No files matched your search
@@ -167,7 +167,7 @@ Every portal verify must report the exit codes of lint, tsc and vitest. Vitest e
|
||||
- **`ROUTE_MODULES`:** maps the print route.
|
||||
- Scope: `solvway-admin-portal/app/**`
|
||||
- Verify: as 5.1
|
||||
- [ ] 5.3 My QR codes (Share, full screen), the new-code notice in the shell, and the event leads Attended column and filter, Source column and Attended checkbox in the edit form.
|
||||
- [x] 5.3 My QR codes (Share, full screen), the new-code notice in the shell, and the event leads Attended column and filter, Source column and Attended checkbox in the edit form.
|
||||
- Depends on: 5.2, 3.3 (event leads part)
|
||||
- Tests first:
|
||||
- **Share:** uses `navigator.share` when present, otherwise the clipboard.
|
||||
|
||||
@@ -14,6 +14,7 @@ vi.mock("@/app/lib/AdminAuthContext", () => ({
|
||||
}));
|
||||
|
||||
vi.mock("./Sidebar", () => ({ default: () => <div data-testid="sidebar" /> }));
|
||||
vi.mock("./NewCodeNotice", () => ({ NewCodeNotice: () => <div data-testid="notice" /> }));
|
||||
vi.mock("./Header", () => ({ default: () => <div data-testid="header" /> }));
|
||||
|
||||
import AppShell from "./AppShell";
|
||||
@@ -53,6 +54,13 @@ describe("AppShell", () => {
|
||||
expect(nav.replace).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("shows the new-code notice in the signed-in shell", () => {
|
||||
auth.loading = false;
|
||||
auth.name = "Admin User";
|
||||
render(<AppShell>content</AppShell>);
|
||||
expect(screen.getByTestId("notice")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("shows the Containerverse credit under the content on small screens (the sidebar is hidden there)", () => {
|
||||
auth.loading = false;
|
||||
auth.name = "Admin User";
|
||||
|
||||
@@ -5,6 +5,7 @@ import { usePathname, useRouter } from "next/navigation";
|
||||
import { useAdminAuth } from "@/app/lib/AdminAuthContext";
|
||||
import { isPublicPath } from "@/app/lib/routeGuard";
|
||||
import { CompanyScopeProvider } from "@/app/lib/CompanyScope";
|
||||
import { NewCodeNotice } from "./NewCodeNotice";
|
||||
import Header from "./Header";
|
||||
import Sidebar from "./Sidebar";
|
||||
import PoweredBy from "./PoweredBy";
|
||||
@@ -58,7 +59,10 @@ export default function AppShell({ children }: { children: React.ReactNode }) {
|
||||
overflow-x-auto container. */}
|
||||
<div className="flex min-h-svh min-w-0 flex-1 flex-col">
|
||||
<Header />
|
||||
<main className="mx-auto w-full max-w-[var(--content-max-width)] min-w-0 flex-1 p-4">{children}</main>
|
||||
<main className="mx-auto w-full max-w-[var(--content-max-width)] min-w-0 flex-1 p-4">
|
||||
<NewCodeNotice />
|
||||
{children}
|
||||
</main>
|
||||
{/* The sidebar (and its credit) is hidden below lg, so repeat the credit under the content there. */}
|
||||
<div data-testid="mobile-credit" className="px-4 pb-4 text-center lg:hidden print:hidden">
|
||||
<PoweredBy />
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { describe, it, expect, vi, beforeEach } from "vitest";
|
||||
|
||||
const mocks = vi.hoisted(() => ({ getMyLinks: vi.fn() }));
|
||||
vi.mock("@/app/lib/services/adminRegistration", () => mocks);
|
||||
|
||||
import { NewCodeNotice } from "./NewCodeNotice";
|
||||
|
||||
const daysAgo = (n: number) => new Date(Date.now() - n * 86_400_000).toISOString();
|
||||
const link = (token: string, addedAt: string | null) => ({ eventUuid: "u", eventName: "KL Expo", startDate: "", endDate: "", location: "", token, enabled: true, addedAt });
|
||||
|
||||
beforeEach(() => {
|
||||
mocks.getMyLinks.mockReset();
|
||||
localStorage.clear();
|
||||
});
|
||||
|
||||
describe("NewCodeNotice", () => {
|
||||
it("links to My QR codes for a code added within 7 days", async () => {
|
||||
mocks.getMyLinks.mockResolvedValue([link("t1", daysAgo(1))]);
|
||||
render(<NewCodeNotice />);
|
||||
const a = await screen.findByRole("link", { name: "My QR codes" });
|
||||
expect(a.getAttribute("href")).toBe("/my-qr");
|
||||
});
|
||||
|
||||
it("stays hidden for old codes and codes without addedAt", async () => {
|
||||
mocks.getMyLinks.mockResolvedValue([link("t1", daysAgo(8)), link("t2", null)]);
|
||||
render(<NewCodeNotice />);
|
||||
await vi.waitFor(() => expect(mocks.getMyLinks).toHaveBeenCalled());
|
||||
expect(screen.queryByRole("link", { name: "My QR codes" })).toBeNull();
|
||||
});
|
||||
|
||||
it("is dismissed per code, and stays dismissed after a reload", async () => {
|
||||
mocks.getMyLinks.mockResolvedValue([link("t1", daysAgo(1))]);
|
||||
const first = render(<NewCodeNotice />);
|
||||
await userEvent.click(await screen.findByRole("button", { name: "Dismiss" }));
|
||||
expect(screen.queryByRole("link", { name: "My QR codes" })).toBeNull();
|
||||
first.unmount();
|
||||
render(<NewCodeNotice />);
|
||||
await vi.waitFor(() => expect(mocks.getMyLinks).toHaveBeenCalledTimes(2));
|
||||
expect(screen.queryByRole("link", { name: "My QR codes" })).toBeNull();
|
||||
});
|
||||
|
||||
it("shows again for a different new code", async () => {
|
||||
localStorage.setItem("qrNoticeDismissed:t1", "1");
|
||||
mocks.getMyLinks.mockResolvedValue([link("t1", daysAgo(1)), link("t2", daysAgo(2))]);
|
||||
render(<NewCodeNotice />);
|
||||
await screen.findByRole("link", { name: "My QR codes" });
|
||||
});
|
||||
|
||||
it("shows nothing when the codes cannot be loaded", async () => {
|
||||
mocks.getMyLinks.mockRejectedValue(new Error("down"));
|
||||
render(<NewCodeNotice />);
|
||||
await vi.waitFor(() => expect(mocks.getMyLinks).toHaveBeenCalled());
|
||||
expect(screen.queryByRole("link")).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,46 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import Link from "next/link";
|
||||
import { X } from "lucide-react";
|
||||
import { getMyLinks } from "@/app/lib/services/adminRegistration";
|
||||
import { useT } from "@/app/lib/i18n/MessagesProvider";
|
||||
|
||||
const WEEK_MS = 7 * 86_400_000;
|
||||
const key = (token: string) => `qrNoticeDismissed:${token}`;
|
||||
const dismissed = (token: string) => {
|
||||
try { return localStorage.getItem(key(token)) !== null; } catch { return false; }
|
||||
};
|
||||
|
||||
/** Banner for personal codes added in the last 7 days; dismissed per code. */
|
||||
export function NewCodeNotice() {
|
||||
const t = useT();
|
||||
const [tokens, setTokens] = useState<string[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
getMyLinks()
|
||||
.then((links) => setTokens(links
|
||||
.filter((l) => l.addedAt && Date.now() - Date.parse(l.addedAt) < WEEK_MS && !dismissed(l.token))
|
||||
.map((l) => l.token)))
|
||||
.catch(() => {}); // a notice is optional; stay silent if the codes cannot load
|
||||
}, []);
|
||||
|
||||
if (tokens.length === 0) return null;
|
||||
|
||||
const dismiss = () => {
|
||||
try { tokens.forEach((tk) => localStorage.setItem(key(tk), "1")); } catch { /* the notice just returns next load */ }
|
||||
setTokens([]);
|
||||
};
|
||||
|
||||
return (
|
||||
<div role="status" className="mb-4 flex items-center justify-between gap-3 rounded-lg border bg-card p-3 text-sm">
|
||||
<p>
|
||||
{t("QrNewCode")}{" "}
|
||||
<Link href="/my-qr" className="font-medium text-primary underline-offset-4 hover:underline">{t("QrMyTitle")}</Link>
|
||||
</p>
|
||||
<button type="button" aria-label={t("QrDismiss")} onClick={dismiss} className="flex size-11 shrink-0 items-center justify-center rounded-md hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-none">
|
||||
<X aria-hidden="true" className="size-4" />
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -2,8 +2,9 @@
|
||||
|
||||
import { useRef, useState } from "react";
|
||||
import { QRCodeCanvas, QRCodeSVG } from "qrcode.react";
|
||||
import { Copy, Download } from "lucide-react";
|
||||
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 { useT } from "@/app/lib/i18n/MessagesProvider";
|
||||
|
||||
@@ -18,6 +19,7 @@ export function QrCodeItem({
|
||||
enabled,
|
||||
onToggle,
|
||||
prefix = "r",
|
||||
personal = false,
|
||||
}: {
|
||||
label: string;
|
||||
eventName: string;
|
||||
@@ -28,16 +30,36 @@ export function QrCodeItem({
|
||||
onToggle?: (enabled: boolean) => void;
|
||||
/** Public path the code opens: r = registration (default), c = check-in. */
|
||||
prefix?: "r" | "c";
|
||||
/** A user's own code (My QR codes): adds Share and Show full screen for use at the booth. */
|
||||
personal?: boolean;
|
||||
}) {
|
||||
const t = useT();
|
||||
const canvas = useRef<HTMLCanvasElement>(null);
|
||||
const [copied, setCopied] = useState(false);
|
||||
const [copyFailed, setCopyFailed] = useState(false);
|
||||
const [full, setFull] = useState(false);
|
||||
const link = `${window.location.origin}/${prefix}/${token}`;
|
||||
|
||||
async function copy() {
|
||||
await navigator.clipboard.writeText(link);
|
||||
setCopied(true);
|
||||
setTimeout(() => setCopied(false), 2000);
|
||||
try {
|
||||
await navigator.clipboard.writeText(link);
|
||||
setCopyFailed(false);
|
||||
setCopied(true);
|
||||
setTimeout(() => setCopied(false), 2000);
|
||||
} catch {
|
||||
setCopied(false);
|
||||
setCopyFailed(true);
|
||||
}
|
||||
}
|
||||
|
||||
async function share() {
|
||||
if (!navigator.share) return copy();
|
||||
try {
|
||||
await navigator.share({ title: eventName, text: t("QrShareText", { event: eventName }), url: link });
|
||||
} catch (err) {
|
||||
// Dismissing the share sheet is an AbortError; anything else falls back to copying.
|
||||
if ((err as { name?: string }).name !== "AbortError") return copy();
|
||||
}
|
||||
}
|
||||
|
||||
function download() {
|
||||
@@ -64,9 +86,32 @@ export function QrCodeItem({
|
||||
<Download aria-hidden="true" className="size-4" />
|
||||
{t("QrDownload")}
|
||||
</Button>
|
||||
{personal && (
|
||||
<>
|
||||
<Button variant="outline" className="min-h-11" onClick={share}>
|
||||
<Share2 aria-hidden="true" className="size-4" />
|
||||
{t("QrShare")}
|
||||
</Button>
|
||||
<Button variant="outline" className="min-h-11" onClick={() => setFull(true)}>
|
||||
<Maximize2 aria-hidden="true" className="size-4" />
|
||||
{t("QrFullScreen")}
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
{onToggle && <Switch checked={enabled} onCheckedChange={onToggle} aria-label={t("QrEnabled")} />}
|
||||
</div>
|
||||
{copyFailed && <p role="alert" className="text-sm text-destructive">{t("CopyFailed")}</p>}
|
||||
</div>
|
||||
{personal && (
|
||||
<Dialog open={full} onOpenChange={setFull}>
|
||||
<DialogContent aria-label={eventName} aria-describedby={undefined} className="max-w-none place-items-center border-0">
|
||||
{/* A light quiet zone around the QR, so it scans in dark mode too. */}
|
||||
<div className="bg-white p-4">
|
||||
<QRCodeSVG value={link} size={512} style={{ width: "min(80vw, 80vh)", height: "min(80vw, 80vh)" }} />
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -22,6 +22,8 @@ const ALLOW: Record<string, string[]> = {
|
||||
// A QR code needs a light quiet zone to scan; a theme surface would put dark modules on dark in
|
||||
// dark mode.
|
||||
"app/pos/_components/SplitTenderPanel.tsx": ["bg-white"],
|
||||
// The full-screen QR sits on a white quiet zone so it scans in dark mode.
|
||||
"app/components/registration/QrCodeItem.tsx": ["bg-white"],
|
||||
// A sent email's HTML is authored for a white mail-client canvas; a theme surface would put the
|
||||
// email's dark text on dark in dark mode.
|
||||
"app/email-templates/logs/[id]/page.tsx": ["bg-white"],
|
||||
|
||||
@@ -240,4 +240,22 @@ describe("EventLeadPage", { timeout: 20000 }, () => {
|
||||
await user.click(screen.getByRole("button", { name: "Save" }));
|
||||
expect(await screen.findByRole("alert")).toHaveTextContent("Could not save the lead. Please try again.");
|
||||
});
|
||||
|
||||
it("sends attended when staff tick it", async () => {
|
||||
const user = await open();
|
||||
await user.click(screen.getByLabelText("Attended"));
|
||||
await user.click(screen.getByRole("button", { name: "Save" }));
|
||||
await waitFor(() => expect(mocks.updateEventLead).toHaveBeenCalledTimes(1));
|
||||
expect(mocks.updateEventLead).toHaveBeenCalledWith("evt-1", "el-1", { ...PAYLOAD, attended: true });
|
||||
});
|
||||
|
||||
it("shows a ticked Attended box for an attended lead and sends false when unticked", async () => {
|
||||
const user = await open({ attended: true });
|
||||
const box = screen.getByLabelText("Attended") as HTMLInputElement;
|
||||
expect(box.checked).toBe(true);
|
||||
await user.click(box);
|
||||
await user.click(screen.getByRole("button", { name: "Save" }));
|
||||
await waitFor(() => expect(mocks.updateEventLead).toHaveBeenCalledTimes(1));
|
||||
expect(mocks.updateEventLead).toHaveBeenCalledWith("evt-1", "el-1", { ...PAYLOAD, attended: false });
|
||||
});
|
||||
});
|
||||
@@ -49,6 +49,8 @@ function EventLead() {
|
||||
const [interestIds, setInterestIds] = useState<number[]>([]);
|
||||
const [nextFollowUpDate, setNextFollowUpDate] = useState("");
|
||||
const [notes, setNotes] = useState("");
|
||||
// Sent only once staff touch the box, so saving other fields never changes attendance.
|
||||
const [attended, setAttended] = useState<boolean | undefined>(undefined);
|
||||
const [fieldErrors, setFieldErrors] = useState<Record<string, string>>({});
|
||||
const [formError, setFormError] = useState<string | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
@@ -124,6 +126,7 @@ function EventLead() {
|
||||
interestIds,
|
||||
nextFollowUpDate: nextFollowUpDate || null,
|
||||
notes: notes.trim() || null,
|
||||
attended,
|
||||
});
|
||||
router.push(back);
|
||||
} catch (err) {
|
||||
@@ -193,6 +196,11 @@ function EventLead() {
|
||||
{fieldError("interestIds")}
|
||||
</fieldset>
|
||||
|
||||
<label className="flex min-h-11 items-center gap-3 text-sm">
|
||||
<input type="checkbox" className="size-5" checked={attended ?? lead.attended ?? false} onChange={(e) => setAttended(e.target.checked)} disabled={busy} />
|
||||
{t("GuestAttended")}
|
||||
</label>
|
||||
|
||||
{field("nextFollowUpDate", t("LeadNextFollowUp"),
|
||||
<DatePicker {...fieldProps("nextFollowUpDate")} className="h-11" value={nextFollowUpDate} onChange={setNextFollowUpDate} disabled={busy} />)}
|
||||
{field("notes", t("LeadNotes"),
|
||||
|
||||
@@ -121,6 +121,50 @@ describe("EventLeadsDetailPage (listing)", { timeout: 20000 }, () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("shows Attended and Source as the last two columns", async () => {
|
||||
mocks.listEventLeads.mockResolvedValue({
|
||||
items: [{
|
||||
eventLeadUuid: "el-1", eventUuid: "evt-1", leadUuid: "lead-1", name: "John Doe", mobile: null, email: null,
|
||||
companyName: null, jobTitle: null, leadType: "NEW", salesperson: null, temperature: null, status: "OPEN",
|
||||
interests: [], nextFollowUpDate: null, notes: null, capturedAt: "2025-06-01", attended: true, source: "INVITE",
|
||||
}],
|
||||
total: 1,
|
||||
});
|
||||
render(<EventLeadsDetailPage />);
|
||||
const row = (await screen.findByRole("link", { name: "John Doe" })).closest("tr")!;
|
||||
const headers = screen.getAllByRole("columnheader").map((h) => h.textContent);
|
||||
expect(headers.slice(-2)).toEqual(["Attended", "Source"]);
|
||||
const cells = within(row).getAllByRole("cell").map((c) => c.textContent);
|
||||
expect(cells.slice(-2)).toEqual(["Yes", "Invite"]);
|
||||
});
|
||||
|
||||
it("shows Attended and Source on the phone card", async () => {
|
||||
mocks.listEventLeads.mockResolvedValue({
|
||||
items: [{
|
||||
eventLeadUuid: "el-1", eventUuid: "evt-1", leadUuid: "lead-1", name: "John Doe", mobile: null, email: null,
|
||||
companyName: null, jobTitle: null, leadType: "NEW", salesperson: null, temperature: null, status: "OPEN",
|
||||
interests: [], nextFollowUpDate: null, notes: null, capturedAt: "2025-06-01", attended: true, source: "QR",
|
||||
}],
|
||||
total: 1,
|
||||
});
|
||||
render(<EventLeadsDetailPage />);
|
||||
const card = within(await screen.findByTestId("lead-card"));
|
||||
expect(card.getByText("Attended: Yes")).toBeInTheDocument();
|
||||
expect(card.getByText("Source: QR")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("filters by attendance for the list and the export", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<EventLeadsDetailPage />);
|
||||
await user.click(await screen.findByRole("combobox", { name: /attended filter/i }));
|
||||
await user.click(await screen.findByRole("option", { name: "Not attended" }));
|
||||
await waitFor(() =>
|
||||
expect(mocks.listEventLeads).toHaveBeenLastCalledWith("evt-1", expect.objectContaining({ attended: "false", page: 1 })),
|
||||
);
|
||||
await user.click(screen.getByRole("button", { name: "Export" }));
|
||||
expect(mocks.exportEventLeads.mock.calls[0][1]).toEqual(expect.objectContaining({ attended: "false" }));
|
||||
});
|
||||
|
||||
it("links each lead row/card to its detail page", async () => {
|
||||
mocks.listEventLeads.mockResolvedValue({
|
||||
items: [{
|
||||
|
||||
@@ -22,10 +22,12 @@ import { useCompanyScope } from "@/app/lib/CompanyScope";
|
||||
import { useT } from "@/app/lib/i18n/MessagesProvider";
|
||||
import { formatDmy } from "@/app/lib/date-input";
|
||||
|
||||
const DEFAULTS = { salespersonId: "", temperature: "", status: "", interestId: "", leadType: "" };
|
||||
const DEFAULTS = { salespersonId: "", temperature: "", status: "", interestId: "", leadType: "", attended: "" };
|
||||
const TEMPERATURE_OPTIONS = [{ value: "HOT", label: "LeadHot" }, { value: "WARM", label: "LeadWarm" }, { value: "COLD", label: "LeadCold" }];
|
||||
const STATUS_OPTIONS = [{ value: "OPEN", label: "LeadOpen" }, { value: "CONTACTED", label: "LeadContacted" }, { value: "QUALIFIED", label: "LeadQualified" }, { value: "WON", label: "LeadWon" }, { value: "LOST", label: "LeadLost" }];
|
||||
const LEAD_TYPE_OPTIONS = [{ value: "NEW", label: "LeadNew" }, { value: "EXISTING", label: "LeadExisting" }];
|
||||
const ATTENDED_OPTIONS = [{ value: "true", label: "GuestAttended" }, { value: "false", label: "LeadNotAttended" }];
|
||||
const SOURCE_LABEL = { STAFF: "LeadSourceStaff", QR: "LeadSourceQr", INVITE: "LeadSourceInvite" } as const;
|
||||
const TEMPERATURE_BADGE = { HOT: "negative", WARM: "warning", COLD: "neutral" } as const;
|
||||
const STATUS_BADGE = { OPEN: "neutral", CONTACTED: "neutral", QUALIFIED: "contrast", WON: "positive", LOST: "negative" } as const;
|
||||
|
||||
@@ -136,6 +138,11 @@ function EventLeadsDetailPageContent() {
|
||||
[t],
|
||||
);
|
||||
|
||||
const attendedOptions = useMemo(
|
||||
() => ATTENDED_OPTIONS.map((o) => ({ value: o.value, label: t(o.label) })),
|
||||
[t],
|
||||
);
|
||||
|
||||
const columns = useMemo<ColumnDef<EventLeadRow, unknown>[]>(
|
||||
() => [
|
||||
...(showCompanyColumn ? [{ id: "company", cell: ({ row }) => codeOf(row.original.companyId ?? 0), header: t("Company"), enableSorting: false } as ColumnDef<EventLeadRow, unknown>] : []),
|
||||
@@ -208,6 +215,18 @@ function EventLeadsDetailPageContent() {
|
||||
enableSorting: false,
|
||||
cell: ({ row }) => <span className="tabular">{row.original.nextFollowUpDate ? formatDmy(row.original.nextFollowUpDate) : "—"}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: "attended",
|
||||
header: t("GuestAttended"),
|
||||
enableSorting: false,
|
||||
cell: ({ row }) => <span>{row.original.attended == null ? "—" : t(row.original.attended ? "Yes" : "No")}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: "source",
|
||||
header: t("LeadSource"),
|
||||
enableSorting: false,
|
||||
cell: ({ row }) => <span>{row.original.source ? t(SOURCE_LABEL[row.original.source]) : "—"}</span>,
|
||||
},
|
||||
],
|
||||
[t, showCompanyColumn, codeOf],
|
||||
);
|
||||
@@ -254,6 +273,9 @@ function EventLeadsDetailPageContent() {
|
||||
<FilterField label={t("LeadLeadTypeFilter")}>
|
||||
<FilterSelect className="w-full" aria-label={t("LeadLeadTypeFilter")} allLabel={t("All")} options={leadTypeOptions} value={filters.leadType} onChange={leadType => set({ leadType })} />
|
||||
</FilterField>
|
||||
<FilterField label={t("LeadAttendedFilter")}>
|
||||
<FilterSelect className="w-full" aria-label={t("LeadAttendedFilter")} allLabel={t("All")} options={attendedOptions} value={filters.attended} onChange={attended => set({ attended })} />
|
||||
</FilterField>
|
||||
</FilterPanel>
|
||||
|
||||
{/* Desktop table (md+) */}
|
||||
@@ -296,6 +318,12 @@ function EventLeadsDetailPageContent() {
|
||||
<div className="text-sm text-muted-foreground">
|
||||
{t("LeadNextFollowUp")}: {lead.nextFollowUpDate ? formatDmy(lead.nextFollowUpDate) : "—"}
|
||||
</div>
|
||||
<div className="text-sm text-muted-foreground">
|
||||
{t("GuestAttended")}: {lead.attended == null ? "—" : t(lead.attended ? "Yes" : "No")}
|
||||
</div>
|
||||
<div className="text-sm text-muted-foreground">
|
||||
{t("LeadSource")}: {lead.source ? t(SOURCE_LABEL[lead.source]) : "—"}
|
||||
</div>
|
||||
</Link>
|
||||
))}
|
||||
{data.items.length === 0 && !loading && (
|
||||
|
||||
@@ -240,6 +240,7 @@ export const DEFAULT_MESSAGES: Record<string, string> = {
|
||||
RolColRole: "Role",
|
||||
RolManageAccess: "Manage access",
|
||||
RolNoRoles: "No roles found",
|
||||
Yes: "Yes",
|
||||
No: "No",
|
||||
// Event form messages
|
||||
EvtNameRequired: "Name is required.",
|
||||
@@ -312,6 +313,12 @@ export const DEFAULT_MESSAGES: Record<string, string> = {
|
||||
LeadStatusFilter: "Status filter",
|
||||
LeadInterestFilter: "Interest filter",
|
||||
LeadLeadTypeFilter: "Lead type filter",
|
||||
LeadAttendedFilter: "Attended filter",
|
||||
LeadNotAttended: "Not attended",
|
||||
LeadSource: "Source",
|
||||
LeadSourceStaff: "Staff",
|
||||
LeadSourceQr: "QR",
|
||||
LeadSourceInvite: "Invite",
|
||||
LeadHot: "Hot",
|
||||
LeadWarm: "Warm",
|
||||
LeadCold: "Cold",
|
||||
@@ -510,6 +517,11 @@ export const DEFAULT_MESSAGES: Record<string, string> = {
|
||||
QrSaveFailed: "Could not change the code.",
|
||||
QrMyTitle: "My QR codes",
|
||||
QrSwitchedOff: "Switched off",
|
||||
QrShare: "Share",
|
||||
QrShareText: "Register for {event}",
|
||||
QrFullScreen: "Show full screen",
|
||||
QrNewCode: "You have a new registration code.",
|
||||
QrDismiss: "Dismiss",
|
||||
QrMyNone: "You have no registration codes yet.",
|
||||
PrivNotice: "Privacy notice",
|
||||
PrivSave: "Save notice",
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { describe, it, expect, vi, beforeEach } from "vitest";
|
||||
|
||||
const mocks = vi.hoisted(() => ({ apiGet: vi.fn(), apiPost: vi.fn(), apiPut: vi.fn() }));
|
||||
const mocks = vi.hoisted(() => ({ apiGet: vi.fn(), apiPost: vi.fn(), apiPut: vi.fn(), apiDownload: vi.fn() }));
|
||||
vi.mock("@/app/lib/clientApi", () => mocks);
|
||||
|
||||
import {
|
||||
captureEventLead,
|
||||
exportEventLeads,
|
||||
getEventLead,
|
||||
listEventLeadEvents,
|
||||
listEventLeadInterests,
|
||||
@@ -40,6 +41,14 @@ describe("adminEventLeads", () => {
|
||||
expect(out).toEqual({ items: [{ eventLeadUuid: "1" }], total: 41 });
|
||||
});
|
||||
|
||||
it("sends the attended filter to the list and to the export", async () => {
|
||||
mocks.apiGet.mockResolvedValue({ content: [], totalElements: 0 });
|
||||
await listEventLeads("9", { page: 1, pageSize: 20, attended: "false" });
|
||||
expect(mocks.apiGet).toHaveBeenCalledWith("/api/event-leads/9/leads?attended=false&page=0&size=20");
|
||||
await exportEventLeads("9", { attended: "true" });
|
||||
expect(mocks.apiDownload).toHaveBeenCalledWith("/api/event-leads/9/export?attended=true", "event-leads.xlsx");
|
||||
});
|
||||
|
||||
it("treats a malformed page as empty", async () => {
|
||||
mocks.apiGet.mockResolvedValue(null);
|
||||
expect(await listEventLeads("9", { page: 1, pageSize: 20 })).toEqual({ items: [], total: 0 });
|
||||
|
||||
@@ -10,7 +10,7 @@ import type {
|
||||
} from "@/app/lib/types";
|
||||
|
||||
const BASE = "/api/event-leads";
|
||||
const FILTERS = ["salespersonId", "temperature", "status", "interestId", "leadType"] as const;
|
||||
const FILTERS = ["salespersonId", "temperature", "status", "interestId", "leadType", "attended"] as const;
|
||||
|
||||
export type EventLeadFilters = Partial<Record<(typeof FILTERS)[number], string>>;
|
||||
|
||||
|
||||
@@ -14,6 +14,8 @@ export interface MyLink extends RegistrationLink {
|
||||
startDate: string;
|
||||
endDate: string;
|
||||
location: string;
|
||||
/** When the caller joined the event team; null on older rows. */
|
||||
addedAt?: string | null;
|
||||
}
|
||||
export interface PrivacyNotice {
|
||||
id: number;
|
||||
|
||||
@@ -246,6 +246,8 @@ export interface EventLeadRow {
|
||||
notes: string | null;
|
||||
capturedAt: string;
|
||||
companyId?: number;
|
||||
attended?: boolean;
|
||||
source?: "STAFF" | "QR" | "INVITE";
|
||||
}
|
||||
|
||||
export interface EventLeadUpdatePayload {
|
||||
@@ -255,6 +257,7 @@ export interface EventLeadUpdatePayload {
|
||||
interestIds?: number[];
|
||||
nextFollowUpDate?: string | null;
|
||||
notes?: string | null;
|
||||
attended?: boolean;
|
||||
}
|
||||
|
||||
export interface EventLeadCapturePayload extends EventLeadUpdatePayload {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { describe, it, expect, vi, beforeEach } from "vitest";
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import { render, screen, waitFor } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
|
||||
const mocks = vi.hoisted(() => ({ getMyLinks: vi.fn() }));
|
||||
vi.mock("@/app/lib/services/adminRegistration", () => mocks);
|
||||
@@ -39,4 +40,75 @@ describe("My QR codes", () => {
|
||||
render(<MyQrPage />);
|
||||
await screen.findByText("You have no registration codes yet.");
|
||||
});
|
||||
|
||||
describe("Share and full screen", () => {
|
||||
const LINK = { eventUuid: "u1", eventName: "Expo 2026", startDate: "2026-12-01", endDate: "2026-12-02", location: "KLCC", token: "t1", enabled: true };
|
||||
const origin = () => `${window.location.origin}/r/t1`;
|
||||
const setNav = (props: object) => Object.defineProperty(navigator, "share", { value: undefined, configurable: true, ...props });
|
||||
const setClipboard = (writeText: unknown) => Object.defineProperty(navigator, "clipboard", { value: { writeText }, configurable: true });
|
||||
|
||||
it("opens the share sheet with the link when the device has one", async () => {
|
||||
mocks.getMyLinks.mockResolvedValue([LINK]);
|
||||
const share = vi.fn().mockResolvedValue(undefined);
|
||||
setNav({ value: share });
|
||||
render(<MyQrPage />);
|
||||
await userEvent.click(await screen.findByRole("button", { name: "Share" }));
|
||||
expect(share).toHaveBeenCalledWith(expect.objectContaining({ url: origin() }));
|
||||
});
|
||||
|
||||
it("does nothing more when the user dismisses the share sheet", async () => {
|
||||
mocks.getMyLinks.mockResolvedValue([LINK]);
|
||||
setNav({ value: vi.fn().mockRejectedValue(new DOMException("cancelled", "AbortError")) });
|
||||
const writeText = vi.fn().mockResolvedValue(undefined);
|
||||
setClipboard(writeText);
|
||||
render(<MyQrPage />);
|
||||
await userEvent.click(await screen.findByRole("button", { name: "Share" }));
|
||||
await waitFor(() => expect(navigator.share).toHaveBeenCalled());
|
||||
expect(writeText).not.toHaveBeenCalled();
|
||||
expect(screen.queryByText("Link copied")).toBeNull();
|
||||
});
|
||||
|
||||
it("copies the link when the share sheet fails for another reason", async () => {
|
||||
mocks.getMyLinks.mockResolvedValue([LINK]);
|
||||
setNav({ value: vi.fn().mockRejectedValue(new DOMException("blocked", "NotAllowedError")) });
|
||||
const writeText = vi.fn().mockResolvedValue(undefined);
|
||||
setClipboard(writeText);
|
||||
render(<MyQrPage />);
|
||||
await userEvent.click(await screen.findByRole("button", { name: "Share" }));
|
||||
expect(writeText).toHaveBeenCalledWith(origin());
|
||||
await screen.findByText("Link copied");
|
||||
});
|
||||
|
||||
it("copies the link when there is no share sheet, and says so", async () => {
|
||||
mocks.getMyLinks.mockResolvedValue([LINK]);
|
||||
setNav({ value: undefined });
|
||||
const writeText = vi.fn().mockResolvedValue(undefined);
|
||||
setClipboard(writeText);
|
||||
render(<MyQrPage />);
|
||||
await userEvent.click(await screen.findByRole("button", { name: "Share" }));
|
||||
expect(writeText).toHaveBeenCalledWith(origin());
|
||||
await screen.findByText("Link copied");
|
||||
});
|
||||
|
||||
it("says when the link could not be copied", async () => {
|
||||
mocks.getMyLinks.mockResolvedValue([LINK]);
|
||||
setNav({ value: undefined });
|
||||
setClipboard(vi.fn().mockRejectedValue(new Error("denied")));
|
||||
render(<MyQrPage />);
|
||||
await userEvent.click(await screen.findByRole("button", { name: "Share" }));
|
||||
await screen.findByText("Could not copy.");
|
||||
});
|
||||
|
||||
it("shows only the QR full screen, and Escape returns", async () => {
|
||||
mocks.getMyLinks.mockResolvedValue([LINK]);
|
||||
render(<MyQrPage />);
|
||||
await userEvent.click(await screen.findByRole("button", { name: "Show full screen" }));
|
||||
const dialog = await screen.findByRole("dialog");
|
||||
expect(dialog.querySelector("[data-testid=qr-svg]")?.getAttribute("data-value")).toBe(origin());
|
||||
expect(dialog.textContent).toBe("Close"); // the sr-only close label; no link, buttons or event text
|
||||
expect(dialog.querySelectorAll("button")).toHaveLength(1);
|
||||
await userEvent.keyboard("{Escape}");
|
||||
await waitFor(() => expect(screen.queryByRole("dialog")).toBeNull());
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -30,7 +30,7 @@ export default function MyQrPage() {
|
||||
{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} />
|
||||
<QrCodeItem label={l.eventName} eventName={l.eventName} token={l.token} enabled={l.enabled} personal />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user