@@ -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' ;
1020import { Button } from '@/components/ui/button' ;
1121import { MoreHorizontalIcon } from 'lucide-react' ;
1222import { ButtonGroup } from '@/components/ui/button-group' ;
@@ -15,10 +25,12 @@ import { useTRPC } from '@/lib/trpc';
1525import { useMutation , useQueryClient } from '@tanstack/react-query' ;
1626import { toast } from 'sonner' ;
1727import { Spinner } from '@/components/ui/spinner' ;
28+ import { useState } from 'react' ;
1829
1930export 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}
0 commit comments