Skip to content

Commit bb86fc1

Browse files
author
Nitish Agrahari
committed
feat: Alert Dialog added
Alert Dialog added for the user to confirm delete operation.
1 parent 684c412 commit bb86fc1

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

src/components/AllUsers.tsx

+38-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import Radio from '@material-ui/core/Radio';
2222
import RadioGroup from '@material-ui/core/RadioGroup';
2323
import Avatar from "@material-ui/core/Avatar";
2424
import { UserData, SaveUserBody } from '../API';
25+
import DialogActions from '@material-ui/core/DialogActions';
26+
import DialogTitle from '@material-ui/core/DialogTitle';
2527
import {
2628
SERVER_URL,
2729
getData,
@@ -80,6 +82,7 @@ const AllUsers: FunctionComponent<any> = () => {
8082
const classes = useStyles();
8183
const [users, setUsers] = useState([]);
8284
const [dialogOpen, setDialogOpen] = useState<boolean>(false);
85+
const [alertDialogOpen, setAlertDialogOpen] = useState<boolean>(false);
8386
const [getRowData, setRowData] = useState<UserData>();
8487

8588
// user information states
@@ -129,6 +132,9 @@ const AllUsers: FunctionComponent<any> = () => {
129132
setDialogOpen(false);
130133
setSaveProfileBtn(false);
131134
}
135+
const handleAlertDialog= () => {
136+
setAlertDialogOpen(false);
137+
}
132138

133139
// handler function to delete user
134140
const handleDeleteUser = async () => {
@@ -146,6 +152,12 @@ const AllUsers: FunctionComponent<any> = () => {
146152
dangerMode: true,
147153
});
148154
}
155+
setAlertDialogOpen(false);
156+
}
157+
158+
// handler for opening alert dialog for deletion
159+
const handleDeleteConfirm = () => {
160+
setAlertDialogOpen(true);
149161
}
150162

151163
// data for edit User
@@ -212,6 +224,30 @@ const AllUsers: FunctionComponent<any> = () => {
212224
});
213225
}
214226
}
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+
}
215251
const showDialog = () => {
216252
return (
217253
<div>
@@ -237,6 +273,7 @@ const AllUsers: FunctionComponent<any> = () => {
237273
</Toolbar>
238274

239275
</AppBar>
276+
{alertDialog()}
240277

241278
<div className={classes.root}>
242279
<div className={classes.formSubdiv}>
@@ -401,7 +438,7 @@ const AllUsers: FunctionComponent<any> = () => {
401438
</Grid>
402439

403440
<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>
405442
</Grid>
406443

407444
</Grid>

0 commit comments

Comments
 (0)