diff --git a/app/scenes/root/root.js b/app/scenes/root/root.js index 3e334cd6d..95afc9ac5 100644 --- a/app/scenes/root/root.js +++ b/app/scenes/root/root.js @@ -10,6 +10,7 @@ export default class Root extends React.Component { static propTypes = { credentials: React.PropTypes.object, logoutRequest: React.PropTypes.object, + loginRequest: React.PropTypes.object, actions: React.PropTypes.shape({ goToSelectServer: React.PropTypes.func, goToSelectTeam: React.PropTypes.func, @@ -23,6 +24,20 @@ export default class Root extends React.Component { componentDidMount() { // Any initialization logic for navigation, setting up the client, etc should go here + this.init(); + } + + componentWillReceiveProps(nextProps) { + if (this.props.logoutRequest.status === RequestStatus.STARTED && + nextProps.logoutRequest.status === RequestStatus.SUCCESS) { + this.props.actions.removeStorage(); + } else if (this.props.logoutRequest.status === RequestStatus.SUCCESS && + nextProps.logoutRequest.status === RequestStatus.NOT_STARTED) { + this.init(); + } + } + + init = () => { if (this.props.logoutRequest.status === RequestStatus.SUCCESS) { this.props.actions.removeStorage().then(() => { setTimeout(this.loadStoreAndScene, 1000); @@ -30,12 +45,18 @@ export default class Root extends React.Component { } else { this.loadStoreAndScene(); } - } + }; loadStoreAndScene = () => { this.props.actions.loadStorage().then(() => { if (this.props.credentials.token && this.props.credentials.url) { - this.props.actions.setStoreFromLocalData(this.props.credentials).then(this.props.actions.goToSelectTeam); + this.props.actions.setStoreFromLocalData(this.props.credentials).then(() => { + if (this.props.loginRequest.status === RequestStatus.SUCCESS) { + this.props.actions.goToSelectTeam(); + } else { + this.props.actions.goToSelectServer(); + } + }); } else { this.props.actions.goToSelectServer(); } diff --git a/app/scenes/root/root_container.js b/app/scenes/root/root_container.js index a62997435..10429869e 100644 --- a/app/scenes/root/root_container.js +++ b/app/scenes/root/root_container.js @@ -15,7 +15,8 @@ function mapStateToProps(state, ownProps) { return { ...ownProps, credentials: state.entities.general.credentials, - logoutRequest: state.requests.users.logout + logoutRequest: state.requests.users.logout, + loginRequest: state.requests.users.login }; }