You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
1.8 KiB

  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { injectIntl, FormattedMessage } from 'react-intl';
  4. import Button from '../../../components/button';
  5. export default @injectIntl
  6. class ConfirmationModal extends React.PureComponent {
  7. static propTypes = {
  8. message: PropTypes.node.isRequired,
  9. confirm: PropTypes.string.isRequired,
  10. onClose: PropTypes.func.isRequired,
  11. onConfirm: PropTypes.func.isRequired,
  12. secondary: PropTypes.string,
  13. onSecondary: PropTypes.func,
  14. closeWhenConfirm: PropTypes.bool,
  15. intl: PropTypes.object.isRequired,
  16. };
  17. static defaultProps = {
  18. closeWhenConfirm: true,
  19. };
  20. componentDidMount() {
  21. this.button.focus();
  22. }
  23. handleClick = () => {
  24. if (this.props.closeWhenConfirm) {
  25. this.props.onClose();
  26. }
  27. this.props.onConfirm();
  28. }
  29. handleSecondary = () => {
  30. this.props.onClose();
  31. this.props.onSecondary();
  32. }
  33. handleCancel = () => {
  34. this.props.onClose();
  35. }
  36. setRef = (c) => {
  37. this.button = c;
  38. }
  39. render () {
  40. const { message, confirm, secondary } = this.props;
  41. return (
  42. <div className='modal-root__modal confirmation-modal'>
  43. <div className='confirmation-modal__container'>
  44. {message}
  45. </div>
  46. <div className='confirmation-modal__action-bar'>
  47. <Button onClick={this.handleCancel} className='confirmation-modal__cancel-button'>
  48. <FormattedMessage id='confirmation_modal.cancel' defaultMessage='Cancel' />
  49. </Button>
  50. {secondary !== undefined && (
  51. <Button text={secondary} onClick={this.handleSecondary} className='confirmation-modal__secondary-button' />
  52. )}
  53. <Button text={confirm} onClick={this.handleClick} ref={this.setRef} />
  54. </div>
  55. </div>
  56. );
  57. }
  58. }