This repository has been archived on 2026-11-23. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
hope-events/frontend/src/app/events/[id]/ClientActions.tsx
T

66 lines
2.7 KiB
TypeScript

"use client";
import { Share2, QrCode, CalendarPlus } from "lucide-react";
import QRCode from "qrcode";
import { API_BASE } from "@/lib/api";
type Props = { event: { id: string; title: string; description?: string | null } };
// The event's own address tagged with where the link was handed out, so visits from it
// show under that source in the funnel report (the page's canonical drops the tag for SEO).
function taggedEventUrl(source: string): string {
return `${window.location.origin}${window.location.pathname}?utm_source=${source}`;
}
export default function ClientActions({ event }: Props) {
return (
<div className="flex gap-2">
<button
onClick={async () => {
try {
await navigator.share({
title: event.title,
text: event.description ?? undefined,
url: taggedEventUrl("share"),
});
} catch (err) {
console.error("Error sharing:", err);
}
}}
className="flex items-center gap-2 px-4 py-2 bg-gray-100 rounded-lg hover:bg-gray-200 transition-colors text-sm font-medium"
>
<Share2 className="w-4 h-4" />
Share
</button>
<button
onClick={async () => {
try {
const url = taggedEventUrl("qr");
const qrDataUrl = await QRCode.toDataURL(url);
const link = document.createElement("a");
link.href = qrDataUrl;
link.download = `${event.title}-qr.png`;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
} catch (err) {
console.error("Error generating QR code:", err);
}
}}
className="flex items-center gap-2 px-4 py-2 bg-gray-100 rounded-lg hover:bg-gray-200 transition-colors text-sm font-medium"
>
<QrCode className="w-4 h-4" />
Save QR
</button>
<a
href={`${API_BASE}/api/v2/events/${event.id}/calendar.ics`}
download
className="flex items-center gap-2 px-4 py-2 bg-gray-100 rounded-lg hover:bg-gray-200 transition-colors text-sm font-medium"
>
<CalendarPlus className="w-4 h-4" />
Add to calendar
</a>
</div>
);
}