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.

AbstractDialog.js 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import React, { Component } from 'react';
  2. import { hideDialog } from '../actions';
  3. import { DIALOG_PROP_TYPES } from '../constants';
  4. /**
  5. * Abstract dialog to display dialogs.
  6. */
  7. export default class AbstractDialog extends Component {
  8. /**
  9. * Abstract Dialog component's property types.
  10. *
  11. * @static
  12. */
  13. static propTypes = {
  14. ...DIALOG_PROP_TYPES,
  15. /**
  16. * Used to show/hide the dialog on cancel.
  17. */
  18. dispatch: React.PropTypes.func
  19. };
  20. /**
  21. * Initializes a new Dialog instance.
  22. *
  23. * @param {Object} props - The read-only properties with which the new
  24. * instance is to be initialized.
  25. */
  26. constructor(props) {
  27. super(props);
  28. this._onCancel = this._onCancel.bind(this);
  29. this._onSubmit = this._onSubmit.bind(this);
  30. }
  31. /**
  32. * Dispatches action to hide the dialog.
  33. *
  34. * @returns {void}
  35. */
  36. _onCancel() {
  37. let hide = true;
  38. if (this.props.onCancel) {
  39. hide = this.props.onCancel();
  40. }
  41. if (hide) {
  42. this.props.dispatch(hideDialog());
  43. }
  44. }
  45. /**
  46. * Dispatches the action when submitting the dialog.
  47. *
  48. * @private
  49. * @param {string} value - The submitted value if any.
  50. * @returns {void}
  51. */
  52. _onSubmit(value) {
  53. let hide = true;
  54. if (this.props.onSubmit) {
  55. hide = this.props.onSubmit(value);
  56. }
  57. if (hide) {
  58. this.props.dispatch(hideDialog());
  59. }
  60. }
  61. }