From 0acab11cf46a9e279d16e803ad32b8aa67e20679 Mon Sep 17 00:00:00 2001 From: nickago Date: Fri, 17 Jul 2015 14:44:13 -0700 Subject: When closing out of a modal, unsaved data and text inside of it is erased. --- web/react/components/create_post.jsx | 2 +- web/react/components/edit_channel_modal.jsx | 3 ++ web/react/components/rename_channel_modal.jsx | 3 ++ web/react/components/rename_team_modal.jsx | 2 +- web/react/components/user_settings.jsx | 46 +++++++++++++++++++++++++-- 5 files changed, 51 insertions(+), 5 deletions(-) (limited to 'web') diff --git a/web/react/components/create_post.jsx b/web/react/components/create_post.jsx index 91d070958..17ed16735 100644 --- a/web/react/components/create_post.jsx +++ b/web/react/components/create_post.jsx @@ -275,7 +275,7 @@ module.exports = React.createClass({ messageText = draft['message']; uploadsInProgress = draft['uploadsInProgress']; } - this.setState({ channel_id: channel_id, messageText: messageText, initialText: messageText, submitting: false, post_error: null, previews: previews, uploadsInProgress: uploadsInProgress }); + this.setState({ channel_id: channel_id, messageText: messageText, initialText: messageText, submitting: false, limit_error: null, server_error: null, post_error: null, previews: previews, uploadsInProgress: uploadsInProgress }); } }, _onActiveThreadChanged: function(rootId, parentId) { diff --git a/web/react/components/edit_channel_modal.jsx b/web/react/components/edit_channel_modal.jsx index d055feacd..0398dba93 100644 --- a/web/react/components/edit_channel_modal.jsx +++ b/web/react/components/edit_channel_modal.jsx @@ -36,6 +36,9 @@ module.exports = React.createClass({ var button = e.relatedTarget; self.setState({ description: $(button).attr('data-desc'), title: $(button).attr('data-title'), channel_id: $(button).attr('data-channelid'), server_error: "" }); }); + $(this.refs.modal.getDOMNode()).on('hidden.bs.modal', function() { + self.setState({description: ""}); + }) }, getInitialState: function() { return { description: "", title: "", channel_id: "" }; diff --git a/web/react/components/rename_channel_modal.jsx b/web/react/components/rename_channel_modal.jsx index 2ae331626..5488b34c6 100644 --- a/web/react/components/rename_channel_modal.jsx +++ b/web/react/components/rename_channel_modal.jsx @@ -95,6 +95,9 @@ module.exports = React.createClass({ var button = $(e.relatedTarget); self.setState({ display_name: button.attr('data-display'), title: button.attr('data-name'), channel_id: button.attr('data-channelid') }); }); + $(this.refs.modal.getDOMNode()).on('hidden.bs.modal', function() { + self.setState({display_name: "", channel_name: "", display_name_error: "", server_error: "", name_error: ""}); + }); }, getInitialState: function() { return { display_name: "", channel_name: "", channel_id: "" }; diff --git a/web/react/components/rename_team_modal.jsx b/web/react/components/rename_team_modal.jsx index a6da57b67..79836e4a8 100644 --- a/web/react/components/rename_team_modal.jsx +++ b/web/react/components/rename_team_modal.jsx @@ -47,7 +47,7 @@ module.exports = React.createClass({ componentDidMount: function() { var self = this; $(this.refs.modal.getDOMNode()).on('hidden.bs.modal', function(e) { - self.setState({ name: self.props.teamDisplayName }); + self.setState({ name: self.props.teamDisplayName, name_error: "", server_error: ""}); }); }, getInitialState: function() { diff --git a/web/react/components/user_settings.jsx b/web/react/components/user_settings.jsx index 1fbbf16ed..17b8a5e30 100644 --- a/web/react/components/user_settings.jsx +++ b/web/react/components/user_settings.jsx @@ -95,11 +95,18 @@ var NotificationsTab = React.createClass({ }.bind(this) ); }, + handleClose: function() { + this.setState({server_error: null}); + }, componentDidMount: function() { UserStore.addChangeListener(this._onChange); + + $('#user_settings1').on('hidden.bs.modal', this.handleClose); }, componentWillUnmount: function() { UserStore.removeChangeListener(this._onChange); + + $('#user_settings1').off('hidden.bs.modal', this.handleClose); }, _onChange: function() { var newState = getNotificationsStateFromStores(); @@ -502,6 +509,23 @@ var SecurityTab = React.createClass({ handleDevicesOpen: function() { $("#user_settings1").modal('hide'); }, + handleClose: function() { + if(this.props.activeSection === 'password') { + this.refs.curPass.getDOMNode().value = ""; + this.refs.newPass.getDOMNode().value = ""; + this.refs.reNewPass.getDOMNode().value = ""; + + this.setState({current_password: '', new_password: '', confirm_password: ''}); + } + + this.setState({server_error: null, password_error: null}); + }, + componentDidMount: function() { + $('#user_settings1').on('hidden.bs.modal', this.handleClose); + }, + componentWillUnmount: function() { + $('#user_settings1').off('hidden.bs.modal', this.handleClose); + }, getInitialState: function() { return { current_password: '', new_password: '', confirm_password: '' }; }, @@ -518,7 +542,7 @@ var SecurityTab = React.createClass({
- +
); @@ -526,7 +550,7 @@ var SecurityTab = React.createClass({
- +
); @@ -534,7 +558,7 @@ var SecurityTab = React.createClass({
- +
); @@ -735,6 +759,15 @@ var GeneralTab = React.createClass({ this.submitActive = false this.props.updateSection(section); }, + handleClose: function() { + this.setState({client_error: null, server_error: null, email_error: null}); + }, + componentDidMount: function() { + $('#user_settings1').on('hidden.bs.modal', this.handleClose); + }, + componentWillUnmount: function() { + $('#user_settings1').off('hidden.bs.modal', this.handleClose); + }, getInitialState: function() { var user = this.props.user; @@ -978,10 +1011,14 @@ var AppearanceTab = React.createClass({ var hex = utils.rgb2hex(e.target.style.backgroundColor); this.setState({ theme: hex.toLowerCase() }); }, + handleClose: function() { + this.setState({server_error: null}); + }, componentDidMount: function() { if (this.props.activeSection === "theme") { $(this.refs[this.state.theme].getDOMNode()).addClass('active-border'); } + $('#user_settings1').on('hidden.bs.modal', this.handleClose); }, componentDidUpdate: function() { if (this.props.activeSection === "theme") { @@ -989,6 +1026,9 @@ var AppearanceTab = React.createClass({ $(this.refs[this.state.theme].getDOMNode()).addClass('active-border'); } }, + componentWillUnmount: function() { + $('#user_settings1').off('hidden.bs.modal', this.handleClose); + }, getInitialState: function() { var user = UserStore.getCurrentUser(); var theme = config.ThemeColors != null ? config.ThemeColors[0] : "#2389d7"; -- cgit v1.2.3-1-g7c22 From dbbe40e893419d78e23b0d73c8bd6a30478cde2c Mon Sep 17 00:00:00 2001 From: nickago Date: Thu, 23 Jul 2015 09:20:37 -0700 Subject: Added a condition to close event listeners on modals when the component is unmounted, and set all unsaved data to be cleared from user settings --- web/react/components/edit_channel_modal.jsx | 10 +++++--- web/react/components/rename_channel_modal.jsx | 10 +++++--- web/react/components/rename_team_modal.jsx | 11 +++++--- web/react/components/user_settings.jsx | 36 ++++++++++++++------------- 4 files changed, 40 insertions(+), 27 deletions(-) (limited to 'web') diff --git a/web/react/components/edit_channel_modal.jsx b/web/react/components/edit_channel_modal.jsx index 0398dba93..a35a531b5 100644 --- a/web/react/components/edit_channel_modal.jsx +++ b/web/react/components/edit_channel_modal.jsx @@ -30,15 +30,19 @@ module.exports = React.createClass({ handleUserInput: function(e) { this.setState({ description: e.target.value }); }, + handleClose: function() { + this.setState({description: "", server_error: ""}); + }, componentDidMount: function() { var self = this; $(this.refs.modal.getDOMNode()).on('show.bs.modal', function(e) { var button = e.relatedTarget; self.setState({ description: $(button).attr('data-desc'), title: $(button).attr('data-title'), channel_id: $(button).attr('data-channelid'), server_error: "" }); }); - $(this.refs.modal.getDOMNode()).on('hidden.bs.modal', function() { - self.setState({description: ""}); - }) + $(this.refs.modal.getDOMNode()).on('hidden.bs.modal', this.handleClose) + }, + componentWillUnmount: function() { + $(this.refs.modal.getDOMNode()).off('hidden.bs.modal', this.handleClose) }, getInitialState: function() { return { description: "", title: "", channel_id: "" }; diff --git a/web/react/components/rename_channel_modal.jsx b/web/react/components/rename_channel_modal.jsx index 5488b34c6..9e4a25f85 100644 --- a/web/react/components/rename_channel_modal.jsx +++ b/web/react/components/rename_channel_modal.jsx @@ -89,15 +89,19 @@ module.exports = React.createClass({ this.refs.channel_name.getDOMNode().value = channel_name; this.setState({ channel_name: channel_name }) }, + handleClose: function() { + this.setState({display_name: "", channel_name: "", display_name_error: "", server_error: "", name_error: ""}); + }, componentDidMount: function() { var self = this; $(this.refs.modal.getDOMNode()).on('show.bs.modal', function(e) { var button = $(e.relatedTarget); self.setState({ display_name: button.attr('data-display'), title: button.attr('data-name'), channel_id: button.attr('data-channelid') }); }); - $(this.refs.modal.getDOMNode()).on('hidden.bs.modal', function() { - self.setState({display_name: "", channel_name: "", display_name_error: "", server_error: "", name_error: ""}); - }); + $(this.refs.modal.getDOMNode()).on('hidden.bs.modal', this.handleClose); + }, + componentWillUnmount: function() { + $(this.refs.modal.getDOMNode()).off('hidden.bs.modal', this.handleClose); }, getInitialState: function() { return { display_name: "", channel_name: "", channel_id: "" }; diff --git a/web/react/components/rename_team_modal.jsx b/web/react/components/rename_team_modal.jsx index 79836e4a8..dfd775a3b 100644 --- a/web/react/components/rename_team_modal.jsx +++ b/web/react/components/rename_team_modal.jsx @@ -44,11 +44,14 @@ module.exports = React.createClass({ onNameChange: function() { this.setState({ name: this.refs.name.getDOMNode().value }) }, + handleClose: function() { + this.setState({ name: this.props.teamDisplayName, name_error: "", server_error: ""}); + }, componentDidMount: function() { - var self = this; - $(this.refs.modal.getDOMNode()).on('hidden.bs.modal', function(e) { - self.setState({ name: self.props.teamDisplayName, name_error: "", server_error: ""}); - }); + $(this.refs.modal.getDOMNode()).on('hidden.bs.modal', this.handleClose); + }, + componentWillUnmount: function() { + $(this.refs.modal.getDOMNode()).off('hidden.bs.modal', this.handleClose); }, getInitialState: function() { return { name: this.props.teamDisplayName }; diff --git a/web/react/components/user_settings.jsx b/web/react/components/user_settings.jsx index 17b8a5e30..b50754ab5 100644 --- a/web/react/components/user_settings.jsx +++ b/web/react/components/user_settings.jsx @@ -11,6 +11,7 @@ var client = require('../utils/client.jsx'); var AsyncClient = require('../utils/async_client.jsx'); var utils = require('../utils/utils.jsx'); var Constants = require('../utils/constants.jsx'); +var assign = require('object-assign'); function getNotificationsStateFromStores() { var user = UserStore.getCurrentUser(); @@ -96,16 +97,18 @@ var NotificationsTab = React.createClass({ ); }, handleClose: function() { - this.setState({server_error: null}); + $(this.getDOMNode()).find(".form-control").each(function() { + this.value = ""; + }); + + this.setState(assign({},getNotificationsStateFromStores(),{server_error: null})); }, componentDidMount: function() { UserStore.addChangeListener(this._onChange); - $('#user_settings1').on('hidden.bs.modal', this.handleClose); }, componentWillUnmount: function() { UserStore.removeChangeListener(this._onChange); - $('#user_settings1').off('hidden.bs.modal', this.handleClose); }, _onChange: function() { @@ -510,15 +513,10 @@ var SecurityTab = React.createClass({ $("#user_settings1").modal('hide'); }, handleClose: function() { - if(this.props.activeSection === 'password') { - this.refs.curPass.getDOMNode().value = ""; - this.refs.newPass.getDOMNode().value = ""; - this.refs.reNewPass.getDOMNode().value = ""; - - this.setState({current_password: '', new_password: '', confirm_password: ''}); - } - - this.setState({server_error: null, password_error: null}); + $(this.getDOMNode()).find(".form-control").each(function() { + this.value = ""; + }); + this.setState({current_password: '', new_password: '', confirm_password: '', server_error: null, password_error: null}); }, componentDidMount: function() { $('#user_settings1').on('hidden.bs.modal', this.handleClose); @@ -542,7 +540,7 @@ var SecurityTab = React.createClass({
- +
); @@ -550,7 +548,7 @@ var SecurityTab = React.createClass({
- +
); @@ -558,7 +556,7 @@ var SecurityTab = React.createClass({
- +
); @@ -760,7 +758,11 @@ var GeneralTab = React.createClass({ this.props.updateSection(section); }, handleClose: function() { - this.setState({client_error: null, server_error: null, email_error: null}); + $(this.getDOMNode()).find(".form-control").each(function() { + this.value = ""; + }); + + this.setState(assign({}, this.getInitialState(), {client_error: null, server_error: null, email_error: null})); }, componentDidMount: function() { $('#user_settings1').on('hidden.bs.modal', this.handleClose); @@ -1012,7 +1014,7 @@ var AppearanceTab = React.createClass({ this.setState({ theme: hex.toLowerCase() }); }, handleClose: function() { - this.setState({server_error: null}); + this.setState({server_error: null}); }, componentDidMount: function() { if (this.props.activeSection === "theme") { -- cgit v1.2.3-1-g7c22