2020-05-22 22:35:24 +08:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import { defineMessages } from 'react-intl';
|
2022-03-02 21:42:17 +08:00
|
|
|
import PropTypes from 'prop-types';
|
2021-11-11 03:10:35 +08:00
|
|
|
import Styled from './styles';
|
2020-05-22 22:35:24 +08:00
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
yesLabel: {
|
2022-11-30 19:31:37 +08:00
|
|
|
id: 'app.confirmationModal.yesLabel',
|
2020-05-22 22:35:24 +08:00
|
|
|
description: 'confirm button label',
|
|
|
|
},
|
|
|
|
noLabel: {
|
|
|
|
id: 'app.endMeeting.noLabel',
|
|
|
|
description: 'cancel confirm button label',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const propTypes = {
|
2022-03-02 21:42:17 +08:00
|
|
|
confirmButtonColor: PropTypes.string,
|
2022-03-02 22:45:33 +08:00
|
|
|
disableConfirmButton: PropTypes.bool,
|
|
|
|
description: PropTypes.string,
|
2022-03-02 21:42:17 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const defaultProps = {
|
|
|
|
confirmButtonColor: 'primary',
|
2022-03-02 22:45:33 +08:00
|
|
|
disableConfirmButton: false,
|
|
|
|
description: '',
|
2020-05-22 22:35:24 +08:00
|
|
|
};
|
|
|
|
|
2022-03-02 21:42:17 +08:00
|
|
|
class ConfirmationModal extends Component {
|
2020-05-22 22:35:24 +08:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
checked: false,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {
|
2022-03-02 21:42:17 +08:00
|
|
|
intl,
|
2023-03-21 21:00:46 +08:00
|
|
|
setIsOpen,
|
2022-03-02 21:42:17 +08:00
|
|
|
onConfirm,
|
|
|
|
title,
|
|
|
|
titleMessageId,
|
|
|
|
titleMessageExtra,
|
|
|
|
checkboxMessageId,
|
|
|
|
confirmButtonColor,
|
2022-11-30 19:31:37 +08:00
|
|
|
confirmButtonLabel,
|
2022-03-03 01:11:05 +08:00
|
|
|
confirmButtonDataTest,
|
2022-03-02 21:42:17 +08:00
|
|
|
confirmParam,
|
2022-03-02 22:45:33 +08:00
|
|
|
disableConfirmButton,
|
|
|
|
description,
|
2020-05-22 22:35:24 +08:00
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
const {
|
|
|
|
checked,
|
|
|
|
} = this.state;
|
|
|
|
|
2022-03-02 21:42:17 +08:00
|
|
|
const hasCheckbox = !!checkboxMessageId;
|
|
|
|
|
2020-05-22 22:35:24 +08:00
|
|
|
return (
|
2022-03-02 21:42:17 +08:00
|
|
|
<Styled.ConfirmationModal
|
2023-03-21 21:00:46 +08:00
|
|
|
onRequestClose={() => setIsOpen(false)}
|
2020-05-22 22:35:24 +08:00
|
|
|
contentLabel={title}
|
2022-11-11 02:09:21 +08:00
|
|
|
title={title || intl.formatMessage({ id: titleMessageId }, { 0: titleMessageExtra })}
|
2023-03-21 21:00:46 +08:00
|
|
|
{...this.props}
|
2020-05-22 22:35:24 +08:00
|
|
|
>
|
2021-11-11 03:10:35 +08:00
|
|
|
<Styled.Container>
|
|
|
|
<Styled.Description>
|
2022-04-07 01:27:05 +08:00
|
|
|
<Styled.DescriptionText>
|
|
|
|
{description}
|
|
|
|
</Styled.DescriptionText>
|
2022-03-02 21:42:17 +08:00
|
|
|
{ hasCheckbox ? (
|
2022-04-12 01:09:13 +08:00
|
|
|
<Styled.Label htmlFor="confirmationCheckbox" key="confirmation-checkbox">
|
2022-03-02 21:42:17 +08:00
|
|
|
<Styled.Checkbox
|
|
|
|
type="checkbox"
|
|
|
|
id="confirmationCheckbox"
|
|
|
|
onChange={() => this.setState({ checked: !checked })}
|
|
|
|
checked={checked}
|
|
|
|
aria-label={intl.formatMessage({ id: checkboxMessageId })}
|
|
|
|
/>
|
|
|
|
<span aria-hidden>{intl.formatMessage({ id: checkboxMessageId })}</span>
|
2022-04-12 01:09:13 +08:00
|
|
|
</Styled.Label>
|
2022-03-02 21:42:17 +08:00
|
|
|
) : null }
|
2021-11-11 03:10:35 +08:00
|
|
|
</Styled.Description>
|
2020-05-22 22:35:24 +08:00
|
|
|
|
2021-11-11 03:10:35 +08:00
|
|
|
<Styled.Footer>
|
2022-03-02 22:45:33 +08:00
|
|
|
<Styled.ConfirmationButton
|
2022-03-02 21:42:17 +08:00
|
|
|
color={confirmButtonColor}
|
2022-11-30 19:31:37 +08:00
|
|
|
label={confirmButtonLabel ? confirmButtonLabel : intl.formatMessage(messages.yesLabel)}
|
2022-03-02 22:45:33 +08:00
|
|
|
disabled={disableConfirmButton}
|
2022-03-03 01:11:05 +08:00
|
|
|
data-test={confirmButtonDataTest}
|
2020-05-22 22:35:24 +08:00
|
|
|
onClick={() => {
|
2022-03-02 21:42:17 +08:00
|
|
|
onConfirm(confirmParam, checked);
|
2023-03-21 21:00:46 +08:00
|
|
|
setIsOpen(false);
|
2020-05-22 22:35:24 +08:00
|
|
|
}}
|
|
|
|
/>
|
2022-11-09 01:51:36 +08:00
|
|
|
<Styled.CancelButton
|
2020-05-22 22:35:24 +08:00
|
|
|
label={intl.formatMessage(messages.noLabel)}
|
2023-03-21 21:00:46 +08:00
|
|
|
onClick={() => setIsOpen(false)}
|
2020-05-22 22:35:24 +08:00
|
|
|
/>
|
2021-11-11 03:10:35 +08:00
|
|
|
</Styled.Footer>
|
|
|
|
</Styled.Container>
|
2022-03-02 21:42:17 +08:00
|
|
|
</Styled.ConfirmationModal>
|
2020-05-22 22:35:24 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-02 21:42:17 +08:00
|
|
|
ConfirmationModal.propTypes = propTypes;
|
|
|
|
ConfirmationModal.defaultProps = defaultProps;
|
|
|
|
|
2023-03-21 21:00:46 +08:00
|
|
|
export default ConfirmationModal;
|