feat: My QR codes as cards
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
4a20e75f82
commit
ac69c34cf2
3 files changed
+70
-11
No files matched your search
@@ -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,37 @@
|
||||
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);
|
||||
});
|
||||
});
|
||||
@@ -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" />
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
|
||||
Reference in new issue
Block a user