@@ -22,6 +22,8 @@ import Radio from '@material-ui/core/Radio';
22
22
import RadioGroup from '@material-ui/core/RadioGroup' ;
23
23
import Avatar from "@material-ui/core/Avatar" ;
24
24
import { UserData , SaveUserBody } from '../API' ;
25
+ import DialogActions from '@material-ui/core/DialogActions' ;
26
+ import DialogTitle from '@material-ui/core/DialogTitle' ;
25
27
import {
26
28
SERVER_URL ,
27
29
getData ,
@@ -80,6 +82,7 @@ const AllUsers: FunctionComponent<any> = () => {
80
82
const classes = useStyles ( ) ;
81
83
const [ users , setUsers ] = useState ( [ ] ) ;
82
84
const [ dialogOpen , setDialogOpen ] = useState < boolean > ( false ) ;
85
+ const [ alertDialogOpen , setAlertDialogOpen ] = useState < boolean > ( false ) ;
83
86
const [ getRowData , setRowData ] = useState < UserData > ( ) ;
84
87
85
88
// user information states
@@ -129,6 +132,9 @@ const AllUsers: FunctionComponent<any> = () => {
129
132
setDialogOpen ( false ) ;
130
133
setSaveProfileBtn ( false ) ;
131
134
}
135
+ const handleAlertDialog = ( ) => {
136
+ setAlertDialogOpen ( false ) ;
137
+ }
132
138
133
139
// handler function to delete user
134
140
const handleDeleteUser = async ( ) => {
@@ -146,6 +152,12 @@ const AllUsers: FunctionComponent<any> = () => {
146
152
dangerMode : true ,
147
153
} ) ;
148
154
}
155
+ setAlertDialogOpen ( false ) ;
156
+ }
157
+
158
+ // handler for opening alert dialog for deletion
159
+ const handleDeleteConfirm = ( ) => {
160
+ setAlertDialogOpen ( true ) ;
149
161
}
150
162
151
163
// data for edit User
@@ -212,6 +224,30 @@ const AllUsers: FunctionComponent<any> = () => {
212
224
} ) ;
213
225
}
214
226
}
227
+
228
+ const alertDialog = ( ) => {
229
+ return (
230
+ < div >
231
+ < Dialog
232
+ open = { alertDialogOpen }
233
+ onClose = { handleAlertDialog }
234
+ aria-labelledby = "alert-dialog-title"
235
+ aria-describedby = "alert-dialog-description"
236
+ >
237
+ < DialogTitle id = "alert-dialog-title" > { "Are you sure want to delete user?" } </ DialogTitle >
238
+ < DialogActions >
239
+ < Button onClick = { handleAlertDialog } color = "primary" >
240
+ No
241
+ </ Button >
242
+ < Button onClick = { handleDeleteUser } color = "primary" autoFocus >
243
+ Yes
244
+ </ Button >
245
+ </ DialogActions >
246
+ </ Dialog >
247
+ </ div >
248
+ ) ;
249
+
250
+ }
215
251
const showDialog = ( ) => {
216
252
return (
217
253
< div >
@@ -237,6 +273,7 @@ const AllUsers: FunctionComponent<any> = () => {
237
273
</ Toolbar >
238
274
239
275
</ AppBar >
276
+ { alertDialog ( ) }
240
277
241
278
< div className = { classes . root } >
242
279
< div className = { classes . formSubdiv } >
@@ -401,7 +438,7 @@ const AllUsers: FunctionComponent<any> = () => {
401
438
</ Grid >
402
439
403
440
< Grid item xs = { 12 } sm = { 6 } >
404
- < Button variant = "contained" fullWidth color = "primary" onClick = { handleDeleteUser } > Delete</ Button >
441
+ < Button variant = "contained" fullWidth color = "primary" onClick = { handleDeleteConfirm } > Delete</ Button >
405
442
</ Grid >
406
443
407
444
</ Grid >
0 commit comments