2017-05-03 01:04:16 +01:00
|
|
|
import React from 'react';
|
2017-04-23 03:39:50 +01:00
|
|
|
import PropTypes from 'prop-types';
|
2017-06-23 15:05:04 +01:00
|
|
|
import { injectIntl, FormattedMessage } from 'react-intl';
|
2017-04-23 03:39:50 +01:00
|
|
|
import Button from '../../../components/button';
|
|
|
|
|
2018-09-14 16:59:48 +01:00
|
|
|
export default @injectIntl
|
|
|
|
class ConfirmationModal extends React.PureComponent {
|
2017-04-23 03:39:50 +01:00
|
|
|
|
2017-05-12 13:44:10 +01:00
|
|
|
static propTypes = {
|
|
|
|
message: PropTypes.node.isRequired,
|
|
|
|
confirm: PropTypes.string.isRequired,
|
|
|
|
onClose: PropTypes.func.isRequired,
|
|
|
|
onConfirm: PropTypes.func.isRequired,
|
2019-03-26 16:34:02 +00:00
|
|
|
secondary: PropTypes.string,
|
|
|
|
onSecondary: PropTypes.func,
|
2017-05-20 16:31:47 +01:00
|
|
|
intl: PropTypes.object.isRequired,
|
2017-05-12 13:44:10 +01:00
|
|
|
};
|
|
|
|
|
2017-05-23 12:10:41 +01:00
|
|
|
componentDidMount() {
|
|
|
|
this.button.focus();
|
|
|
|
}
|
|
|
|
|
2017-05-12 13:44:10 +01:00
|
|
|
handleClick = () => {
|
2017-04-23 03:39:50 +01:00
|
|
|
this.props.onClose();
|
|
|
|
this.props.onConfirm();
|
|
|
|
}
|
|
|
|
|
2019-03-26 16:34:02 +00:00
|
|
|
handleSecondary = () => {
|
|
|
|
this.props.onClose();
|
|
|
|
this.props.onSecondary();
|
|
|
|
}
|
|
|
|
|
2017-05-23 12:10:41 +01:00
|
|
|
handleCancel = () => {
|
2017-04-23 03:39:50 +01:00
|
|
|
this.props.onClose();
|
|
|
|
}
|
|
|
|
|
2017-05-23 12:10:41 +01:00
|
|
|
setRef = (c) => {
|
|
|
|
this.button = c;
|
|
|
|
}
|
|
|
|
|
2017-04-23 03:39:50 +01:00
|
|
|
render () {
|
2019-03-26 16:34:02 +00:00
|
|
|
const { message, confirm, secondary } = this.props;
|
2017-04-23 03:39:50 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className='modal-root__modal confirmation-modal'>
|
|
|
|
<div className='confirmation-modal__container'>
|
|
|
|
{message}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className='confirmation-modal__action-bar'>
|
2017-05-23 12:10:41 +01:00
|
|
|
<Button onClick={this.handleCancel} className='confirmation-modal__cancel-button'>
|
|
|
|
<FormattedMessage id='confirmation_modal.cancel' defaultMessage='Cancel' />
|
|
|
|
</Button>
|
2019-03-26 16:34:02 +00:00
|
|
|
{secondary !== undefined && (
|
|
|
|
<Button text={secondary} onClick={this.handleSecondary} className='confirmation-modal__secondary-button' />
|
|
|
|
)}
|
2017-05-23 12:10:41 +01:00
|
|
|
<Button text={confirm} onClick={this.handleClick} ref={this.setRef} />
|
2017-04-23 03:39:50 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|