2017-04-23 12:39:50 +10:00
|
|
|
import PropTypes from 'prop-types';
|
2023-05-24 01:15:17 +10:00
|
|
|
import { PureComponent } from 'react';
|
|
|
|
|
2017-06-24 00:05:04 +10:00
|
|
|
import { injectIntl, FormattedMessage } from 'react-intl';
|
2023-05-24 01:15:17 +10:00
|
|
|
|
2023-10-23 18:43:00 +11:00
|
|
|
import { Button } from '../../../components/button';
|
2017-04-23 12:39:50 +10:00
|
|
|
|
2023-05-23 18:52:27 +10:00
|
|
|
class ConfirmationModal extends PureComponent {
|
2017-04-23 12:39:50 +10:00
|
|
|
|
2017-05-12 22:44:10 +10:00
|
|
|
static propTypes = {
|
|
|
|
message: PropTypes.node.isRequired,
|
|
|
|
confirm: PropTypes.string.isRequired,
|
|
|
|
onClose: PropTypes.func.isRequired,
|
|
|
|
onConfirm: PropTypes.func.isRequired,
|
2019-03-27 03:34:02 +11:00
|
|
|
secondary: PropTypes.string,
|
|
|
|
onSecondary: PropTypes.func,
|
2021-08-06 20:14:13 +10:00
|
|
|
closeWhenConfirm: PropTypes.bool,
|
2017-05-21 01:31:47 +10:00
|
|
|
intl: PropTypes.object.isRequired,
|
2017-05-12 22:44:10 +10:00
|
|
|
};
|
|
|
|
|
2021-08-06 20:14:13 +10:00
|
|
|
static defaultProps = {
|
|
|
|
closeWhenConfirm: true,
|
|
|
|
};
|
|
|
|
|
2017-05-12 22:44:10 +10:00
|
|
|
handleClick = () => {
|
2021-08-06 20:14:13 +10:00
|
|
|
if (this.props.closeWhenConfirm) {
|
|
|
|
this.props.onClose();
|
|
|
|
}
|
2017-04-23 12:39:50 +10:00
|
|
|
this.props.onConfirm();
|
2023-01-30 11:45:35 +11:00
|
|
|
};
|
2017-04-23 12:39:50 +10:00
|
|
|
|
2019-03-27 03:34:02 +11:00
|
|
|
handleSecondary = () => {
|
|
|
|
this.props.onClose();
|
|
|
|
this.props.onSecondary();
|
2023-01-30 11:45:35 +11:00
|
|
|
};
|
2019-03-27 03:34:02 +11:00
|
|
|
|
2017-05-23 21:10:41 +10:00
|
|
|
handleCancel = () => {
|
2017-04-23 12:39:50 +10:00
|
|
|
this.props.onClose();
|
2023-01-30 11:45:35 +11:00
|
|
|
};
|
2017-04-23 12:39:50 +10:00
|
|
|
|
|
|
|
render () {
|
2019-03-27 03:34:02 +11:00
|
|
|
const { message, confirm, secondary } = this.props;
|
2017-04-23 12:39:50 +10: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 21:10:41 +10:00
|
|
|
<Button onClick={this.handleCancel} className='confirmation-modal__cancel-button'>
|
|
|
|
<FormattedMessage id='confirmation_modal.cancel' defaultMessage='Cancel' />
|
|
|
|
</Button>
|
2019-03-27 03:34:02 +11:00
|
|
|
{secondary !== undefined && (
|
|
|
|
<Button text={secondary} onClick={this.handleSecondary} className='confirmation-modal__secondary-button' />
|
|
|
|
)}
|
2023-10-23 18:43:00 +11:00
|
|
|
<Button text={confirm} onClick={this.handleClick} autoFocus />
|
2017-04-23 12:39:50 +10:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2023-03-24 13:17:53 +11:00
|
|
|
|
|
|
|
export default injectIntl(ConfirmationModal);
|