182 lines
5.5 KiB
TypeScript
182 lines
5.5 KiB
TypeScript
// Copyright (c) 2025-2026 Probo Inc <hello@probo.com>.
|
|
//
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
// copyright notice and this permission notice appear in all copies.
|
|
//
|
|
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
// PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
import { lazy } from "@probo/react-lazy";
|
|
import {
|
|
type AppRoute,
|
|
loaderFromQueryLoader,
|
|
routeFromAppRoute,
|
|
withQueryRef,
|
|
} from "@probo/routes";
|
|
import { Fragment } from "react";
|
|
import { loadQuery } from "react-relay";
|
|
import { createBrowserRouter, redirect } from "react-router";
|
|
|
|
import { MainLayout } from "#/layouts/MainLayout";
|
|
import { DocumentsPage } from "#/pages/DocumentsPage";
|
|
import { OverviewPage } from "#/pages/OverviewPage";
|
|
import { SubprocessorsPage } from "#/pages/SubprocessorsPage";
|
|
import { currentTrustUpdatesQuery, UpdatesPage } from "#/pages/UpdatesPage";
|
|
import {
|
|
currentTrustDocumentsQuery,
|
|
currentTrustGraphQuery,
|
|
currentTrustSubprocessorsQuery,
|
|
} from "#/queries/TrustGraph";
|
|
|
|
import { DocumentPageErrorBoundary } from "./components/DocumentPageErrorBoundary";
|
|
import { PageError } from "./components/PageError";
|
|
import { RootErrorBoundary } from "./components/RootErrorBoundary";
|
|
import { MainSkeleton } from "./components/Skeletons/MainSkeleton";
|
|
import { TabSkeleton } from "./components/Skeletons/TabSkeleton";
|
|
import { consoleEnvironment } from "./providers/RelayProviders";
|
|
|
|
const routes = [
|
|
{
|
|
Component: lazy(() => import("#/pages/auth/AuthLayoutLoader")),
|
|
children: [
|
|
{
|
|
path: "/connect",
|
|
Component: lazy(() => import("#/pages/auth/ConnectPageLoader")),
|
|
},
|
|
{
|
|
path: "/verify-magic-link",
|
|
Component: lazy(() => import("#/pages/auth/VerifyMagicLinkPage")),
|
|
},
|
|
{
|
|
path: "/magic-link-expired",
|
|
Component: lazy(() => import("#/pages/auth/MagicLinkExpiredPage")),
|
|
},
|
|
{
|
|
path: "/magic-link-already-used",
|
|
Component: lazy(() => import("#/pages/auth/MagicLinkAlreadyUsedPage")),
|
|
},
|
|
{
|
|
path: "/full-name",
|
|
Component: lazy(() => import("#/pages/auth/FullNamePage")),
|
|
},
|
|
],
|
|
},
|
|
{
|
|
path: "/",
|
|
loader: () => {
|
|
// eslint-disable-next-line
|
|
throw redirect("/overview");
|
|
},
|
|
Component: Fragment,
|
|
ErrorBoundary: RootErrorBoundary,
|
|
},
|
|
{
|
|
path: "/nda",
|
|
Component: lazy(() => import("#/pages/NDAPageLoader")),
|
|
ErrorBoundary: RootErrorBoundary,
|
|
},
|
|
// Custom domain routes (subdomain-based)
|
|
{
|
|
path: "/overview",
|
|
loader: loaderFromQueryLoader(() =>
|
|
loadQuery(consoleEnvironment, currentTrustGraphQuery, {}),
|
|
),
|
|
Component: withQueryRef(MainLayout),
|
|
Fallback: MainSkeleton,
|
|
ErrorBoundary: RootErrorBoundary,
|
|
children: [
|
|
{
|
|
path: "",
|
|
Fallback: TabSkeleton,
|
|
Component: OverviewPage,
|
|
},
|
|
],
|
|
},
|
|
{
|
|
path: "/documents/:documentId",
|
|
Component: lazy(() => import("#/pages/DocumentPageLoader")),
|
|
ErrorBoundary: DocumentPageErrorBoundary,
|
|
},
|
|
{
|
|
path: "/documents",
|
|
loader: loaderFromQueryLoader(() =>
|
|
loadQuery(consoleEnvironment, currentTrustGraphQuery, {}),
|
|
),
|
|
Component: withQueryRef(MainLayout),
|
|
Fallback: MainSkeleton,
|
|
ErrorBoundary: RootErrorBoundary,
|
|
children: [
|
|
{
|
|
path: "",
|
|
loader: loaderFromQueryLoader(() =>
|
|
loadQuery(consoleEnvironment, currentTrustDocumentsQuery, {}),
|
|
),
|
|
Fallback: TabSkeleton,
|
|
Component: withQueryRef(DocumentsPage),
|
|
},
|
|
],
|
|
},
|
|
{
|
|
path: "/subprocessors",
|
|
loader: loaderFromQueryLoader(() =>
|
|
loadQuery(consoleEnvironment, currentTrustGraphQuery, {}),
|
|
),
|
|
Component: withQueryRef(MainLayout),
|
|
Fallback: MainSkeleton,
|
|
ErrorBoundary: RootErrorBoundary,
|
|
children: [
|
|
{
|
|
path: "",
|
|
loader: loaderFromQueryLoader(() =>
|
|
loadQuery(consoleEnvironment, currentTrustSubprocessorsQuery, {}),
|
|
),
|
|
Fallback: TabSkeleton,
|
|
Component: withQueryRef(SubprocessorsPage),
|
|
},
|
|
],
|
|
},
|
|
{
|
|
path: "/updates",
|
|
loader: loaderFromQueryLoader(() =>
|
|
loadQuery(consoleEnvironment, currentTrustGraphQuery, {}),
|
|
),
|
|
Component: withQueryRef(MainLayout),
|
|
Fallback: MainSkeleton,
|
|
ErrorBoundary: RootErrorBoundary,
|
|
children: [
|
|
{
|
|
path: "",
|
|
loader: loaderFromQueryLoader(() =>
|
|
loadQuery(consoleEnvironment, currentTrustUpdatesQuery, {}),
|
|
),
|
|
Fallback: TabSkeleton,
|
|
Component: withQueryRef(UpdatesPage),
|
|
},
|
|
],
|
|
},
|
|
// Fallback URL to the NotFound Page
|
|
{
|
|
path: "*",
|
|
Component: PageError,
|
|
},
|
|
] satisfies AppRoute[];
|
|
|
|
// Detect basename from current URL path
|
|
// If URL starts with /trust/{slug}, extract that as the basename
|
|
// Otherwise, use "/" for custom domains
|
|
function getBasename(): string {
|
|
const path = window.location.pathname;
|
|
const trustMatch = path.match(/^\/trust\/[^/]+/);
|
|
return trustMatch ? trustMatch[0] : "/";
|
|
}
|
|
|
|
export const router = createBrowserRouter(routes.map(routeFromAppRoute), {
|
|
basename: getBasename(),
|
|
});
|