PLT-3220 Fixed create channel modal not saving upon enter (#3380)
* fixed create channel modal not saving upon enter * used componentWillReceiveProps
Этот коммит содержится в:
коммит произвёл
Christopher Speller
родитель
944966f7d1
Коммит
00dc8e734c
@@ -4,6 +4,8 @@
|
||||
import $ from 'jquery';
|
||||
import ReactDOM from 'react-dom';
|
||||
import * as Utils from 'utils/utils.jsx';
|
||||
import Constants from 'utils/constants.jsx';
|
||||
import PreferenceStore from 'stores/preference_store.jsx';
|
||||
|
||||
import {intlShape, injectIntl, defineMessages, FormattedMessage} from 'react-intl';
|
||||
|
||||
@@ -24,23 +26,51 @@ class NewChannelModal extends React.Component {
|
||||
|
||||
this.handleSubmit = this.handleSubmit.bind(this);
|
||||
this.handleChange = this.handleChange.bind(this);
|
||||
this.onEnterKeyDown = this.onEnterKeyDown.bind(this);
|
||||
this.onPreferenceChange = this.onPreferenceChange.bind(this);
|
||||
|
||||
this.ctrlSend = PreferenceStore.getBool(Constants.Preferences.CATEGORY_ADVANCED_SETTINGS, 'send_on_ctrl_enter');
|
||||
|
||||
this.state = {
|
||||
displayNameError: ''
|
||||
};
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
if (nextProps.show === true && this.props.show === false) {
|
||||
this.setState({
|
||||
displayNameError: ''
|
||||
});
|
||||
|
||||
document.addEventListener('keydown', this.onEnterKeyDown);
|
||||
} else if (nextProps.show === false && this.props.show === true) {
|
||||
document.removeEventListener('keydown', this.onEnterKeyDown);
|
||||
}
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
if (Utils.isBrowserIE()) {
|
||||
$('body').addClass('browser--ie');
|
||||
}
|
||||
PreferenceStore.addChangeListener(this.onPreferenceChange);
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
PreferenceStore.removeChangeListener(this.onPreferenceChange);
|
||||
}
|
||||
|
||||
onPreferenceChange() {
|
||||
this.ctrlSend = PreferenceStore.getBool(Constants.Preferences.CATEGORY_ADVANCED_SETTINGS, 'send_on_ctrl_enter');
|
||||
}
|
||||
|
||||
onEnterKeyDown(e) {
|
||||
if (this.ctrlSend && e.keyCode === Constants.KeyCodes.ENTER && e.ctrlKey) {
|
||||
this.handleSubmit(e);
|
||||
} else if (!this.ctrlSend && e.keyCode === Constants.KeyCodes.ENTER && !e.shiftKey && !e.altKey) {
|
||||
this.handleSubmit(e);
|
||||
}
|
||||
}
|
||||
|
||||
handleSubmit(e) {
|
||||
e.preventDefault();
|
||||
|
||||
@@ -52,6 +82,7 @@ class NewChannelModal extends React.Component {
|
||||
|
||||
this.props.onSubmitChannel();
|
||||
}
|
||||
|
||||
handleChange() {
|
||||
const newData = {
|
||||
displayName: ReactDOM.findDOMNode(this.refs.display_name).value,
|
||||
@@ -59,6 +90,7 @@ class NewChannelModal extends React.Component {
|
||||
};
|
||||
this.props.onDataChanged(newData);
|
||||
}
|
||||
|
||||
render() {
|
||||
var displayNameError = null;
|
||||
var serverError = null;
|
||||
|
||||
Ссылка в новой задаче
Block a user