From 51acd1da5b4c43df797a517f14e18c98465f215b Mon Sep 17 00:00:00 2001
From: Kasper Fabricius Kristensen
<45367945+kasperkristensen@users.noreply.github.com>
Date: Thu, 11 Apr 2024 10:44:13 +0200
Subject: [PATCH] fix(dashboard): Minor cleanup and improve text legibility
(#7045)
**What**
- Cleans up some artifacts from the V1 -> V2 migrations.
- Removes the MedusaProvider from the root in favor of a plain QueryClient.
- Applies font styles to make the text in admin resemble designs in Figma more closely.
---
packages/admin-next/dashboard/src/app.tsx | 14 +-
.../authentication/protected-route/index.ts | 1 +
.../protected-route/protected-route.tsx | 30 +++
.../require-auth/require-auth.tsx | 3 +
.../components/layout-v2/main-layout/index.ts | 1 -
.../layout-v2/main-layout/main-layout.tsx | 205 ------------------
.../layout/main-layout/main-layout.tsx | 12 +-
.../src/components/layout/shell/shell.tsx | 5 +-
packages/admin-next/dashboard/src/index.css | 3 +-
.../admin-next/dashboard/src/lib/debounce.ts | 20 --
.../dashboard/src/lib/uppercase-first.ts | 4 -
.../feature-provider/feature-context.tsx | 10 +-
.../feature-provider/feature-provider.tsx | 30 +--
.../src/providers/feature-provider/types.ts | 10 +-
.../src/providers/router-provider/v2.tsx | 54 +----
.../sidebar-provider/sidebar-provider.tsx | 12 +-
.../admin-next/dashboard/src/vite-env.d.ts | 2 +-
17 files changed, 96 insertions(+), 320 deletions(-)
create mode 100644 packages/admin-next/dashboard/src/components/authentication/protected-route/index.ts
create mode 100644 packages/admin-next/dashboard/src/components/authentication/protected-route/protected-route.tsx
delete mode 100644 packages/admin-next/dashboard/src/components/layout-v2/main-layout/index.ts
delete mode 100644 packages/admin-next/dashboard/src/components/layout-v2/main-layout/main-layout.tsx
delete mode 100644 packages/admin-next/dashboard/src/lib/debounce.ts
delete mode 100644 packages/admin-next/dashboard/src/lib/uppercase-first.ts
diff --git a/packages/admin-next/dashboard/src/app.tsx b/packages/admin-next/dashboard/src/app.tsx
index 602ac18fba..7c7dd7e07f 100644
--- a/packages/admin-next/dashboard/src/app.tsx
+++ b/packages/admin-next/dashboard/src/app.tsx
@@ -1,24 +1,18 @@
import { Toaster } from "@medusajs/ui"
-import { MedusaProvider } from "medusa-react"
+import { QueryClientProvider } from "@tanstack/react-query"
+import { queryClient } from "./lib/medusa"
import { RouterProvider } from "./providers/router-provider"
import { ThemeProvider } from "./providers/theme-provider"
-import { MEDUSA_BACKEND_URL, queryClient } from "./lib/medusa"
-
function App() {
return (
-
+
-
+
)
}
diff --git a/packages/admin-next/dashboard/src/components/authentication/protected-route/index.ts b/packages/admin-next/dashboard/src/components/authentication/protected-route/index.ts
new file mode 100644
index 0000000000..ca67fd59d2
--- /dev/null
+++ b/packages/admin-next/dashboard/src/components/authentication/protected-route/index.ts
@@ -0,0 +1 @@
+export * from "./protected-route"
diff --git a/packages/admin-next/dashboard/src/components/authentication/protected-route/protected-route.tsx b/packages/admin-next/dashboard/src/components/authentication/protected-route/protected-route.tsx
new file mode 100644
index 0000000000..94d6bc81bf
--- /dev/null
+++ b/packages/admin-next/dashboard/src/components/authentication/protected-route/protected-route.tsx
@@ -0,0 +1,30 @@
+import { Spinner } from "@medusajs/icons"
+import { Navigate, Outlet, useLocation } from "react-router-dom"
+import { useMe } from "../../../hooks/api/users"
+import { SearchProvider } from "../../../providers/search-provider"
+import { SidebarProvider } from "../../../providers/sidebar-provider"
+
+export const ProtectedRoute = () => {
+ const { user, isLoading } = useMe()
+ const location = useLocation()
+
+ if (isLoading) {
+ return (
+
+
+
+ )
+ }
+
+ if (!user) {
+ return
+ }
+
+ return (
+
+
+
+
+
+ )
+}
diff --git a/packages/admin-next/dashboard/src/components/authentication/require-auth/require-auth.tsx b/packages/admin-next/dashboard/src/components/authentication/require-auth/require-auth.tsx
index e3a29ae7ea..cfc8d9a5de 100644
--- a/packages/admin-next/dashboard/src/components/authentication/require-auth/require-auth.tsx
+++ b/packages/admin-next/dashboard/src/components/authentication/require-auth/require-auth.tsx
@@ -5,6 +5,9 @@ import { useAdminGetSession } from "medusa-react"
import { SearchProvider } from "../../../providers/search-provider"
import { SidebarProvider } from "../../../providers/sidebar-provider"
+/**
+ * @deprecated - Delete once all V1 domains have been migrated to V2.
+ */
export const ProtectedRoute = () => {
const { user, isLoading } = useAdminGetSession()
const location = useLocation()
diff --git a/packages/admin-next/dashboard/src/components/layout-v2/main-layout/index.ts b/packages/admin-next/dashboard/src/components/layout-v2/main-layout/index.ts
deleted file mode 100644
index 035d09e6d6..0000000000
--- a/packages/admin-next/dashboard/src/components/layout-v2/main-layout/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export * from "./main-layout"
diff --git a/packages/admin-next/dashboard/src/components/layout-v2/main-layout/main-layout.tsx b/packages/admin-next/dashboard/src/components/layout-v2/main-layout/main-layout.tsx
deleted file mode 100644
index 0b29836030..0000000000
--- a/packages/admin-next/dashboard/src/components/layout-v2/main-layout/main-layout.tsx
+++ /dev/null
@@ -1,205 +0,0 @@
-import {
- Buildings,
- ChevronDownMini,
- CurrencyDollar,
- MinusMini,
- ReceiptPercent,
- ShoppingCart,
- SquaresPlus,
- Tag,
- Users,
-} from "@medusajs/icons"
-import { Avatar, Text } from "@medusajs/ui"
-import * as Collapsible from "@radix-ui/react-collapsible"
-import { useTranslation } from "react-i18next"
-
-import { Skeleton } from "../../common/skeleton"
-import { NavItem, NavItemProps } from "../../layout/nav-item"
-import { Shell } from "../../layout/shell"
-
-import extensions from "medusa-admin:routes/links"
-import { useStore } from "../../../hooks/api/store"
-
-export const MainLayout = () => {
- return (
-
-
-
- )
-}
-
-const MainSidebar = () => {
- return (
-
- )
-}
-
-const Header = () => {
- const { store, isError, error } = useStore()
-
- const name = store?.name
- const fallback = store?.name?.slice(0, 1).toUpperCase()
-
- if (isError) {
- throw error
- }
-
- return (
-
-
-
- {fallback ? (
-
- ) : (
-
- )}
- {name ? (
-
- {store.name}
-
- ) : (
-
- )}
-
-
-
- )
-}
-
-const useCoreRoutes = (): Omit[] => {
- const { t } = useTranslation()
-
- return [
- {
- icon: ,
- label: t("orders.domain"),
- to: "/orders",
- items: [
- {
- label: t("draftOrders.domain"),
- to: "/draft-orders",
- },
- ],
- },
- {
- icon: ,
- label: t("products.domain"),
- to: "/products",
- items: [
- {
- label: t("collections.domain"),
- to: "/collections",
- },
- {
- label: t("categories.domain"),
- to: "/categories",
- },
- {
- label: t("giftCards.domain"),
- to: "/gift-cards",
- },
- ],
- },
- {
- icon: ,
- label: t("inventory.domain"),
- to: "/inventory",
- items: [
- {
- label: t("reservations.domain"),
- to: "/reservations",
- },
- ],
- },
- {
- icon: ,
- label: t("customers.domain"),
- to: "/customers",
- items: [
- {
- label: t("customerGroups.domain"),
- to: "/customer-groups",
- },
- ],
- },
- {
- icon: ,
- label: t("promotions.domain"),
- to: "/promotions",
- },
- {
- icon: ,
- label: t("pricing.domain"),
- to: "/pricing",
- },
- ]
-}
-
-const CoreRouteSection = () => {
- const coreRoutes = useCoreRoutes()
-
- return (
-
- )
-}
-
-const ExtensionRouteSection = () => {
- if (!extensions.links || extensions.links.length === 0) {
- return null
- }
-
- return (
-
-
-
-
-
-
-
-
-
-
-
- {extensions.links.map((link) => {
- return (
- : }
- type="extension"
- />
- )
- })}
-
-
-
-
-
- )
-}
diff --git a/packages/admin-next/dashboard/src/components/layout/main-layout/main-layout.tsx b/packages/admin-next/dashboard/src/components/layout/main-layout/main-layout.tsx
index 40bf61c1f9..6f91909423 100644
--- a/packages/admin-next/dashboard/src/components/layout/main-layout/main-layout.tsx
+++ b/packages/admin-next/dashboard/src/components/layout/main-layout/main-layout.tsx
@@ -11,12 +11,12 @@ import {
} from "@medusajs/icons"
import { Avatar, Text } from "@medusajs/ui"
import * as Collapsible from "@radix-ui/react-collapsible"
-import { useAdminStore } from "medusa-react"
import { useTranslation } from "react-i18next"
+import { useStore } from "../../../hooks/api/store"
import { Skeleton } from "../../common/skeleton"
-import { NavItem, NavItemProps } from "../nav-item"
-import { Shell } from "../shell"
+import { NavItem, NavItemProps } from "../../layout/nav-item"
+import { Shell } from "../../layout/shell"
import extensions from "medusa-admin:routes/links"
@@ -46,7 +46,7 @@ const MainSidebar = () => {
}
const Header = () => {
- const { store, isError, error } = useAdminStore()
+ const { store, isError, error } = useStore()
const name = store?.name
const fallback = store?.name?.slice(0, 1).toUpperCase()
@@ -135,8 +135,8 @@ const useCoreRoutes = (): Omit[] => {
},
{
icon: ,
- label: t("discounts.domain"),
- to: "/discounts",
+ label: t("promotions.domain"),
+ to: "/promotions",
},
{
icon: ,
diff --git a/packages/admin-next/dashboard/src/components/layout/shell/shell.tsx b/packages/admin-next/dashboard/src/components/layout/shell/shell.tsx
index 099724022e..cf65fffb5e 100644
--- a/packages/admin-next/dashboard/src/components/layout/shell/shell.tsx
+++ b/packages/admin-next/dashboard/src/components/layout/shell/shell.tsx
@@ -105,7 +105,6 @@ const Breadcrumbs = () => {
)}
- {/* {!isLast && } */}
{!isLast && ›}
)
@@ -140,7 +139,7 @@ const UserBadge = () => {