From 9d0bfc2b391bf19c1174ed87c418d07c13a3a752 Mon Sep 17 00:00:00 2001
From: Kasper Fabricius Kristensen
<45367945+kasperkristensen@users.noreply.github.com>
Date: Mon, 6 May 2024 18:07:44 +0200
Subject: [PATCH] chore(dashboard): Remove feature flag and always load v2
admin (#7251)
---
.../router-provider/route-extensions.tsx | 16 +
.../router-provider/{v2.tsx => route-map.tsx} | 33 +-
.../router-provider/router-provider.tsx | 7 +-
.../router-provider/settings-extensions.tsx | 15 +
.../src/providers/router-provider/v1.tsx | 320 ------------------
5 files changed, 50 insertions(+), 341 deletions(-)
create mode 100644 packages/admin-next/dashboard/src/providers/router-provider/route-extensions.tsx
rename packages/admin-next/dashboard/src/providers/router-provider/{v2.tsx => route-map.tsx} (98%)
create mode 100644 packages/admin-next/dashboard/src/providers/router-provider/settings-extensions.tsx
delete mode 100644 packages/admin-next/dashboard/src/providers/router-provider/v1.tsx
diff --git a/packages/admin-next/dashboard/src/providers/router-provider/route-extensions.tsx b/packages/admin-next/dashboard/src/providers/router-provider/route-extensions.tsx
new file mode 100644
index 0000000000..f82326e45a
--- /dev/null
+++ b/packages/admin-next/dashboard/src/providers/router-provider/route-extensions.tsx
@@ -0,0 +1,16 @@
+import { RouteObject } from "react-router-dom"
+
+import routes from "medusa-admin:routes/pages"
+
+/**
+ * UI Route extensions.
+ */
+export const RouteExtensions: RouteObject[] = routes.pages.map((ext) => {
+ return {
+ path: ext.path,
+ async lazy() {
+ const { default: Component } = await import(/* @vite-ignore */ ext.file)
+ return { Component }
+ },
+ }
+})
diff --git a/packages/admin-next/dashboard/src/providers/router-provider/v2.tsx b/packages/admin-next/dashboard/src/providers/router-provider/route-map.tsx
similarity index 98%
rename from packages/admin-next/dashboard/src/providers/router-provider/v2.tsx
rename to packages/admin-next/dashboard/src/providers/router-provider/route-map.tsx
index 919a2cd83d..2aafd0f003 100644
--- a/packages/admin-next/dashboard/src/providers/router-provider/v2.tsx
+++ b/packages/admin-next/dashboard/src/providers/router-provider/route-map.tsx
@@ -1,3 +1,8 @@
+import {
+ AdminCollectionsRes,
+ AdminProductsRes,
+ AdminRegionsRes,
+} from "@medusajs/medusa"
import {
AdminApiKeyResponse,
AdminCustomerGroupResponse,
@@ -7,26 +12,18 @@ import {
SalesChannelDTO,
UserDTO,
} from "@medusajs/types"
-import {
- AdminCollectionsRes,
- AdminProductsRes,
- AdminRegionsRes,
-} from "@medusajs/medusa"
-import { InventoryItemRes, PriceListRes } from "../../types/api-responses"
import { Outlet, RouteObject } from "react-router-dom"
-import { AdminCustomersRes } from "@medusajs/client-types"
+import { ProtectedRoute } from "../../components/authentication/protected-route"
import { ErrorBoundary } from "../../components/error/error-boundary"
import { MainLayout } from "../../components/layout/main-layout"
-import { ProtectedRoute } from "../../components/authentication/protected-route"
import { SettingsLayout } from "../../components/layout/settings-layout"
+import { InventoryItemRes, PriceListRes } from "../../types/api-responses"
-/**
- * Experimental V2 routes.
- *
- * These routes are only available if the `MEDUSA_V2` feature flag is enabled.
- */
-export const v2Routes: RouteObject[] = [
+import { RouteExtensions } from "./route-extensions"
+import { SettingsExtensions } from "./settings-extensions"
+
+export const RouteMap: RouteObject[] = [
{
path: "/login",
lazy: () => import("../../v2-routes/login"),
@@ -181,7 +178,8 @@ export const v2Routes: RouteObject[] = [
lazy: () =>
import("../../v2-routes/promotions/promotion-detail"),
handle: {
- crumb: (data: AdminPromotionRes) => data.promotion?.code,
+ // TODO: Re-add type when it's available again
+ crumb: (data: any) => data.promotion?.code,
},
children: [
{
@@ -317,7 +315,8 @@ export const v2Routes: RouteObject[] = [
path: ":id",
lazy: () => import("../../v2-routes/customers/customer-detail"),
handle: {
- crumb: (data: AdminCustomersRes) => data.customer.email,
+ // Re-add type when it's available again
+ crumb: (data: any) => data.customer.email,
},
children: [
{
@@ -488,6 +487,7 @@ export const v2Routes: RouteObject[] = [
},
],
},
+ ...RouteExtensions,
],
},
{
@@ -973,6 +973,7 @@ export const v2Routes: RouteObject[] = [
},
],
},
+ ...SettingsExtensions,
],
},
]
diff --git a/packages/admin-next/dashboard/src/providers/router-provider/router-provider.tsx b/packages/admin-next/dashboard/src/providers/router-provider/router-provider.tsx
index da09efa75f..296b9fedf6 100644
--- a/packages/admin-next/dashboard/src/providers/router-provider/router-provider.tsx
+++ b/packages/admin-next/dashboard/src/providers/router-provider/router-provider.tsx
@@ -3,12 +3,9 @@ import {
createBrowserRouter,
} from "react-router-dom"
-import { v1Routes } from "./v1"
-import { v2Routes } from "./v2"
+import { RouteMap } from "./route-map"
-const V2_ENABLED = import.meta.env.VITE_MEDUSA_V2 === "true"
-
-const router = createBrowserRouter(V2_ENABLED ? v2Routes : v1Routes)
+const router = createBrowserRouter(RouteMap)
export const RouterProvider = () => {
return
diff --git a/packages/admin-next/dashboard/src/providers/router-provider/settings-extensions.tsx b/packages/admin-next/dashboard/src/providers/router-provider/settings-extensions.tsx
new file mode 100644
index 0000000000..cd95feda75
--- /dev/null
+++ b/packages/admin-next/dashboard/src/providers/router-provider/settings-extensions.tsx
@@ -0,0 +1,15 @@
+import settings from "medusa-admin:settings/pages"
+import { RouteObject } from "react-router-dom"
+
+/**
+ * UI Settings extensions.
+ */
+export const SettingsExtensions: RouteObject[] = settings.pages.map((ext) => {
+ return {
+ path: `/settings${ext.path}`,
+ async lazy() {
+ const { default: Component } = await import(/* @vite-ignore */ ext.file)
+ return { Component }
+ },
+ }
+})
diff --git a/packages/admin-next/dashboard/src/providers/router-provider/v1.tsx b/packages/admin-next/dashboard/src/providers/router-provider/v1.tsx
deleted file mode 100644
index 16ac2d6255..0000000000
--- a/packages/admin-next/dashboard/src/providers/router-provider/v1.tsx
+++ /dev/null
@@ -1,320 +0,0 @@
-import type {
- AdminDiscountsRes,
- AdminDraftOrdersRes,
- AdminGiftCardsRes,
- AdminOrdersRes,
-} from "@medusajs/medusa"
-import { Outlet, RouteObject } from "react-router-dom"
-
-import { ProtectedRoute } from "../../components/authentication/require-auth"
-import { ErrorBoundary } from "../../components/error/error-boundary"
-import { MainLayout } from "../../components/layout/main-layout"
-
-import routes from "medusa-admin:routes/pages"
-import settings from "medusa-admin:settings/pages"
-
-const routeExtensions: RouteObject[] = routes.pages.map((ext) => {
- return {
- path: ext.path,
- async lazy() {
- const { default: Component } = await import(/* @vite-ignore */ ext.file)
- return { Component }
- },
- }
-})
-
-const settingsExtensions: RouteObject[] = settings.pages.map((ext) => {
- return {
- path: `/settings${ext.path}`,
- async lazy() {
- const { default: Component } = await import(/* @vite-ignore */ ext.file)
- return { Component }
- },
- }
-})
-
-/**
- * V1 routes.
- *
- * These routes are loaded by default.
- */
-export const v1Routes: RouteObject[] = [
- {
- path: "/login",
- lazy: () => import("../../routes/login"),
- },
- {
- path: "/reset-password",
- element: ,
- children: [
- {
- index: true,
- lazy: () =>
- import("../../routes/reset-password/reset-password-request"),
- },
- {
- path: ":token",
- lazy: () => import("../../routes/reset-password/reset-password-token"),
- },
- ],
- },
- {
- path: "/invite",
- lazy: () => import("../../routes/invite"),
- },
- {
- element: ,
- errorElement: ,
- children: [
- {
- path: "/",
- element: ,
- children: [
- {
- index: true,
- lazy: () => import("../../routes/home"),
- },
- {
- path: "/orders",
- handle: {
- crumb: () => "Orders",
- },
- children: [
- {
- path: "",
- lazy: () => import("../../routes/orders/order-list"),
- },
- {
- path: ":id",
- lazy: () => import("../../routes/orders/order-detail"),
- handle: {
- crumb: (data: AdminOrdersRes) =>
- `Order #${data.order.display_id}`,
- },
- children: [
- {
- path: "shipping-address",
- lazy: () =>
- import("../../routes/orders/order-shipping-address"),
- },
- {
- path: "billing-address",
- lazy: () =>
- import("../../routes/orders/order-billing-address"),
- },
- {
- path: "email",
- lazy: () => import("../../routes/orders/order-email"),
- },
- {
- path: "transfer-ownership",
- lazy: () =>
- import("../../routes/orders/order-transfer-ownership"),
- },
- {
- path: "edit",
- lazy: () => import("../../routes/orders/order-edit"),
- },
- {
- path: "returns",
- lazy: () =>
- import("../../routes/orders/order-create-return"),
- },
- {
- path: "refund",
- lazy: () => import("../../routes/orders/order-refund"),
- },
- ],
- },
- ],
- },
- {
- path: "/draft-orders",
- handle: {
- crumb: () => "Draft Orders",
- },
- children: [
- {
- path: "",
- lazy: () =>
- import("../../routes/draft-orders/draft-order-list"),
- children: [
- {
- path: "create",
- lazy: () =>
- import("../../routes/draft-orders/draft-order-create"),
- },
- ],
- },
- {
- path: ":id",
- lazy: () =>
- import("../../routes/draft-orders/draft-order-detail"),
- handle: {
- crumb: (data: AdminDraftOrdersRes) =>
- `Draft #${data.draft_order.display_id}`,
- },
- children: [
- {
- path: "transfer-ownership",
- lazy: () =>
- import(
- "../../routes/draft-orders/draft-order-transfer-ownership"
- ),
- },
- {
- path: "shipping-address",
- lazy: () =>
- import(
- "../../routes/draft-orders/draft-order-shipping-address"
- ),
- },
- {
- path: "billing-address",
- lazy: () =>
- import(
- "../../routes/draft-orders/draft-order-billing-address"
- ),
- },
- {
- path: "email",
- lazy: () =>
- import("../../routes/draft-orders/draft-order-email"),
- },
- ],
- },
- ],
- },
- {
- path: "/categories",
- handle: {
- crumb: () => "Categories",
- },
- children: [
- {
- index: true,
- lazy: () => import("../../routes/categories/list"),
- },
- {
- path: ":id",
- lazy: () => import("../../routes/categories/details"),
- },
- ],
- },
- {
- path: "/inventory",
- handle: {
- crumb: () => "Inventory",
- },
- lazy: () => import("../../routes/inventory/inventory-list"),
- },
- {
- path: "/reservations",
- handle: {
- crumb: () => "Reservations",
- },
- children: [
- {
- path: "",
- lazy: () =>
- import("../../routes/reservations/reservation-list"),
- },
- {
- path: ":id",
- lazy: () =>
- import("../../routes/reservations/reservation-detail"),
- // children: [
- // {
- // path: "edit",
- // lazy: () =>
- // import("../../routes/reservations/reservation-edit"),
- // },
- // ],
- },
- ],
- },
- {
- path: "/gift-cards",
- handle: {
- crumb: () => "Gift Cards",
- },
- children: [
- {
- path: "",
- lazy: () => import("../../routes/gift-cards/gift-card-list"),
- children: [
- {
- path: "create",
- lazy: () =>
- import("../../routes/gift-cards/gift-card-create"),
- },
- ],
- },
- {
- path: ":id",
- lazy: () => import("../../routes/gift-cards/gift-card-detail"),
- handle: {
- crumb: (data: AdminGiftCardsRes) => data.gift_card.code,
- },
- children: [
- {
- path: "edit",
- lazy: () =>
- import("../../routes/gift-cards/gift-card-edit"),
- },
- ],
- },
- ],
- },
- {
- path: "/discounts",
- handle: {
- crumb: () => "Discounts",
- },
- children: [
- {
- path: "",
- lazy: () => import("../../routes/discounts/discount-list"),
- },
- {
- path: "create",
- lazy: () => import("../../routes/discounts/discount-create"),
- },
- {
- path: ":id",
- lazy: () => import("../../routes/discounts/discount-detail"),
- handle: {
- crumb: (data: AdminDiscountsRes) => data.discount.code,
- },
- children: [
- {
- path: "edit",
- lazy: () =>
- import("../../routes/discounts/discount-edit-details"),
- },
- {
- path: "configuration",
- lazy: () =>
- import(
- "../../routes/discounts/discount-edit-configuration"
- ),
- },
- {
- path: "conditions",
- lazy: () =>
- import("../../routes/discounts/discount-edit-conditions"),
- },
- ],
- },
- ],
- },
- ],
- },
- ...routeExtensions,
- ],
- },
- {
- path: "*",
- lazy: () => import("../../routes/no-match"),
- },
-]