2021-03-18 18:54:03 +00:00
|
|
|
/* eslint-disable react/prop-types */
|
|
|
|
import React from "react";
|
|
|
|
import { Redirect, Route } from "react-router-dom";
|
|
|
|
import AppLoader from "../AppLoader";
|
|
|
|
import { inject, observer } from "mobx-react";
|
|
|
|
|
|
|
|
export const PublicRoute = ({ component: Component, ...rest }) => {
|
2021-09-08 13:24:20 +00:00
|
|
|
const { wizardCompleted, isAuthenticated, isLoaded, personal } = rest;
|
2021-03-18 18:54:03 +00:00
|
|
|
const renderComponent = (props) => {
|
|
|
|
if (!isLoaded) {
|
|
|
|
return <AppLoader />;
|
|
|
|
}
|
|
|
|
|
2021-09-08 13:24:20 +00:00
|
|
|
if (isAuthenticated || personal) {
|
2021-03-18 18:54:03 +00:00
|
|
|
return (
|
|
|
|
<Redirect
|
|
|
|
to={{
|
|
|
|
pathname: "/",
|
|
|
|
state: { from: props.location },
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-03-18 19:16:09 +00:00
|
|
|
if (!wizardCompleted && props.location.pathname !== "/wizard") {
|
|
|
|
return (
|
|
|
|
<Redirect
|
|
|
|
to={{
|
|
|
|
pathname: "/wizard",
|
|
|
|
state: { from: props.location },
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-03-18 18:54:03 +00:00
|
|
|
return <Component {...props} {...rest} />;
|
|
|
|
};
|
|
|
|
return <Route {...rest} render={renderComponent} />;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default inject(({ auth }) => {
|
|
|
|
const { settingsStore, isAuthenticated, isLoaded } = auth;
|
2021-09-08 13:24:20 +00:00
|
|
|
const { wizardCompleted, personal } = settingsStore;
|
2021-03-18 18:54:03 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
wizardCompleted,
|
|
|
|
isAuthenticated,
|
|
|
|
isLoaded,
|
2021-09-08 13:24:20 +00:00
|
|
|
personal,
|
2021-03-18 18:54:03 +00:00
|
|
|
};
|
|
|
|
})(observer(PublicRoute));
|