jiti-meet/react/features/base/dialog/components/AbstractDialog.js

74 lines
1.5 KiB
JavaScript
Raw Normal View History

2017-03-07 03:34:51 +00:00
import React, { Component } from 'react';
import { hideDialog } from '../actions';
2017-06-07 16:45:04 +00:00
import { DIALOG_PROP_TYPES } from '../constants';
2017-03-07 03:34:51 +00:00
/**
* Abstract dialog to display dialogs.
*/
export default class AbstractDialog extends Component {
/**
* Abstract Dialog component's property types.
*
* @static
*/
static propTypes = {
2017-06-07 16:45:04 +00:00
...DIALOG_PROP_TYPES,
2017-03-07 03:34:51 +00:00
/**
* Used to show/hide the dialog on cancel.
2017-03-07 03:34:51 +00:00
*/
dispatch: React.PropTypes.func
};
2017-03-07 03:34:51 +00:00
/**
* Initializes a new Dialog instance.
*
* @param {Object} props - The read-only properties with which the new
* instance is to be initialized.
*/
constructor(props) {
super(props);
this._onCancel = this._onCancel.bind(this);
this._onSubmit = this._onSubmit.bind(this);
}
/**
* Dispatches action to hide the dialog.
*
* @returns {void}
*/
_onCancel() {
let hide = true;
if (this.props.onCancel) {
hide = this.props.onCancel();
}
if (hide) {
this.props.dispatch(hideDialog());
}
}
/**
* Dispatches the action when submitting the dialog.
*
* @private
* @param {string} value - The submitted value if any.
* @returns {void}
*/
_onSubmit(value) {
let hide = true;
if (this.props.onSubmit) {
hide = this.props.onSubmit(value);
}
if (hide) {
this.props.dispatch(hideDialog());
}
}
}