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.

63 lines
1.6 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. intl: PropTypes.object.isRequired,
  15. };
  16. componentDidMount() {
  17. this.button.focus();
  18. }
  19. handleClick = () => {
  20. this.props.onClose();
  21. this.props.onConfirm();
  22. }
  23. handleSecondary = () => {
  24. this.props.onClose();
  25. this.props.onSecondary();
  26. }
  27. handleCancel = () => {
  28. this.props.onClose();
  29. }
  30. setRef = (c) => {
  31. this.button = c;
  32. }
  33. render () {
  34. const { message, confirm, secondary } = this.props;
  35. return (
  36. <div className='modal-root__modal confirmation-modal'>
  37. <div className='confirmation-modal__container'>
  38. {message}
  39. </div>
  40. <div className='confirmation-modal__action-bar'>
  41. <Button onClick={this.handleCancel} className='confirmation-modal__cancel-button'>
  42. <FormattedMessage id='confirmation_modal.cancel' defaultMessage='Cancel' />
  43. </Button>
  44. {secondary !== undefined && (
  45. <Button text={secondary} onClick={this.handleSecondary} className='confirmation-modal__secondary-button' />
  46. )}
  47. <Button text={confirm} onClick={this.handleClick} ref={this.setRef} />
  48. </div>
  49. </div>
  50. );
  51. }
  52. }