fix(ui) - redirect to destination path on login

This commit is contained in:
Shekar Siri 2021-12-28 16:45:43 +05:30
parent edd6cc737e
commit b00c557e25

View file

@ -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() {