The public /r/<code> page (no admin shell, never redirects a visitor to the staff login), its proxy sending only the last X-Forwarded-For hop, the event page's Registration QR card, a My QR codes page in the user menu, and the super-admin privacy notice editor on Companies. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
70 lines
2.4 KiB
TypeScript
70 lines
2.4 KiB
TypeScript
"use client";
|
|
|
|
import { useRef, useState } from "react";
|
|
import { QRCodeCanvas, QRCodeSVG } from "qrcode.react";
|
|
import { Copy, Download } from "lucide-react";
|
|
import { Button } from "@/app/components/ui/button";
|
|
import { Switch } from "@/app/components/ui/switch";
|
|
import { useT } from "@/app/lib/i18n/MessagesProvider";
|
|
|
|
const slug = (s: string) => s.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
|
|
|
|
/** One registration code: QR, link, copy, PNG download and (when onToggle is given) an on/off switch. */
|
|
export function QrCodeItem({
|
|
label,
|
|
eventName,
|
|
fileLabel,
|
|
token,
|
|
enabled,
|
|
onToggle,
|
|
}: {
|
|
label: string;
|
|
eventName: string;
|
|
/** Member name for the download file name; omit for the event code. */
|
|
fileLabel?: string;
|
|
token: string;
|
|
enabled: boolean;
|
|
onToggle?: (enabled: boolean) => void;
|
|
}) {
|
|
const t = useT();
|
|
const canvas = useRef<HTMLCanvasElement>(null);
|
|
const [copied, setCopied] = useState(false);
|
|
const link = `${window.location.origin}/r/${token}`;
|
|
|
|
async function copy() {
|
|
await navigator.clipboard.writeText(link);
|
|
setCopied(true);
|
|
setTimeout(() => setCopied(false), 2000);
|
|
}
|
|
|
|
function download() {
|
|
if (!canvas.current) return;
|
|
const a = document.createElement("a");
|
|
a.href = canvas.current.toDataURL("image/png");
|
|
a.download = `${slug(eventName)}-${slug(fileLabel || "event")}-qr.png`;
|
|
a.click();
|
|
}
|
|
|
|
return (
|
|
<div className="flex flex-col gap-3 rounded-lg border p-4 sm:flex-row sm:items-center">
|
|
<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>
|
|
<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}>
|
|
<Copy aria-hidden="true" className="size-4" />
|
|
{copied ? t("QrCopied") : t("QrCopy")}
|
|
</Button>
|
|
<Button variant="outline" size="sm" onClick={download}>
|
|
<Download aria-hidden="true" className="size-4" />
|
|
{t("QrDownload")}
|
|
</Button>
|
|
{onToggle && <Switch checked={enabled} onCheckedChange={onToggle} aria-label={t("QrEnabled")} />}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|