feat: Init. v2 implementation in admin (#6715)

This commit is contained in:
Oli Juhl
2024-03-20 14:28:28 +01:00
committed by GitHub
parent c658bd0233
commit 8155e2cfad
52 changed files with 1951 additions and 23 deletions

View File

@@ -6,7 +6,7 @@ import {
import { v1Routes } from "./v1"
import { v2Routes } from "./v2"
const V2_ENABLED = import.meta.env.MEDUSA_V2 || false
const V2_ENABLED = import.meta.env.VITE_MEDUSA_V2 || false
const router = createBrowserRouter(V2_ENABLED ? v2Routes : v1Routes)

View File

@@ -1,4 +1,38 @@
import { RouteObject } from "react-router-dom"
import { Navigate, RouteObject, useLocation } from "react-router-dom"
import { SettingsLayout } from "../../components/layout/settings-layout"
import { Outlet } from "react-router-dom"
import { SidebarProvider } from "../sidebar-provider"
import { SearchProvider } from "../search-provider"
import { ErrorBoundary } from "../../components/error/error-boundary"
import { Spinner } from "@medusajs/icons"
import { useV2Session } from "../../lib/api-v2"
export const ProtectedRoute = () => {
const { user, isLoading } = useV2Session()
const location = useLocation()
if (isLoading) {
return (
<div className="flex min-h-screen items-center justify-center">
<Spinner className="text-ui-fg-interactive animate-spin" />
</div>
)
}
if (!user) {
return <Navigate to="/login" state={{ from: location }} replace />
}
return (
<SidebarProvider>
<SearchProvider>
<Outlet />
</SearchProvider>
</SidebarProvider>
)
}
/**
* Experimental V2 routes.
@@ -10,8 +44,62 @@ export const v2Routes: RouteObject[] = [
path: "/login",
lazy: () => import("../../v2-routes/login"),
},
{
path: "/",
lazy: () => import("../../v2-routes/home"),
},
{
path: "*",
lazy: () => import("../../routes/no-match"),
},
{
element: <ProtectedRoute />,
errorElement: <ErrorBoundary />,
children: [
{
path: "/settings",
element: <SettingsLayout />,
handle: {
crumb: () => "Settings",
},
children: [
{
index: true,
lazy: () => import("../../v2-routes/settings"),
},
{
path: "profile",
lazy: () => import("../../v2-routes/profile/profile-detail"),
handle: {
crumb: () => "Profile",
},
children: [
{
path: "edit",
lazy: () => import("../../v2-routes/profile/profile-edit"),
},
],
},
{
path: "store",
lazy: () => import("../../v2-routes/store/store-detail"),
handle: {
crumb: () => "Store",
},
children: [
{
path: "edit",
lazy: () => import("../../v2-routes/store/store-edit"),
},
{
path: "add-currencies",
lazy: () =>
import("../../v2-routes/store/store-add-currencies"),
},
],
},
],
},
],
},
]