From b00c557e25954ba3e0e9aab24d3d251d508b1ee3 Mon Sep 17 00:00:00 2001 From: Shekar Siri Date: Tue, 28 Dec 2021 16:45:43 +0530 Subject: [PATCH] fix(ui) - redirect to destination path on login --- frontend/app/Router.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/frontend/app/Router.js b/frontend/app/Router.js index e7f05190e..06b71e3cb 100644 --- a/frontend/app/Router.js +++ b/frontend/app/Router.js @@ -76,6 +76,9 @@ const ONBOARDING_REDIRECT_PATH = routes.onboarding(OB_DEFAULT_TAB); fetchUserInfo, fetchTenants }) class Router extends React.Component { + state = { + destinationPath: null + } constructor(props) { super(props); if (props.isLoggedIn) { @@ -85,10 +88,22 @@ class Router extends React.Component { props.fetchTenants(); } - componentDidUpdate(prevProps) { + componentDidMount() { + const { isLoggedIn, location } = this.props; + if (!isLoggedIn) { + this.setState({ destinationPath: location.pathname }); + } + } + + componentDidUpdate(prevProps, prevState) { if (prevProps.email !== this.props.email && !this.props.email) { this.props.fetchTenants(); } + + if (!prevProps.isLoggedIn && this.props.isLoggedIn && this.state.destinationPath !== routes.login()) { + this.props.history.push(this.state.destinationPath); + this.setState({ destinationPath: null }); + } } render() {