From 97fa0d95b4d26734ce17a489d5e82d7f0298bffb Mon Sep 17 00:00:00 2001 From: Reed Garmsen Date: Wed, 2 Sep 2015 16:26:43 -0700 Subject: [PATCH 1/2] Replaced remaining calls of getInitialState --- web/react/components/team_feature_tab.jsx | 24 ++++++++++++------- .../user_settings_notifications.jsx | 2 +- .../components/user_settings_security.jsx | 10 +++++--- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/web/react/components/team_feature_tab.jsx b/web/react/components/team_feature_tab.jsx index e5398332e6..3251746b8a 100644 --- a/web/react/components/team_feature_tab.jsx +++ b/web/react/components/team_feature_tab.jsx @@ -14,15 +14,9 @@ export default class FeatureTab extends React.Component { this.submitValetFeature = this.submitValetFeature.bind(this); this.handleValetRadio = this.handleValetRadio.bind(this); this.onUpdateSection = this.onUpdateSection.bind(this); + this.setupInitialState = this.setupInitialState.bind(this); - this.state = {}; - var team = this.props.team; - - if (team && team.allow_valet) { - this.state.allowValet = 'true'; - } else { - this.state.allowValet = 'false'; - } + this.state = this.setupInitialState(); } componentWillReceiveProps(newProps) { var team = newProps.team; @@ -44,7 +38,7 @@ export default class FeatureTab extends React.Component { AsyncClient.getMyTeam(); }.bind(this), function fail(err) { - var state = this.getInitialState(); + var state = this.setupInitialState(); state.serverError = err; this.setState(state); }.bind(this) @@ -62,6 +56,18 @@ export default class FeatureTab extends React.Component { this.props.updateSection('valet'); } } + setupInitialState() { + var allowValet; + var team = this.props.team; + + if (team && team.allow_valet) { + allowValet = 'true'; + } else { + allowValet = 'false'; + } + + return {allowValet: allowValet}; + } render() { var clientError = null; var serverError = null; diff --git a/web/react/components/user_settings_notifications.jsx b/web/react/components/user_settings_notifications.jsx index 84a7b62c73..5fe6bbb4e8 100644 --- a/web/react/components/user_settings_notifications.jsx +++ b/web/react/components/user_settings_notifications.jsx @@ -142,7 +142,7 @@ export default class NotificationsTab extends React.Component { this.props.updateTab('general'); } updateSection(section) { - this.setState(this.getInitialState()); + this.setState(getNotificationsStateFromStores()); this.props.updateSection(section); } componentDidMount() { diff --git a/web/react/components/user_settings_security.jsx b/web/react/components/user_settings_security.jsx index d83151cd85..6ccd09cb16 100644 --- a/web/react/components/user_settings_security.jsx +++ b/web/react/components/user_settings_security.jsx @@ -16,8 +16,9 @@ export default class SecurityTab extends React.Component { this.updateNewPassword = this.updateNewPassword.bind(this); this.updateConfirmPassword = this.updateConfirmPassword.bind(this); this.handleClose = this.handleClose.bind(this); + this.setupInitialState = this.setupInitialState.bind(this); - this.state = {currentPassword: '', newPassword: '', confirmPassword: ''}; + this.state = this.setupInitialState(); } submitPassword(e) { e.preventDefault(); @@ -51,10 +52,10 @@ export default class SecurityTab extends React.Component { function success() { this.props.updateSection(''); AsyncClient.getMe(); - this.setState({currentPassword: '', newPassword: '', confirmPassword: ''}); + this.setState(this.setupInitialState()); }.bind(this), function fail(err) { - var state = this.getInitialState(); + var state = this.setupInitialState(); if (err.message) { state.serverError = err.message; } else { @@ -88,6 +89,9 @@ export default class SecurityTab extends React.Component { this.props.updateTab('general'); } + setupInitialState() { + return {currentPassword: '', newPassword: '', confirmPassword: ''}; + } componentDidMount() { $('#user_settings').on('hidden.bs.modal', this.handleClose); } From 7b70892c75aec62a7b4fa326b08fbda26d4e3262 Mon Sep 17 00:00:00 2001 From: Reed Garmsen Date: Wed, 2 Sep 2015 16:42:20 -0700 Subject: [PATCH 2/2] Moved componentWillMount logic into the constructor of the react components it was used in --- .../components/team_signup_send_invites_page.jsx | 11 +++++------ web/react/components/team_signup_welcome_page.jsx | 5 ++--- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/web/react/components/team_signup_send_invites_page.jsx b/web/react/components/team_signup_send_invites_page.jsx index 35d2441c54..11a9980d71 100644 --- a/web/react/components/team_signup_send_invites_page.jsx +++ b/web/react/components/team_signup_send_invites_page.jsx @@ -18,6 +18,11 @@ export default class TeamSignupSendInvitesPage extends React.Component { this.state = { emailEnabled: !ConfigStore.getSettingAsBoolean('ByPassEmail', false) }; + + if (!this.state.emailEnabled) { + this.props.state.wizard = 'username'; + this.props.updateParent(this.props.state); + } } submitBack(e) { e.preventDefault(); @@ -75,12 +80,6 @@ export default class TeamSignupSendInvitesPage extends React.Component { this.submitNext(e); } } - componentWillMount() { - if (!this.state.emailEnabled) { - this.props.state.wizard = 'username'; - this.props.updateParent(this.props.state); - } - } componentDidMount() { if (!this.state.emailEnabled) { // Must use keypress not keyup due to event chain of pressing enter diff --git a/web/react/components/team_signup_welcome_page.jsx b/web/react/components/team_signup_welcome_page.jsx index e4374fa288..43b7aea0e7 100644 --- a/web/react/components/team_signup_welcome_page.jsx +++ b/web/react/components/team_signup_welcome_page.jsx @@ -16,6 +16,8 @@ export default class TeamSignupWelcomePage extends React.Component { this.handleKeyPress = this.handleKeyPress.bind(this); this.state = {useDiff: false}; + + document.addEventListener('keyup', this.handleKeyPress, false); } submitNext(e) { if (!BrowserStore.isLocalStorageSupported()) { @@ -68,9 +70,6 @@ export default class TeamSignupWelcomePage extends React.Component { this.submitNext(event); } } - componentWillMount() { - document.addEventListener('keyup', this.handleKeyPress, false); - } componentWillUnmount() { document.removeEventListener('keyup', this.handleKeyPress, false); }