2020-05-22 22:35:24 +08:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import { defineMessages } from 'react-intl';
|
2022-02-15 23:54:55 +08:00
|
|
|
import { withModalMounter } from '/imports/ui/components/common/modal/service';
|
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: {
|
|
|
|
id: 'app.endMeeting.yesLabel',
|
|
|
|
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,
|
|
|
|
mountModal,
|
|
|
|
onConfirm,
|
|
|
|
title,
|
|
|
|
titleMessageId,
|
|
|
|
titleMessageExtra,
|
|
|
|
checkboxMessageId,
|
|
|
|
confirmButtonColor,
|
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
|
2020-05-22 22:35:24 +08:00
|
|
|
onRequestClose={() => mountModal(null)}
|
|
|
|
contentLabel={title}
|
2022-11-11 02:09:21 +08:00
|
|
|
title={title || intl.formatMessage({ id: titleMessageId }, { 0: titleMessageExtra })}
|
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}
|
2020-05-22 22:35:24 +08:00
|
|
|
label={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);
|
2020-05-22 22:35:24 +08:00
|
|
|
mountModal(null);
|
|
|
|
}}
|
|
|
|
/>
|
2022-11-09 01:51:36 +08:00
|
|
|
<Styled.CancelButton
|
2020-05-22 22:35:24 +08:00
|
|
|
label={intl.formatMessage(messages.noLabel)}
|
|
|
|
onClick={() => mountModal(null)}
|
|
|
|
/>
|
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;
|
|
|
|
|
|
|
|
export default withModalMounter(ConfirmationModal);
|