/* eslint-disable react/prop-types */ import React, { useEffect } from "react"; import { Redirect, Route } from "react-router-dom"; //import Loader from "@docspace/components/loader"; //import Section from "../Section"; // import Error401 from "client/Error401"; // import Error404 from "client/Error404"; import AppLoader from "../AppLoader"; import { inject, observer } from "mobx-react"; import { isMe } from "../../utils"; import combineUrl from "../../utils/combineUrl"; import { AppServerConfig, TenantStatus } from "../../constants"; const PrivateRoute = ({ component: Component, ...rest }) => { const { isAdmin, isAuthenticated, isLoaded, restricted, allowForMe, user, computedMatch, setModuleInfo, modules, currentProductId, wizardCompleted, personal, location, tenantStatus, } = rest; const isPortal = window.location.pathname === "/preparation-portal"; const { params, path } = computedMatch; const { userId } = params; const renderComponent = (props) => { if (isLoaded && !isAuthenticated) { if (personal) { window.location.replace("/"); return <>; } console.log("PrivateRoute render Redirect to login", rest); const redirectPath = wizardCompleted ? "/login" : "/wizard"; return window.location.replace(redirectPath); // return ( // // ); } if (location.pathname === "/" && personal) { return ( ); } if ( isLoaded && isAuthenticated && tenantStatus === TenantStatus.PortalRestore && !isPortal ) { return ( ); } if (!isLoaded) { return ; } // const userLoaded = !isEmpty(user); // if (!userLoaded) { // return ; // } // if (!userLoaded) { // console.log("PrivateRoute render Loader", rest); // return ( //
// // // //
// ); // } if ( !restricted || isAdmin || (allowForMe && userId && isMe(user, userId)) ) { // console.log( // "PrivateRoute render Component", // rest, // Component.name || Component.displayName // ); return ; } if (restricted) { console.log("PrivateRoute render Error401", rest); return ( ); } console.log("PrivateRoute render Error404", rest); return ( ); }; //console.log("PrivateRoute render", rest); return ; }; export default inject(({ auth }) => { const { userStore, isAuthenticated, isLoaded, isAdmin, settingsStore } = auth; const { user } = userStore; const { setModuleInfo, wizardCompleted, personal, tenantStatus, } = settingsStore; return { user, isAuthenticated, isAdmin, isLoaded, setModuleInfo, wizardCompleted, tenantStatus, personal, }; })(observer(PrivateRoute));