feat: run backup now

This commit is contained in:
Nicolas Meienberger
2025-10-31 22:16:31 +01:00
parent c64e50bdec
commit d81f3653ec
4 changed files with 34 additions and 5 deletions

View File

@@ -10,6 +10,7 @@ import {
listRepositoriesOptions,
upsertBackupScheduleMutation,
getBackupScheduleForVolumeOptions,
runBackupNowMutation,
} from "~/api-client/@tanstack/react-query.gen";
import { parseError } from "~/lib/errors";
import { CreateScheduleForm, type BackupScheduleFormValues } from "../components/create-schedule-form";
@@ -65,6 +66,19 @@ export const VolumeBackupsTabContent = ({ volume }: Props) => {
},
});
const runBackupNow = useMutation({
...runBackupNowMutation(),
onSuccess: () => {
toast.success("Backup started successfully");
queryClient.invalidateQueries({ queryKey: ["getBackupScheduleForVolume", volume.id.toString()] });
},
onError: (error) => {
toast.error("Failed to start backup", {
description: parseError(error)?.message,
});
},
});
const handleSubmit = (formValues: BackupScheduleFormValues) => {
const cronExpression = getCronExpression(formValues.frequency, formValues.dailyTime, formValues.weeklyDay);
@@ -145,12 +159,23 @@ export const VolumeBackupsTabContent = ({ volume }: Props) => {
});
};
const handleRunBackupNow = () => {
if (!existingSchedule) return;
runBackupNow.mutate({
path: {
scheduleId: existingSchedule.id.toString(),
},
});
};
const repository = repositories.find((repo) => repo.id === existingSchedule?.repositoryId);
if (existingSchedule && repository && !isEditMode) {
return (
<ScheduleSummary
handleToggleEnabled={handleToggleEnabled}
handleRunBackupNow={handleRunBackupNow}
repository={repository}
setIsEditMode={setIsEditMode}
schedule={existingSchedule}