Skip to content

Commit 47a3add

Browse files
committed
feat: add delete confirmation modal to backup schedule dropdown
- Introduced a confirmation modal to `BackupSettingsDropDown` for deleting backup schedules to prevent accidental deletions. - Updated `ServiceBackupsList` to pass `serviceId` prop to `BackupSettingsDropDown`. - Enhanced error handling and notifications for delete actions.
1 parent 669b176 commit 47a3add

2 files changed

Lines changed: 60 additions & 21 deletions

File tree

apps/web/app/dashboard/services/[serviceId]/components/tabs/backups/backup-settings-drop-down.tsx

Lines changed: 56 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ import {
77
DropdownMenuSeparator,
88
DropdownMenuTrigger,
99
} from '@/components/ui/dropdown-menu';
10+
import {
11+
AlertDialog,
12+
AlertDialogAction,
13+
AlertDialogCancel,
14+
AlertDialogContent,
15+
AlertDialogDescription,
16+
AlertDialogFooter,
17+
AlertDialogHeader,
18+
AlertDialogTitle,
19+
} from '@/components/ui/alert-dialog';
1020
import { Button } from '@/components/ui/button';
1121
import { MoreHorizontalIcon } from 'lucide-react';
1222
import { ButtonGroup } from '@/components/ui/button-group';
@@ -15,10 +25,12 @@ import { useTRPC } from '@/lib/trpc';
1525
import { useMutation, useQueryClient } from '@tanstack/react-query';
1626
import { toast } from 'sonner';
1727
import { Spinner } from '@/components/ui/spinner';
28+
import { useState } from 'react';
1829

1930
export default function BackupSettingsDropDown({
2031
backup,
21-
}: Readonly<{ backup: Backup }>) {
32+
serviceId,
33+
}: Readonly<{ backup: Backup; serviceId: string }>) {
2234
const trpc = useTRPC();
2335
const queryClient = useQueryClient();
2436
const startBackupMutation = useMutation(
@@ -29,12 +41,13 @@ export default function BackupSettingsDropDown({
2941
onSuccess: async () => {
3042
await queryClient.invalidateQueries({
3143
queryKey: trpc.services.backups.listBackups.queryKey({
32-
serviceId: backup.volume.serviceId,
44+
serviceId,
3345
}),
3446
});
3547
},
3648
})
3749
);
50+
const [showDeleteModal, setShowDeleteModal] = useState(false);
3851
return (
3952
<ButtonGroup>
4053
<Button
@@ -71,28 +84,51 @@ export default function BackupSettingsDropDown({
7184
<DropdownMenuSeparator />
7285
<DropdownMenuItem
7386
variant='destructive'
74-
onClick={async () => {
75-
try {
76-
await deleteMutation.mutateAsync({
77-
volumeBackupScheduleId: backup.id,
78-
});
79-
toast.success('Backup schedule deleted');
80-
} catch (e) {
81-
console.error(e);
82-
toast.error('Unable to delete backup schedule');
83-
}
84-
}}
87+
onClick={() => setShowDeleteModal(true)}
8588
>
86-
{deleteMutation.isPending ? (
87-
<span className='flex items-center gap-2'>
88-
<Spinner /> Deleting...
89-
</span>
90-
) : (
91-
'Delete backup schedule'
92-
)}
89+
Delete backup schedule
9390
</DropdownMenuItem>
9491
</DropdownMenuContent>
9592
</DropdownMenu>
93+
<AlertDialog
94+
open={showDeleteModal}
95+
onOpenChange={setShowDeleteModal}
96+
>
97+
<AlertDialogContent>
98+
<AlertDialogHeader>
99+
<AlertDialogTitle>
100+
Are you absolutely sure?
101+
</AlertDialogTitle>
102+
<AlertDialogDescription>
103+
This action cannot be undone. This will permanently
104+
delete this backup schedule. Existing backup
105+
archives in your storage destination will not be
106+
removed.
107+
</AlertDialogDescription>
108+
</AlertDialogHeader>
109+
<AlertDialogFooter>
110+
<AlertDialogCancel>Cancel</AlertDialogCancel>
111+
<AlertDialogAction
112+
onClick={async () => {
113+
try {
114+
await deleteMutation.mutateAsync({
115+
volumeBackupScheduleId: backup.id,
116+
});
117+
setShowDeleteModal(false);
118+
toast.success('Backup schedule deleted');
119+
} catch (e) {
120+
console.error(e);
121+
toast.error(
122+
'Unable to delete backup schedule'
123+
);
124+
}
125+
}}
126+
>
127+
Continue
128+
</AlertDialogAction>
129+
</AlertDialogFooter>
130+
</AlertDialogContent>
131+
</AlertDialog>
96132
</ButtonGroup>
97133
);
98134
}

apps/web/app/dashboard/services/[serviceId]/components/tabs/backups/service-backups-list.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ export default function ServiceBackupsList({
3838
Location : {backup.destination.name}
3939
</CardDescription>
4040
<CardAction>
41-
<BackupSettingsDropDown backup={backup} />
41+
<BackupSettingsDropDown
42+
backup={backup}
43+
serviceId={serviceId}
44+
/>
4245
</CardAction>
4346
</CardHeader>
4447
</Card>

0 commit comments

Comments
 (0)