feat(dashboard): Migrate to new hooks and API client (#6963)

This commit is contained in:
Kasper Fabricius Kristensen
2024-04-05 18:27:08 +02:00
committed by GitHub
parent 5ba74ec5fc
commit 8a5c6928f7
195 changed files with 3919 additions and 6028 deletions

View File

@@ -12,25 +12,21 @@ import {
User as UserIcon,
} from "@medusajs/icons"
import { Avatar, DropdownMenu, IconButton, Kbd, Text, clx } from "@medusajs/ui"
import { PropsWithChildren } from "react"
import {
Link,
Outlet,
UIMatch,
useLocation,
useMatches,
useNavigate,
} from "react-router-dom"
import { useAdminDeleteSession, useAdminGetSession } from "medusa-react"
import { PropsWithChildren } from "react"
import { Skeleton } from "../../common/skeleton"
import { queryClient } from "../../../lib/medusa"
import { useMe } from "../../../hooks/api/users"
import { useSearch } from "../../../providers/search-provider"
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"
export const Shell = ({ children }: PropsWithChildren) => {
return (
@@ -119,22 +115,7 @@ const Breadcrumbs = () => {
}
const UserBadge = () => {
const isV2Enabled = V2_ENABLED === "true"
console.warn(isV2Enabled)
// Medusa V2 disabled
const v1 = useAdminGetSession({
enabled: !isV2Enabled,
})
// Medusa V2 enabled
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 { user, isLoading, isError, error } = useMe()
const name = [user?.first_name, user?.last_name].filter(Boolean).join(" ")
const displayName = name || user?.email
@@ -220,20 +201,20 @@ const ThemeToggle = () => {
}
const Logout = () => {
const navigate = useNavigate()
const { mutateAsync: logoutMutation } = useAdminDeleteSession()
// const navigate = useNavigate()
// const { mutateAsync: logoutMutation } = useAdminDeleteSession()
const handleLayout = async () => {
await logoutMutation(undefined, {
onSuccess: () => {
/**
* When the user logs out, we want to clear the query cache
*/
queryClient.clear()
navigate("/login")
},
})
// await logoutMutation(undefined, {
// onSuccess: () => {
// /**
// * When the user logs out, we want to clear the query cache
// */
// queryClient.clear()
// navigate("/login")
// },
// })
// noop
}
return (