-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
CancelConfirmDialog.tsx
71 lines (66 loc) · 1.73 KB
/
CancelConfirmDialog.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import {
Button,
Dialog,
DialogActions,
DialogContent,
DialogContentText,
DialogTitle,
} from "@mui/material";
import { type ReactElement, useState } from "react";
import { useTranslation } from "react-i18next";
import LoadingButton from "components/Buttons/LoadingButton";
interface CancelConfirmDialogProps {
open: boolean;
textId: string;
handleCancel: () => void;
handleConfirm: () => Promise<void> | void;
buttonIdCancel?: string;
buttonIdConfirm?: string;
}
/**
* Dialog to cancel or confirm an action
*/
export default function CancelConfirmDialog(
props: CancelConfirmDialogProps
): ReactElement {
const [loading, setLoading] = useState(false);
const { t } = useTranslation();
const onConfirm = async (): Promise<void> => {
setLoading(true);
await props.handleConfirm();
};
return (
<Dialog
open={props.open}
onClose={props.handleCancel}
aria-labelledby="alert-dialog-title"
aria-describedby="alert-dialog-description"
>
<DialogTitle id="alert-dialog-title">
{t("buttons.proceedWithCaution")}
</DialogTitle>
<DialogContent>
<DialogContentText id="alert-dialog-description">
{t(props.textId)}
</DialogContentText>
</DialogContent>
<DialogActions>
<Button
color="primary"
disabled={loading}
id={props.buttonIdCancel}
onClick={props.handleCancel}
variant="outlined"
>
{t("buttons.cancel")}
</Button>
<LoadingButton
buttonProps={{ id: props.buttonIdConfirm, onClick: onConfirm }}
loading={loading}
>
{t("buttons.confirm")}
</LoadingButton>
</DialogActions>
</Dialog>
);
}