|
| 1 | +import React from "react" |
| 2 | +import {Routes,Route,useNavigate, BrowserRouter} from "react-router-dom" |
| 3 | +import {Loading} from "./components/Loading" |
| 4 | +import {SERVER_LOADING_MESSAGE} from "./components/constants" |
| 5 | +import {PlansPage} from "./pages/PlansPage" |
| 6 | +import PrivateRoute from "./routing/PrivateRoute" |
| 7 | +import {WOQLClientObj} from './init-woql-client' |
| 8 | +import {ServerError} from './components/ServerError' |
| 9 | +import {InvitePage} from './pages/InvitePage' |
| 10 | +import {localSettings} from "../localSettings" |
| 11 | +import * as PATH from "./routing/constants" |
| 12 | + |
| 13 | +import {Home} from "./pages/Home" |
| 14 | +import {PageNotFound} from "./pages/PageNotFound" |
| 15 | +import {PLANS} from "./routing/constants"; |
| 16 | +import TestApp from "./TestApp" |
| 17 | + |
| 18 | +import {OrganizationHome } from "./pages/OrganizationHome" |
| 19 | +import {Profile} from "./pages/Profile" |
| 20 | +import { DocumentControlMain } from "./pages/DocumentControlMain" |
| 21 | +import {DataProductsHome} from "./pages/DataProductsHome" |
| 22 | +import { ProductsExplorer } from "./pages/ProductsExplorer" |
| 23 | +import { ModelProductPage } from "./pages/ModelProductPage" |
| 24 | + |
| 25 | +export function App (props){ |
| 26 | + let navigate = useNavigate(); |
| 27 | + const {connectionError,loadingServer,clientUser,accessControlDashboard,woqlClient} = WOQLClientObj() |
| 28 | + if(!clientUser) return "" |
| 29 | + // we have this loading only in terminusX, it is auth0 information/login loading |
| 30 | + const {loading} = clientUser |
| 31 | + |
| 32 | + if (clientUser.firstLogin === true && window.location.pathname.indexOf("/invite/") === -1) { |
| 33 | + clientUser.firstLogin = false |
| 34 | + //only if the user is not invited in a team |
| 35 | + window.location.replace(`/${PLANS}`) |
| 36 | + |
| 37 | + } |
| 38 | + |
| 39 | + // this happen after confirm you password linking in the email url |
| 40 | + if (window.location.search.includes("supportSignUp=true")) { |
| 41 | + window.location.replace('/') |
| 42 | + } |
| 43 | + |
| 44 | + if(connectionError) { |
| 45 | + return <ServerError message={connectionError}/> |
| 46 | + } |
| 47 | + |
| 48 | + if(loading || loadingServer) { |
| 49 | + return <main role="main" className="loading-parent content mr-3 ml-5"> |
| 50 | + <Loading message={SERVER_LOADING_MESSAGE}/> |
| 51 | + </main> |
| 52 | + } |
| 53 | + //the accessControlDashboard in terminusX is created only after the login |
| 54 | + // so he can be undefined at the start |
| 55 | + const isAdmin = accessControlDashboard ? accessControlDashboard.isAdmin() : false |
| 56 | + |
| 57 | + const basename = process.env.BASE_URL ? {basename:process.env.BASE_URL} : {} |
| 58 | + |
| 59 | + return <div className="container-fluid container-background h-100"> |
| 60 | + <Routes> |
| 61 | + {getRoutes(clientUser,isAdmin, woqlClient)} |
| 62 | + </Routes> |
| 63 | + </div> |
| 64 | +} |
| 65 | + |
| 66 | +function getRoutes(clientUser, isAdmin, woqlClient){ |
| 67 | + //const client = createApolloClient() |
| 68 | + |
| 69 | + if(localSettings.connection_type==="LOCAL"){ |
| 70 | + return <React.Fragment> |
| 71 | + <Route index element={<Home/>} /> |
| 72 | + </React.Fragment> |
| 73 | + } |
| 74 | + return <React.Fragment> |
| 75 | + {/*<Route path="/verify" element={<VerifyEmail/>}/>*/} |
| 76 | + <Route path="/verify" element={<TestApp/>} /> |
| 77 | + <Route path = {PATH.INVITE_PAGE} element = {<PrivateRoute component={InvitePage}/>} /> |
| 78 | + <Route path={PATH.PLANS} element={<PrivateRoute component={PlansPage}/>}/> |
| 79 | + <Route path="*" element={<PageNotFound/>} /> |
| 80 | + <Route index element={<PrivateRoute component={Home}/>} /> |
| 81 | + <Route path=":organization" > |
| 82 | + <Route index element={<PrivateRoute component={OrganizationHome}></PrivateRoute>}/> |
| 83 | + <Route path = {PATH.PROFILE} element = {<PrivateRoute component={Profile}/>} /> |
| 84 | + |
| 85 | + <Route path=":dataProduct" element={<DocumentControlMain/>} > |
| 86 | + <Route index element={<PrivateRoute component={DataProductsHome}/>} /> |
| 87 | + <Route path={PATH.PRODUCT_MODELS} element={<PrivateRoute component={ModelProductPage}/>} /> |
| 88 | + |
| 89 | + </Route> |
| 90 | + </Route> |
| 91 | + </React.Fragment> |
| 92 | +} |
0 commit comments