fix(backup): prevent immediate deletion before confirmation dialog

This commit is contained in:
Slinetrac
2025-10-16 16:54:25 +08:00
parent 4835d68222
commit fd5bddeb80

View File

@@ -33,6 +33,14 @@ export type BackupFile = {
export const DEFAULT_ROWS_PER_PAGE = 5; export const DEFAULT_ROWS_PER_PAGE = 5;
type ConfirmFn = (message?: string) => boolean | Promise<boolean>;
// Normalizes synchronous and async confirm implementations.
const confirmAsync = async (message: string): Promise<boolean> => {
const confirmFn = window.confirm as unknown as ConfirmFn;
return await confirmFn.call(window, message);
};
interface BackupTableViewerProps { interface BackupTableViewerProps {
datasource: BackupFile[]; datasource: BackupFile[];
page: number; page: number;
@@ -154,13 +162,13 @@ export const BackupTableViewer = memo(
aria-label={t("Delete")} aria-label={t("Delete")}
size="small" size="small"
title={t("Delete Backup")} title={t("Delete Backup")}
onClick={(e: React.MouseEvent) => { onClick={async (e: React.MouseEvent) => {
e.preventDefault(); e.preventDefault();
const confirmed = window.confirm( const confirmed = await confirmAsync(
t("Confirm to delete this backup file?"), t("Confirm to delete this backup file?"),
); );
if (confirmed) { if (confirmed) {
void handleDelete(file.filename); await handleDelete(file.filename);
} }
}} }}
> >
@@ -177,13 +185,13 @@ export const BackupTableViewer = memo(
size="small" size="small"
title={t("Restore Backup")} title={t("Restore Backup")}
disabled={!file.allow_apply} disabled={!file.allow_apply}
onClick={(e: React.MouseEvent) => { onClick={async (e: React.MouseEvent) => {
e.preventDefault(); e.preventDefault();
const confirmed = window.confirm( const confirmed = await confirmAsync(
t("Confirm to restore this backup file?"), t("Confirm to restore this backup file?"),
); );
if (confirmed) { if (confirmed) {
void handleRestore(file.filename); await handleRestore(file.filename);
} }
}} }}
> >