1- import  React  from  'react' ; 
1+ import  React ,   {   useState   }  from  'react' ; 
22import  { 
33 IconButton , 
44 ListItemSecondaryAction , 
55 Tooltip , 
6+  Dialog , 
7+  DialogTitle , 
8+  DialogContent , 
9+  DialogContentText , 
10+  DialogActions , 
11+  Button , 
612}  from  '@material-ui/core' ; 
713import  DeleteIcon  from  '@material-ui/icons/Delete' ; 
814import  FileCopyIcon  from  '@material-ui/icons/FileCopy' ; 
@@ -20,18 +26,22 @@ interface DbEntryProps {
2026 duplicate : ( )  =>  void ; 
2127 dbType : DBType ; 
2228} 
29+ 
2330const  DbEntry  =  ( { 
2431 db, 
2532 isSelected, 
2633 select, 
2734 duplicate, 
2835 dbType, 
2936} : DbEntryProps )  =>  { 
37+  const  [ isDeleteDialogOpen ,  setIsDeleteDialogOpen ]  =  useState ( false ) ; 
38+ 
3039 const  handleDelete  =  ( )  =>  { 
3140 ipcRenderer 
3241 . invoke ( 'drop-db' ,  db ,  isSelected ,  dbType ) 
3342 . then ( ( )  =>  { 
3443 if  ( isSelected )  select ( '' ,  dbType ) ; 
44+  setIsDeleteDialogOpen ( false ) ; 
3545 } ) 
3646 . catch ( ( )  => 
3747 sendFeedback ( {  type : 'error' ,  message : `Failed to delete ${ db }  `  } ) 
@@ -52,10 +62,36 @@ const DbEntry = ({
5262 </ IconButton > 
5363 </ Tooltip > 
5464 < Tooltip  title = "Drop Database" > 
55-  < IconButton  edge = "end"  onClick = { handleDelete } > 
65+  < IconButton  edge = "end"  onClick = { ( )   =>   setIsDeleteDialogOpen ( true ) } > 
5666 < DeleteIcon  /> 
5767 </ IconButton > 
5868 </ Tooltip > 
69+  < Dialog 
70+  open = { isDeleteDialogOpen } 
71+  onClose = { ( )  =>  setIsDeleteDialogOpen ( false ) } 
72+  aria-labelledby = "alert-dialog-title" 
73+  aria-describedby = "alert-dialog-description" 
74+  > 
75+  < DialogTitle  style = { {  color : 'black'  } }  id = "alert-dialog-title" > 
76+  Confirm deletion
77+  </ DialogTitle > 
78+  < DialogContent > 
79+  < DialogContentText  id = "alert-dialog-description" > 
80+  Are you sure you want to delete the database { db } ?
81+  </ DialogContentText > 
82+  </ DialogContent > 
83+  < DialogActions > 
84+  < Button 
85+  onClick = { ( )  =>  setIsDeleteDialogOpen ( false ) } 
86+  color = "primary" 
87+  > 
88+  Cancel
89+  </ Button > 
90+  < Button  onClick = { handleDelete }  color = "primary"  autoFocus > 
91+  Delete
92+  </ Button > 
93+  </ DialogActions > 
94+  </ Dialog > 
5995 </ ListItemSecondaryAction > 
6096 </ SidebarListItem > 
6197 ) ; 
0 commit comments