From 9766266b97358c8b053d282dea8f64ee55f603db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frane=20Poli=C4=87?= <16856471+fPolic@users.noreply.github.com> Date: Wed, 27 Mar 2024 18:18:48 +0100 Subject: [PATCH] fix(admin-next): admin v2 flag parsing and loading user data (#6843) --- .../src/components/layout/shell/shell.tsx | 22 ++++++++++--------- .../admin-next/dashboard/src/vite-env.d.ts | 2 +- 2 files changed, 13 insertions(+), 11 deletions(-) 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 fe80ebca1d..2c013c5b64 100644 --- a/packages/admin-next/dashboard/src/components/layout/shell/shell.tsx +++ b/packages/admin-next/dashboard/src/components/layout/shell/shell.tsx @@ -30,7 +30,7 @@ import { useSidebar } from "../../../providers/sidebar-provider" import { useTheme } from "../../../providers/theme-provider" import { useV2Session } from "../../../lib/api-v2" -const V2_ENABLED = import.meta.env.VITE_MEDUSA_V2 || false +const V2_ENABLED = import.meta.env.VITE_MEDUSA_V2 || "false" export const Shell = ({ children }: PropsWithChildren) => { return ( @@ -119,19 +119,21 @@ const Breadcrumbs = () => { } const UserBadge = () => { - // Comment: Only place where we switch between the two modes inline. - // This is to avoid having to rebuild the shell for the app. - let { user, isLoading, isError, error } = {} as any + const isV2Enabled = V2_ENABLED === "true" // Medusa V2 disabled - ;({ user, isLoading, isError, error } = useAdminGetSession({ - enabled: V2_ENABLED == "false", - })) + const v1 = useAdminGetSession({ + enabled: !isV2Enabled, + }) // Medusa V2 enabled - ;({ user, isLoading, isError, error } = useV2Session({ - enabled: V2_ENABLED == "true", - })) + const v2 = useV2Session({ + enabled: isV2Enabled, + }) + + // Comment: Only place where we switch between the two modes inline. + // This is to avoid having to rebuild the shell for the app. + const { user, isLoading, isError, error } = !isV2Enabled ? v1 : v2 const name = [user?.first_name, user?.last_name].filter(Boolean).join(" ") const displayName = name || user?.email diff --git a/packages/admin-next/dashboard/src/vite-env.d.ts b/packages/admin-next/dashboard/src/vite-env.d.ts index 04d24530dd..a06ec85a27 100644 --- a/packages/admin-next/dashboard/src/vite-env.d.ts +++ b/packages/admin-next/dashboard/src/vite-env.d.ts @@ -2,7 +2,7 @@ interface ImportMetaEnv { readonly MEDUSA_ADMIN_BACKEND_URL: string - readonly VITE_MEDUSA_V2: boolean + readonly VITE_MEDUSA_V2: "true" | "false" } interface ImportMeta {