bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/common/modal/confirmation/component.jsx

112 lines
3.0 KiB
React
Raw Normal View History

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';
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 = {
confirmButtonColor: PropTypes.string,
disableConfirmButton: PropTypes.bool,
description: PropTypes.string,
};
const defaultProps = {
confirmButtonColor: 'primary',
disableConfirmButton: false,
description: '',
2020-05-22 22:35:24 +08:00
};
class ConfirmationModal extends Component {
2020-05-22 22:35:24 +08:00
constructor(props) {
super(props);
this.state = {
checked: false,
};
}
render() {
const {
intl,
mountModal,
onConfirm,
title,
titleMessageId,
titleMessageExtra,
checkboxMessageId,
confirmButtonColor,
confirmButtonDataTest,
confirmParam,
disableConfirmButton,
description,
2020-05-22 22:35:24 +08:00
} = this.props;
const {
checked,
} = this.state;
const hasCheckbox = !!checkboxMessageId;
2020-05-22 22:35:24 +08:00
return (
<Styled.ConfirmationModal
2020-05-22 22:35:24 +08:00
onRequestClose={() => mountModal(null)}
contentLabel={title}
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>
<Styled.DescriptionText>
{description}
</Styled.DescriptionText>
{ hasCheckbox ? (
<Styled.Label htmlFor="confirmationCheckbox" key="confirmation-checkbox">
<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>
</Styled.Label>
) : 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>
<Styled.ConfirmationButton
color={confirmButtonColor}
2020-05-22 22:35:24 +08:00
label={intl.formatMessage(messages.yesLabel)}
disabled={disableConfirmButton}
data-test={confirmButtonDataTest}
2020-05-22 22:35:24 +08:00
onClick={() => {
onConfirm(confirmParam, checked);
2020-05-22 22:35:24 +08:00
mountModal(null);
}}
/>
<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>
</Styled.ConfirmationModal>
2020-05-22 22:35:24 +08:00
);
}
}
ConfirmationModal.propTypes = propTypes;
ConfirmationModal.defaultProps = defaultProps;
export default withModalMounter(ConfirmationModal);