/** * File : frontend/src/components/ExportBackupButton.tsx (new) * Purpose : one button that saves a project's backup file. * Consumers: App.tsx (project detail view). * Read-only: it never changes any project data. * Styles : existing classes from index.css only (secondary-btn, locked-note, form-error). */ import { useState } from "react"; import { BackupApiError, downloadBackup } from "../api/backup"; interface Props { protocolId: string; } export function ExportBackupButton({ protocolId }: Props) { const [busy, setBusy] = useState(false); const [error, setError] = useState(null); const [done, setDone] = useState(false); async function handleClick() { setBusy(true); setError(null); setDone(false); try { await downloadBackup(protocolId); setDone(true); } catch (err) { setError(err instanceof BackupApiError ? err.message : "Backup failed. Please try again."); } finally { setBusy(false); } } return (
{done &&
Backup saved to your downloads.
} {error &&
{error}
}
); }