2017-04-23 05:39:50 +03:00
|
|
|
import PropTypes from 'prop-types';
|
2023-05-28 17:38:10 +03:00
|
|
|
import { PureComponent } from 'react';
|
|
|
|
|
2017-06-23 17:05:04 +03:00
|
|
|
import { injectIntl, FormattedMessage } from 'react-intl';
|
2023-05-28 17:38:10 +03:00
|
|
|
|
2023-11-15 13:01:51 +02:00
|
|
|
import { Button } from '../../../components/button';
|
2017-04-23 05:39:50 +03:00
|
|
|
|
2023-05-28 15:18:23 +03:00
|
|
|
class ConfirmationModal extends PureComponent {
|
2017-04-23 05:39:50 +03:00
|
|
|
|
2017-05-12 15:44:10 +03:00
|
|
|
static propTypes = {
|
|
|
|
message: PropTypes.node.isRequired,
|
|
|
|
confirm: PropTypes.string.isRequired,
|
|
|
|
onClose: PropTypes.func.isRequired,
|
|
|
|
onConfirm: PropTypes.func.isRequired,
|
2019-03-26 18:34:02 +02:00
|
|
|
secondary: PropTypes.string,
|
|
|
|
onSecondary: PropTypes.func,
|
2021-08-06 13:14:13 +03:00
|
|
|
closeWhenConfirm: PropTypes.bool,
|
2018-11-27 18:31:50 +02:00
|
|
|
onDoNotAsk: PropTypes.func,
|
2017-05-20 18:31:47 +03:00
|
|
|
intl: PropTypes.object.isRequired,
|
2017-05-12 15:44:10 +03:00
|
|
|
};
|
|
|
|
|
2021-08-06 13:14:13 +03:00
|
|
|
static defaultProps = {
|
|
|
|
closeWhenConfirm: true,
|
|
|
|
};
|
|
|
|
|
2017-05-12 15:44:10 +03:00
|
|
|
handleClick = () => {
|
2021-08-06 13:14:13 +03:00
|
|
|
if (this.props.closeWhenConfirm) {
|
|
|
|
this.props.onClose();
|
|
|
|
}
|
2017-04-23 05:39:50 +03:00
|
|
|
this.props.onConfirm();
|
2018-11-27 18:31:50 +02:00
|
|
|
if (this.props.onDoNotAsk && this.doNotAskCheckbox.checked) {
|
|
|
|
this.props.onDoNotAsk();
|
|
|
|
}
|
2023-02-03 21:52:07 +02:00
|
|
|
};
|
2017-04-23 05:39:50 +03:00
|
|
|
|
2019-03-26 18:34:02 +02:00
|
|
|
handleSecondary = () => {
|
|
|
|
this.props.onClose();
|
|
|
|
this.props.onSecondary();
|
2023-02-03 21:52:07 +02:00
|
|
|
};
|
2019-03-26 18:34:02 +02:00
|
|
|
|
2017-05-23 14:10:41 +03:00
|
|
|
handleCancel = () => {
|
2017-04-23 05:39:50 +03:00
|
|
|
this.props.onClose();
|
2023-02-03 21:52:07 +02:00
|
|
|
};
|
2017-04-23 05:39:50 +03:00
|
|
|
|
2018-11-27 18:31:50 +02:00
|
|
|
setDoNotAskRef = (c) => {
|
|
|
|
this.doNotAskCheckbox = c;
|
2023-02-03 21:52:07 +02:00
|
|
|
};
|
2018-11-27 18:31:50 +02:00
|
|
|
|
2017-04-23 05:39:50 +03:00
|
|
|
render () {
|
2019-03-26 18:34:02 +02:00
|
|
|
const { message, confirm, secondary, onDoNotAsk } = this.props;
|
2017-04-23 05:39:50 +03:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className='modal-root__modal confirmation-modal'>
|
|
|
|
<div className='confirmation-modal__container'>
|
|
|
|
{message}
|
|
|
|
</div>
|
|
|
|
|
2018-11-27 18:31:50 +02: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>
|
2019-03-26 18:34:02 +02:00
|
|
|
{secondary !== undefined && (
|
|
|
|
<Button text={secondary} onClick={this.handleSecondary} className='confirmation-modal__secondary-button' />
|
|
|
|
)}
|
2023-10-23 10:43:00 +03:00
|
|
|
<Button text={confirm} onClick={this.handleClick} autoFocus />
|
2018-11-27 18:31:50 +02:00
|
|
|
</div>
|
2017-04-23 05:39:50 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2023-03-25 00:15:25 +02:00
|
|
|
|
|
|
|
export default injectIntl(ConfirmationModal);
|