-
Notifications
You must be signed in to change notification settings - Fork 3
/
ConfirmationDialog.tsx
114 lines (109 loc) · 2.81 KB
/
ConfirmationDialog.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import {
Button,
Dialog,
DialogActions,
DialogContent,
Divider
} from "@mui/material";
import { ConfirmationDialogProps } from "./ConfirmProvider.types";
import DialogContentText from "@mui/material/DialogContentText";
import DialogTitle from "../DialogTitle";
import React from "react";
const ConfirmationDialog: React.FC<ConfirmationDialogProps> = ({
open,
options,
onCancel,
onConfirm,
onClose
}) => {
const {
title,
description,
content,
confirmationText,
cancellationText,
dialogProps,
dialogActionsProps,
titleProps
} = options;
// dialog actions for the confirmation dialog component (confirm and cancel buttons)
const dialogActions = (
<>
<Button
onClick={onCancel}
{...options.cancellationButtonProps}
data-testid="confirm-dialog-cancel-button"
>
{cancellationText || "Cancel"}
</Button>
<Button
onClick={onConfirm}
color="primary"
variant="contained"
{...options.confirmationButtonProps}
data-testid="confirm-dialog-confirm-button"
>
{confirmationText || "Confirm"}
</Button>
</>
);
return (
<>
{open ? (
<Dialog
fullWidth
{...dialogProps}
open={true}
onClose={onClose}
data-testid="confirm-dialog"
>
{title && (
// use the dialog title from the dialog title component
<DialogTitle onClose={onCancel} {...titleProps}>
{title}
</DialogTitle>
)}
<Divider />
{content ? (
<DialogContent sx={{ p: 2 }}>
<DialogContentText
sx={{
color: theme =>
theme.palette.mode === "light"
? "rgba(0, 0, 0, 0.8)"
: "rgba(255,255,255, 1)"
}}
>
{content}
<DialogContentText />
</DialogContentText>
</DialogContent>
) : (
description && (
<DialogContent sx={{ p: 2 }}>
<DialogContentText
sx={{
color: theme =>
theme.palette.mode === "light"
? "rgba(0, 0, 0, 0.8)"
: "rgba(255,255,255, 1)"
}}
>
{description}
</DialogContentText>
</DialogContent>
)
)}
<Divider />
<DialogActions
sx={{ justifyContent: "flex-end", padding: "16px" }}
{...dialogActionsProps}
>
{dialogActions}
</DialogActions>
</Dialog>
) : null}
</>
);
};
export default ConfirmationDialog;