import { useState } from 'react'; /** * @param {{ * id: string, * title: string, * description: string, * endpoint: string, * filename: string, * baseParams?: Record, * fullReport?: { description: string, filename: string, help: string }, * }} props */ function ExportCard({ id, title, description, endpoint, filename, baseParams = {}, fullReport }) { const [from, setFrom] = useState(''); const [to, setTo] = useState(''); const [full, setFull] = useState(false); const [error, setError] = useState(''); const [busy, setBusy] = useState(false); const useFull = Boolean(fullReport && full); async function download(event) { event.preventDefault(); setError(''); setBusy(true); const params = new URLSearchParams(baseParams); if (useFull) { params.set('full', 'true'); } if (from) { params.set('from', from); } if (to) { params.set('to', to); } try { const response = await fetch(`${endpoint}?${params}`, { credentials: 'include', }); if (response.status === 401) { window.location.assign('/admin/login'); return; } if (!response.ok) { const data = await response.json().catch(() => ({})); throw new Error(data?.error?.message || 'Export failed'); } const blob = await response.blob(); const url = URL.createObjectURL(blob); const link = document.createElement('a'); link.href = url; link.download = useFull && fullReport ? fullReport.filename : filename; link.click(); URL.revokeObjectURL(url); } catch (downloadError) { setError(downloadError.message); } finally { setBusy(false); } } return (

{title}

{useFull && fullReport ? fullReport.description : description}

{fullReport ? (
setFull(event.target.checked)} />

{fullReport.help}

) : null} {error ? (

{error}

) : null}
); } export default function ReportsPage() { return (

Reports

These files contain personal data.

); }