2017-05-03 02:04:16 +02:00
|
|
|
import React from 'react';
|
2017-04-23 04:39:50 +02:00
|
|
|
import PropTypes from 'prop-types';
|
2017-06-23 16:05:04 +02:00
|
|
|
import { injectIntl, FormattedMessage } from 'react-intl';
|
2017-12-04 08:26:40 +01:00
|
|
|
import Button from 'flavours/glitch/components/button';
|
2017-04-23 04:39:50 +02:00
|
|
|
|
2017-06-23 19:36:54 +02:00
|
|
|
@injectIntl
|
|
|
|
export default class ConfirmationModal extends React.PureComponent {
|
2017-04-23 04:39:50 +02:00
|
|
|
|
2017-05-12 14:44:10 +02:00
|
|
|
static propTypes = {
|
|
|
|
message: PropTypes.node.isRequired,
|
|
|
|
confirm: PropTypes.string.isRequired,
|
|
|
|
onClose: PropTypes.func.isRequired,
|
|
|
|
onConfirm: PropTypes.func.isRequired,
|
2018-11-27 17:31:50 +01:00
|
|
|
onDoNotAsk: PropTypes.func,
|
2017-05-20 17:31:47 +02:00
|
|
|
intl: PropTypes.object.isRequired,
|
2017-05-12 14:44:10 +02:00
|
|
|
};
|
|
|
|
|
2017-05-23 13:10:41 +02:00
|
|
|
componentDidMount() {
|
|
|
|
this.button.focus();
|
|
|
|
}
|
|
|
|
|
2017-05-12 14:44:10 +02:00
|
|
|
handleClick = () => {
|
2017-04-23 04:39:50 +02:00
|
|
|
this.props.onClose();
|
|
|
|
this.props.onConfirm();
|
2018-11-27 17:31:50 +01:00
|
|
|
if (this.props.onDoNotAsk && this.doNotAskCheckbox.checked) {
|
|
|
|
this.props.onDoNotAsk();
|
|
|
|
}
|
2017-04-23 04:39:50 +02:00
|
|
|
}
|
|
|
|
|
2017-05-23 13:10:41 +02:00
|
|
|
handleCancel = () => {
|
2017-04-23 04:39:50 +02:00
|
|
|
this.props.onClose();
|
|
|
|
}
|
|
|
|
|
2017-05-23 13:10:41 +02:00
|
|
|
setRef = (c) => {
|
|
|
|
this.button = c;
|
|
|
|
}
|
|
|
|
|
2018-11-27 17:31:50 +01:00
|
|
|
setDoNotAskRef = (c) => {
|
|
|
|
this.doNotAskCheckbox = c;
|
|
|
|
}
|
|
|
|
|
2017-04-23 04:39:50 +02:00
|
|
|
render () {
|
2018-11-27 17:31:50 +01:00
|
|
|
const { message, confirm, onDoNotAsk } = this.props;
|
2017-04-23 04:39:50 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className='modal-root__modal confirmation-modal'>
|
|
|
|
<div className='confirmation-modal__container'>
|
|
|
|
{message}
|
|
|
|
</div>
|
|
|
|
|
2018-11-27 17:31:50 +01:00
|
|
|
<div>
|
|
|
|
{ onDoNotAsk && (
|
|
|
|
<div className='confirmation-modal__do_not_ask_again'>
|
|
|
|
<input type='checkbox' id='confirmation-modal__do_not_ask_again-checkbox' ref={this.setDoNotAskRef} />
|
|
|
|
<label for='confirmation-modal__do_not_ask_again-checkbox'>
|
|
|
|
<FormattedMessage id='confirmation_modal.do_not_ask_again' defaultMessage='Do not ask for confirmation again' />
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
<div className='confirmation-modal__action-bar'>
|
|
|
|
<Button onClick={this.handleCancel} className='confirmation-modal__cancel-button'>
|
|
|
|
<FormattedMessage id='confirmation_modal.cancel' defaultMessage='Cancel' />
|
|
|
|
</Button>
|
|
|
|
<Button text={confirm} onClick={this.handleClick} ref={this.setRef} />
|
|
|
|
</div>
|
2017-04-23 04:39:50 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|