Systematic-tool-review / frontend /src /components /ExportBackupButton.tsx
Sadum1's picture
Upload 2 files
834b620 verified
Raw History Blame Contribute Delete
1.45 kB
/**
* 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<string | null>(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 (
<div style={{ marginBottom: 14 }}>
<button type="button" className="secondary-btn" onClick={handleClick} disabled={busy}>
{busy ? "Preparing backup…" : "Export project backup"}
</button>
{done && <div className="locked-note" role="status">Backup saved to your downloads.</div>}
{error && <div className="form-error" role="alert" style={{ whiteSpace: "pre-line" }}>{error}</div>}
</div>
);
}