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.

71 lines
2.0 KiB

  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { injectIntl, FormattedMessage } from 'react-intl';
  4. import Button from 'flavours/glitch/components/button';
  5. @injectIntl
  6. export default 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. onDoNotAsk: PropTypes.func,
  13. intl: PropTypes.object.isRequired,
  14. };
  15. componentDidMount() {
  16. this.button.focus();
  17. }
  18. handleClick = () => {
  19. this.props.onClose();
  20. this.props.onConfirm();
  21. if (this.props.onDoNotAsk && this.doNotAskCheckbox.checked) {
  22. this.props.onDoNotAsk();
  23. }
  24. }
  25. handleCancel = () => {
  26. this.props.onClose();
  27. }
  28. setRef = (c) => {
  29. this.button = c;
  30. }
  31. setDoNotAskRef = (c) => {
  32. this.doNotAskCheckbox = c;
  33. }
  34. render () {
  35. const { message, confirm, onDoNotAsk } = this.props;
  36. return (
  37. <div className='modal-root__modal confirmation-modal'>
  38. <div className='confirmation-modal__container'>
  39. {message}
  40. </div>
  41. <div>
  42. { onDoNotAsk && (
  43. <div className='confirmation-modal__do_not_ask_again'>
  44. <input type='checkbox' id='confirmation-modal__do_not_ask_again-checkbox' ref={this.setDoNotAskRef} />
  45. <label for='confirmation-modal__do_not_ask_again-checkbox'>
  46. <FormattedMessage id='confirmation_modal.do_not_ask_again' defaultMessage='Do not ask for confirmation again' />
  47. </label>
  48. </div>
  49. )}
  50. <div className='confirmation-modal__action-bar'>
  51. <Button onClick={this.handleCancel} className='confirmation-modal__cancel-button'>
  52. <FormattedMessage id='confirmation_modal.cancel' defaultMessage='Cancel' />
  53. </Button>
  54. <Button text={confirm} onClick={this.handleClick} ref={this.setRef} />
  55. </div>
  56. </div>
  57. </div>
  58. );
  59. }
  60. }