-
Notifications
You must be signed in to change notification settings - Fork 212
Expand file tree
/
Copy pathindex.jsx
More file actions
139 lines (132 loc) · 4.22 KB
/
index.jsx
File metadata and controls
139 lines (132 loc) · 4.22 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
* Copyright (c) 2021, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import React from 'react'
import {noop} from '../../utils/utils'
import {
Button,
DialogBody,
DialogCloseTrigger,
DialogContent,
DialogFooter,
DialogHeader,
DialogRoot,
DialogTitle,
DialogTrigger,
Text
} from '@chakra-ui/react'
import PropTypes from 'prop-types'
import {CONFIRMATION_DIALOG_DEFAULT_CONFIG} from '../../pages/account/constant'
import {useIntl} from 'react-intl'
const ConfirmationModal = ({
dialogTitle = CONFIRMATION_DIALOG_DEFAULT_CONFIG.dialogTitle,
confirmationMessage = CONFIRMATION_DIALOG_DEFAULT_CONFIG.confirmationMessage,
primaryActionLabel = CONFIRMATION_DIALOG_DEFAULT_CONFIG.primaryActionLabel,
primaryActionAriaLabel = CONFIRMATION_DIALOG_DEFAULT_CONFIG.primaryActionAriaLabel,
alternateActionLabel = CONFIRMATION_DIALOG_DEFAULT_CONFIG.alternateActionLabel,
alternateActionAriaLabel = CONFIRMATION_DIALOG_DEFAULT_CONFIG.alternateActionAriaLabel,
hideAlternateAction = false,
onPrimaryAction = noop,
onAlternateAction = noop,
...props
}) => {
const {formatMessage} = useIntl()
const handleConfirmClick = () => {
onPrimaryAction()
props.onClose()
}
const handleAlternateActionClick = () => {
onAlternateAction()
props.onClose()
}
return (
<DialogRoot
role="alertdialog"
isOpen={props.isOpen}
isCentered
onClose={handleAlternateActionClick}
{...props}
>
{/*<AlertDialogOverlay />*/}
<DialogContent>
<DialogHeader>{formatMessage(dialogTitle)}</DialogHeader>
<DialogBody>
<Text>{formatMessage(confirmationMessage)}</Text>
</DialogBody>
<DialogFooter>
{!hideAlternateAction ? (
<Button
variant="ghost"
mr={3}
aria-label={formatMessage(alternateActionAriaLabel)}
onClick={handleAlternateActionClick}
>
{formatMessage(alternateActionLabel)}
</Button>
) : null}
<Button
variant="solid"
onClick={handleConfirmClick}
aria-label={formatMessage(primaryActionAriaLabel)}
>
{formatMessage(primaryActionLabel)}
</Button>
</DialogFooter>
</DialogContent>
</DialogRoot>
)
}
ConfirmationModal.propTypes = {
/**
* Prop to check if modal is open
*/
isOpen: PropTypes.bool.isRequired,
/**
* Callback invoked to open the modal
*/
onOpen: PropTypes.func.isRequired,
/**
* Callback invoked to close the modal
*/
onClose: PropTypes.func.isRequired,
/**
* Text to be displayed as modal header
*/
dialogTitle: PropTypes.object,
/**
* Text to display in confirmation modal prompting user to pick an action
*/
confirmationMessage: PropTypes.object,
/**
* Button Label for primary action in confirmation modal
*/
primaryActionLabel: PropTypes.object,
/**
* Button aria Label for primary action
*/
primaryActionAriaLabel: PropTypes.object,
/**
* Button Label for alternate or secondary action in confirmation modal
*/
alternateActionLabel: PropTypes.object,
/**
* Button aria Label for alternate or secondary action in confirmation modal
*/
alternateActionAriaLabel: PropTypes.object,
/**
* Action to execute if user selects primary action
*/
onPrimaryAction: PropTypes.func,
/**
* Action to execute if user selects alternate or secondary action
*/
onAlternateAction: PropTypes.func,
/**
* Flag to hide of show alternative button
*/
hideAlternateAction: PropTypes.bool
}
export default ConfirmationModal