Archived
Add multi-day events (frontend), attendance register and certificates
Event wizard: one date or multiple sessions with a repeat-pattern builder, and a new Attendance step (late joining and pricing, check-in window, session reminders, certificates with preview). Public pages show the schedule and late prices; the scanner picks today's session; new attendance register page, My Certificates, and a public verify page. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
"use client";
|
||||
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { Award, Download } from "lucide-react";
|
||||
import { apiFetch, API_BASE } from "@/lib/api";
|
||||
import { fetchApiFile, saveBlob } from "@/lib/export";
|
||||
import { formatDate } from "@/lib/date";
|
||||
import { errorMessage } from "@/lib/utils";
|
||||
import type { MyCertificate } from "@/types";
|
||||
|
||||
// Completion certificates on My Events. Hidden until the person has one.
|
||||
export function MyCertificates({ token }: { token: string | null }) {
|
||||
const [certs, setCerts] = useState<MyCertificate[]>([]);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!token) return;
|
||||
apiFetch<MyCertificate[]>("/api/attendance/certificates/mine", { authToken: token })
|
||||
.then(list => setCerts(Array.isArray(list) ? list : []))
|
||||
.catch(() => setCerts([]));
|
||||
}, [token]);
|
||||
|
||||
if (certs.length === 0) return null;
|
||||
|
||||
const download = async (c: MyCertificate) => {
|
||||
if (!token) return;
|
||||
setError(null);
|
||||
try {
|
||||
saveBlob(await fetchApiFile(API_BASE, token, `/api/attendance/certificates/${c.id}/pdf`), `Certificate - ${c.event.title.replace(/[^a-z0-9 -]/gi, "")}.pdf`);
|
||||
} catch (e) {
|
||||
setError(errorMessage(e) || "Download failed");
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<section className="mb-6 border rounded-xl p-5 bg-white shadow-sm">
|
||||
<div className="flex items-center gap-2 mb-3">
|
||||
<Award className="w-5 h-5 text-brand-600" />
|
||||
<h2 className="text-lg font-semibold text-gray-900">My Certificates</h2>
|
||||
</div>
|
||||
{error && <div className="mb-3 p-2 border rounded bg-red-50 text-red-700 text-sm">{error}</div>}
|
||||
<ul className="divide-y">
|
||||
{certs.map(c => (
|
||||
<li key={c.id} className="flex flex-wrap items-center justify-between gap-2 py-2.5">
|
||||
<div className="min-w-0">
|
||||
<div className="font-medium text-gray-900">{c.event.title}</div>
|
||||
<div className="text-xs text-gray-500">
|
||||
{c.name} · {c.totalSessions > 1 ? `${c.sessionsAttended} of ${c.totalSessions} sessions · ` : ""}issued {formatDate(new Date(c.issuedAt))}
|
||||
</div>
|
||||
</div>
|
||||
<button type="button" onClick={() => download(c)} className="inline-flex items-center gap-1.5 px-3 py-1.5 text-sm rounded-lg border border-brand-200 bg-brand-50 text-brand-700 hover:bg-brand-100">
|
||||
<Download className="w-4 h-4" /> Download
|
||||
</button>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user