diff --git a/.github/workflows/dev-build.yaml b/.github/workflows/dev-build.yaml index a333a969..fbcdcb7c 100644 --- a/.github/workflows/dev-build.yaml +++ b/.github/workflows/dev-build.yaml @@ -6,7 +6,7 @@ concurrency: on: push: - branches: ['4582-epub2-static-build'] # put your current branch to create a build. Core team only. + branches: ['4686-feat-migrate-react-router-to-use-createbrowserrouter'] # put your current branch to create a build. Core team only. paths-ignore: - '**.md' - 'cloud-deployments/*' diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index 24e4becb..1ae785cc 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -1,16 +1,9 @@ -import React, { lazy, Suspense } from "react"; -import { Routes, Route } from "react-router-dom"; +import React, { Suspense } from "react"; +import { Outlet } from "react-router-dom"; import { I18nextProvider } from "react-i18next"; import { AuthProvider } from "@/AuthContext"; -import PrivateRoute, { - AdminRoute, - ManagerRoute, -} from "@/components/PrivateRoute"; import { ToastContainer } from "react-toastify"; import "react-toastify/dist/ReactToastify.css"; -import Login from "@/pages/Login"; -import SimpleSSOPassthrough from "@/pages/Login/SSO/simple"; -import OnboardingFlow from "@/pages/OnboardingFlow"; import i18n from "./i18n"; import { PfpProvider } from "./PfpContext"; @@ -20,83 +13,6 @@ import { ThemeProvider } from "./ThemeContext"; import { PWAModeProvider } from "./PWAContext"; import KeyboardShortcutsHelp from "@/components/KeyboardShortcutsHelp"; -const Main = lazy(() => import("@/pages/Main")); -const InvitePage = lazy(() => import("@/pages/Invite")); -const WorkspaceChat = lazy(() => import("@/pages/WorkspaceChat")); -const AdminUsers = lazy(() => import("@/pages/Admin/Users")); -const AdminInvites = lazy(() => import("@/pages/Admin/Invitations")); -const AdminWorkspaces = lazy(() => import("@/pages/Admin/Workspaces")); -const AdminLogs = lazy(() => import("@/pages/Admin/Logging")); -const AdminAgents = lazy(() => import("@/pages/Admin/Agents")); -const GeneralChats = lazy(() => import("@/pages/GeneralSettings/Chats")); -const InterfaceSettings = lazy( - () => import("@/pages/GeneralSettings/Settings/Interface") -); -const BrandingSettings = lazy( - () => import("@/pages/GeneralSettings/Settings/Branding") -); - -const ChatSettings = lazy( - () => import("@/pages/GeneralSettings/Settings/Chat") -); - -const GeneralApiKeys = lazy(() => import("@/pages/GeneralSettings/ApiKeys")); -const GeneralLLMPreference = lazy( - () => import("@/pages/GeneralSettings/LLMPreference") -); -const GeneralTranscriptionPreference = lazy( - () => import("@/pages/GeneralSettings/TranscriptionPreference") -); -const GeneralAudioPreference = lazy( - () => import("@/pages/GeneralSettings/AudioPreference") -); -const GeneralEmbeddingPreference = lazy( - () => import("@/pages/GeneralSettings/EmbeddingPreference") -); -const EmbeddingTextSplitterPreference = lazy( - () => import("@/pages/GeneralSettings/EmbeddingTextSplitterPreference") -); -const GeneralVectorDatabase = lazy( - () => import("@/pages/GeneralSettings/VectorDatabase") -); -const GeneralSecurity = lazy(() => import("@/pages/GeneralSettings/Security")); -const GeneralBrowserExtension = lazy( - () => import("@/pages/GeneralSettings/BrowserExtensionApiKey") -); -const WorkspaceSettings = lazy(() => import("@/pages/WorkspaceSettings")); - -const ChatEmbedWidgets = lazy( - () => import("@/pages/GeneralSettings/ChatEmbedWidgets") -); -const PrivacyAndData = lazy( - () => import("@/pages/GeneralSettings/PrivacyAndData") -); -const ExperimentalFeatures = lazy( - () => import("@/pages/Admin/ExperimentalFeatures") -); -const LiveDocumentSyncManage = lazy( - () => import("@/pages/Admin/ExperimentalFeatures/Features/LiveSync/manage") -); -const AgentBuilder = lazy(() => import("@/pages/Admin/AgentBuilder")); -const CommunityHubTrending = lazy( - () => import("@/pages/GeneralSettings/CommunityHub/Trending") -); -const CommunityHubAuthentication = lazy( - () => import("@/pages/GeneralSettings/CommunityHub/Authentication") -); -const CommunityHubImportItem = lazy( - () => import("@/pages/GeneralSettings/CommunityHub/ImportItem") -); -const SystemPromptVariables = lazy( - () => import("@/pages/Admin/SystemPromptVariables") -); -const MobileConnections = lazy( - () => import("@/pages/GeneralSettings/MobileConnections") -); -const DefaultSystemPrompt = lazy( - () => import("@/pages/Admin/DefaultSystemPrompt") -); - export default function App() { return ( @@ -106,198 +22,7 @@ export default function App() { - - } - /> - } /> - } - /> - - } - /> - } - /> - } - /> - } - /> - - {/* Admin */} - } - /> - - } - /> - - } - /> - - } - /> - - } - /> - } - /> - } - /> - - } - /> - - } - /> - } - /> - } - /> - {/* Manager */} - } - /> - } - /> - } - /> - } - /> - } - /> - } - /> - } - /> - } - /> - } - /> - - } - /> - } - /> - } - /> - } - /> - } - /> - {/* Onboarding Flow */} - } /> - } - /> - - {/* Experimental feature pages */} - {/* Live Document Sync feature */} - - } - /> - - } - /> - - } - /> - - } - /> - - } - /> - + diff --git a/frontend/src/main.jsx b/frontend/src/main.jsx index bb415f3a..58e496cc 100644 --- a/frontend/src/main.jsx +++ b/frontend/src/main.jsx @@ -1,15 +1,383 @@ import React from "react"; import ReactDOM from "react-dom/client"; -import { BrowserRouter as Router } from "react-router-dom"; +import { createBrowserRouter, RouterProvider } from "react-router-dom"; import App from "@/App.jsx"; +import PrivateRoute, { + AdminRoute, + ManagerRoute, +} from "@/components/PrivateRoute"; +import Login from "@/pages/Login"; +import SimpleSSOPassthrough from "@/pages/Login/SSO/simple"; +import OnboardingFlow from "@/pages/OnboardingFlow"; import "@/index.css"; + const isDev = process.env.NODE_ENV !== "production"; const REACTWRAP = isDev ? React.Fragment : React.StrictMode; +const router = createBrowserRouter([ + { + path: "/", + element: , + children: [ + { + path: "/", + lazy: async () => { + const { default: Main } = await import("@/pages/Main"); + return { element: }; + }, + }, + { + path: "/login", + element: , + }, + { + path: "/sso/simple", + element: , + }, + { + path: "/workspace/:slug/settings/:tab", + lazy: async () => { + const { default: WorkspaceSettings } = await import( + "@/pages/WorkspaceSettings" + ); + return { element: }; + }, + }, + { + path: "/workspace/:slug", + lazy: async () => { + const { default: WorkspaceChat } = await import( + "@/pages/WorkspaceChat" + ); + return { element: }; + }, + }, + { + path: "/workspace/:slug/t/:threadSlug", + lazy: async () => { + const { default: WorkspaceChat } = await import( + "@/pages/WorkspaceChat" + ); + return { element: }; + }, + }, + { + path: "/accept-invite/:code", + lazy: async () => { + const { default: InvitePage } = await import("@/pages/Invite"); + return { element: }; + }, + }, + // Admin routes + { + path: "/settings/llm-preference", + lazy: async () => { + const { default: GeneralLLMPreference } = await import( + "@/pages/GeneralSettings/LLMPreference" + ); + return { element: }; + }, + }, + { + path: "/settings/transcription-preference", + lazy: async () => { + const { default: GeneralTranscriptionPreference } = await import( + "@/pages/GeneralSettings/TranscriptionPreference" + ); + return { + element: , + }; + }, + }, + { + path: "/settings/audio-preference", + lazy: async () => { + const { default: GeneralAudioPreference } = await import( + "@/pages/GeneralSettings/AudioPreference" + ); + return { + element: , + }; + }, + }, + { + path: "/settings/embedding-preference", + lazy: async () => { + const { default: GeneralEmbeddingPreference } = await import( + "@/pages/GeneralSettings/EmbeddingPreference" + ); + return { + element: , + }; + }, + }, + { + path: "/settings/text-splitter-preference", + lazy: async () => { + const { default: EmbeddingTextSplitterPreference } = await import( + "@/pages/GeneralSettings/EmbeddingTextSplitterPreference" + ); + return { + element: , + }; + }, + }, + { + path: "/settings/vector-database", + lazy: async () => { + const { default: GeneralVectorDatabase } = await import( + "@/pages/GeneralSettings/VectorDatabase" + ); + return { + element: , + }; + }, + }, + { + path: "/settings/agents", + lazy: async () => { + const { default: AdminAgents } = await import("@/pages/Admin/Agents"); + return { element: }; + }, + }, + { + path: "/settings/agents/builder", + lazy: async () => { + const { default: AgentBuilder } = await import( + "@/pages/Admin/AgentBuilder" + ); + return { + element: ( + + ), + }; + }, + }, + { + path: "/settings/agents/builder/:flowId", + lazy: async () => { + const { default: AgentBuilder } = await import( + "@/pages/Admin/AgentBuilder" + ); + return { + element: ( + + ), + }; + }, + }, + { + path: "/settings/event-logs", + lazy: async () => { + const { default: AdminLogs } = await import("@/pages/Admin/Logging"); + return { element: }; + }, + }, + { + path: "/settings/embed-chat-widgets", + lazy: async () => { + const { default: ChatEmbedWidgets } = await import( + "@/pages/GeneralSettings/ChatEmbedWidgets" + ); + return { element: }; + }, + }, + // Manager routes + { + path: "/settings/security", + lazy: async () => { + const { default: GeneralSecurity } = await import( + "@/pages/GeneralSettings/Security" + ); + return { element: }; + }, + }, + { + path: "/settings/privacy", + lazy: async () => { + const { default: PrivacyAndData } = await import( + "@/pages/GeneralSettings/PrivacyAndData" + ); + return { element: }; + }, + }, + { + path: "/settings/interface", + lazy: async () => { + const { default: InterfaceSettings } = await import( + "@/pages/GeneralSettings/Settings/Interface" + ); + return { element: }; + }, + }, + { + path: "/settings/branding", + lazy: async () => { + const { default: BrandingSettings } = await import( + "@/pages/GeneralSettings/Settings/Branding" + ); + return { element: }; + }, + }, + { + path: "/settings/default-system-prompt", + lazy: async () => { + const { default: DefaultSystemPrompt } = await import( + "@/pages/Admin/DefaultSystemPrompt" + ); + return { element: }; + }, + }, + { + path: "/settings/chat", + lazy: async () => { + const { default: ChatSettings } = await import( + "@/pages/GeneralSettings/Settings/Chat" + ); + return { element: }; + }, + }, + { + path: "/settings/beta-features", + lazy: async () => { + const { default: ExperimentalFeatures } = await import( + "@/pages/Admin/ExperimentalFeatures" + ); + return { element: }; + }, + }, + { + path: "/settings/api-keys", + lazy: async () => { + const { default: GeneralApiKeys } = await import( + "@/pages/GeneralSettings/ApiKeys" + ); + return { element: }; + }, + }, + { + path: "/settings/system-prompt-variables", + lazy: async () => { + const { default: SystemPromptVariables } = await import( + "@/pages/Admin/SystemPromptVariables" + ); + return { + element: , + }; + }, + }, + { + path: "/settings/browser-extension", + lazy: async () => { + const { default: GeneralBrowserExtension } = await import( + "@/pages/GeneralSettings/BrowserExtensionApiKey" + ); + return { + element: , + }; + }, + }, + { + path: "/settings/workspace-chats", + lazy: async () => { + const { default: GeneralChats } = await import( + "@/pages/GeneralSettings/Chats" + ); + return { element: }; + }, + }, + { + path: "/settings/invites", + lazy: async () => { + const { default: AdminInvites } = await import( + "@/pages/Admin/Invitations" + ); + return { element: }; + }, + }, + { + path: "/settings/users", + lazy: async () => { + const { default: AdminUsers } = await import("@/pages/Admin/Users"); + return { element: }; + }, + }, + { + path: "/settings/workspaces", + lazy: async () => { + const { default: AdminWorkspaces } = await import( + "@/pages/Admin/Workspaces" + ); + return { element: }; + }, + }, + // Onboarding Flow + { + path: "/onboarding", + element: , + }, + { + path: "/onboarding/:step", + element: , + }, + // Experimental feature pages + { + path: "/settings/beta-features/live-document-sync/manage", + lazy: async () => { + const { default: LiveDocumentSyncManage } = await import( + "@/pages/Admin/ExperimentalFeatures/Features/LiveSync/manage" + ); + return { + element: , + }; + }, + }, + { + path: "/settings/community-hub/trending", + lazy: async () => { + const { default: CommunityHubTrending } = await import( + "@/pages/GeneralSettings/CommunityHub/Trending" + ); + return { element: }; + }, + }, + { + path: "/settings/community-hub/authentication", + lazy: async () => { + const { default: CommunityHubAuthentication } = await import( + "@/pages/GeneralSettings/CommunityHub/Authentication" + ); + return { + element: , + }; + }, + }, + { + path: "/settings/community-hub/import-item", + lazy: async () => { + const { default: CommunityHubImportItem } = await import( + "@/pages/GeneralSettings/CommunityHub/ImportItem" + ); + return { + element: , + }; + }, + }, + { + path: "/settings/mobile-connections", + lazy: async () => { + const { default: MobileConnections } = await import( + "@/pages/GeneralSettings/MobileConnections" + ); + return { element: }; + }, + }, + ], + }, +]); + ReactDOM.createRoot(document.getElementById("root")).render( - - - + );