-
Notifications
You must be signed in to change notification settings - Fork 4
/
ConfirmationModalWithOutcome.tsx
118 lines (113 loc) · 3.26 KB
/
ConfirmationModalWithOutcome.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
115
116
117
118
import * as React from "react";
import { Modal } from "react-bootstrap";
import { Button } from "library-simplified-reusable-components";
export const SHOW_CONFIRMATION = "SHOW_CONFIRMATION";
export const SHOW_OUTCOME = "SHOW_OUTCOME";
export type ModalState =
| typeof SHOW_CONFIRMATION
| typeof SHOW_OUTCOME
| undefined;
export type ConfirmationModalWithOutcomeProps = {
modalState: ModalState;
onClose: () => void;
onConfirm: () => void;
onDismissOutcome?: () => void;
confirmationTitle?: string;
confirmationBody?: React.ReactElement;
confirmationButtonContent?: string;
confirmationButtonTitle?: string;
confirmationButtonDisabled?: boolean;
cancelButtonContent?: string;
cancelButtonTitle?: string;
outcomeTitle?: string;
outcomeBody?: React.ReactElement;
dismissOutcomeButtonContent?: string;
dismissOutcomeButtonTitle?: string;
};
export const ConfirmationModalWithOutcome = ({
modalState,
onClose,
onConfirm,
onDismissOutcome = onClose,
confirmationTitle = "Confirm",
confirmationBody = <p>Are you sure?</p>,
confirmationButtonContent = "Confirm",
confirmationButtonTitle = "Confirm action.",
confirmationButtonDisabled = false,
cancelButtonContent = "Cancel",
cancelButtonTitle = "Cancel action.",
outcomeTitle = "Result",
outcomeBody = <p>Action performed.</p>,
dismissOutcomeButtonContent = "Dismiss",
dismissOutcomeButtonTitle = "Dismiss outcome.",
}: ConfirmationModalWithOutcomeProps) => {
switch (modalState) {
case SHOW_CONFIRMATION:
return renderModal({
show: true,
onHide: onClose,
title: confirmationTitle,
content: (
<>
<div>{confirmationBody}</div>
<Button
className="left-align small inline"
onClick={onConfirm}
title={confirmationButtonTitle}
content={confirmationButtonContent}
disabled={confirmationButtonDisabled}
/>
<Button
className="inverted left-align small inline"
callback={onClose}
title={cancelButtonTitle}
content={cancelButtonContent}
/>
</>
),
});
case SHOW_OUTCOME:
return renderModal({
show: true,
onHide: onDismissOutcome,
title: outcomeTitle,
className: "confirmation-modal",
content: (
<>
<div>{outcomeBody}</div>
<Button
className="inverted left-align small inline"
callback={onDismissOutcome}
title={dismissOutcomeButtonTitle}
content={dismissOutcomeButtonContent}
/>
</>
),
});
default:
return null;
}
};
const renderModal = ({
show = true,
onHide,
title = undefined,
content = undefined,
footer = undefined,
className = "",
}) => {
return (
<Modal className={className} show={show} onHide={onHide}>
{!!title && (
<Modal.Header>
<Modal.Title>{title}</Modal.Title>
</Modal.Header>
)}
{!!content && (
<Modal.Body style={{ overflow: "wrap" }}>{content}</Modal.Body>
)}
{!!footer && <Modal.Footer>{footer}</Modal.Footer>}
</Modal>
);
};
export default ConfirmationModalWithOutcome;