2024-06-18 09:01:13 +03:00
|
|
|
import { Toaster } from '@affine/admin/components/ui/sonner';
|
|
|
|
import { Telemetry } from '@affine/core/telemetry';
|
|
|
|
import { wrapCreateBrowserRouter } from '@sentry/react';
|
|
|
|
import { useEffect } from 'react';
|
|
|
|
import {
|
|
|
|
createBrowserRouter as reactRouterCreateBrowserRouter,
|
|
|
|
RouterProvider,
|
|
|
|
useLocation,
|
|
|
|
useNavigate,
|
|
|
|
} from 'react-router-dom';
|
|
|
|
|
|
|
|
import { TooltipProvider } from './components/ui/tooltip';
|
|
|
|
|
|
|
|
const createBrowserRouter = wrapCreateBrowserRouter(
|
|
|
|
reactRouterCreateBrowserRouter
|
|
|
|
);
|
|
|
|
|
|
|
|
const _createBrowserRouter = window.SENTRY_RELEASE
|
|
|
|
? createBrowserRouter
|
|
|
|
: reactRouterCreateBrowserRouter;
|
|
|
|
|
|
|
|
const Redirect = function Redirect() {
|
|
|
|
const location = useLocation();
|
|
|
|
const navigate = useNavigate();
|
|
|
|
useEffect(() => {
|
2024-08-13 09:11:03 +03:00
|
|
|
if (!location.pathname.startsWith('/admin/accounts')) {
|
|
|
|
navigate('/admin/accounts', { replace: true });
|
2024-06-18 09:01:13 +03:00
|
|
|
}
|
|
|
|
}, [location, navigate]);
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const router = _createBrowserRouter(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
path: '/',
|
|
|
|
element: <Redirect />,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: '/admin',
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
path: '',
|
2024-08-13 09:11:03 +03:00
|
|
|
element: <Redirect />,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: '/admin/accounts',
|
|
|
|
lazy: () => import('./modules/accounts'),
|
2024-06-18 09:01:13 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
path: '/admin/auth',
|
|
|
|
lazy: () => import('./modules/auth'),
|
|
|
|
},
|
2024-08-13 08:45:00 +03:00
|
|
|
{
|
|
|
|
path: '/admin/ai',
|
|
|
|
lazy: () => import('./modules/ai'),
|
|
|
|
},
|
2024-06-18 09:01:13 +03:00
|
|
|
{
|
2024-08-13 09:11:03 +03:00
|
|
|
path: '/admin/setup',
|
|
|
|
lazy: () => import('./modules/setup'),
|
2024-06-18 09:01:13 +03:00
|
|
|
},
|
2024-08-13 09:38:39 +03:00
|
|
|
{
|
|
|
|
path: '/admin/config',
|
|
|
|
lazy: () => import('./modules/config'),
|
|
|
|
},
|
2024-08-13 09:51:31 +03:00
|
|
|
{
|
|
|
|
path: '/admin/settings',
|
|
|
|
lazy: () => import('./modules/settings'),
|
|
|
|
},
|
2024-06-18 09:01:13 +03:00
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
{
|
|
|
|
future: {
|
|
|
|
v7_normalizeFormMethod: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
export const App = () => {
|
|
|
|
return (
|
|
|
|
<TooltipProvider>
|
|
|
|
<Telemetry />
|
|
|
|
<RouterProvider router={router} />
|
|
|
|
<Toaster />
|
|
|
|
</TooltipProvider>
|
|
|
|
);
|
|
|
|
};
|