feat(dashboard): Migrate to new hooks and API client (#6963)
This commit is contained in:
committed by
GitHub
parent
5ba74ec5fc
commit
8a5c6928f7
@@ -1,9 +1,9 @@
|
||||
import { SalesChannel } from "@medusajs/medusa"
|
||||
import {
|
||||
Product,
|
||||
ProductCollection,
|
||||
ProductVariant,
|
||||
SalesChannel,
|
||||
} from "@medusajs/medusa"
|
||||
ProductCollectionDTO,
|
||||
ProductDTO,
|
||||
ProductVariantDTO,
|
||||
} from "@medusajs/types"
|
||||
import { StatusBadge, Text } from "@medusajs/ui"
|
||||
import { useTranslation } from "react-i18next"
|
||||
import { Thumbnail } from "../thumbnail"
|
||||
@@ -11,7 +11,7 @@ import { Thumbnail } from "../thumbnail"
|
||||
export const ProductVariantCell = ({
|
||||
variants,
|
||||
}: {
|
||||
variants: ProductVariant[] | null
|
||||
variants: ProductVariantDTO[] | null
|
||||
}) => {
|
||||
const { t } = useTranslation()
|
||||
|
||||
@@ -35,7 +35,7 @@ export const ProductVariantCell = ({
|
||||
export const ProductStatusCell = ({
|
||||
status,
|
||||
}: {
|
||||
status: Product["status"]
|
||||
status: ProductDTO["status"]
|
||||
}) => {
|
||||
const { t } = useTranslation()
|
||||
|
||||
@@ -95,7 +95,7 @@ export const ProductAvailabilityCell = ({
|
||||
)
|
||||
}
|
||||
|
||||
export const ProductTitleCell = ({ product }: { product: Product }) => {
|
||||
export const ProductTitleCell = ({ product }: { product: ProductDTO }) => {
|
||||
const thumbnail = product.thumbnail
|
||||
const title = product.title
|
||||
|
||||
@@ -112,7 +112,7 @@ export const ProductTitleCell = ({ product }: { product: Product }) => {
|
||||
export const ProductCollectionCell = ({
|
||||
collection,
|
||||
}: {
|
||||
collection: ProductCollection | null
|
||||
collection: ProductCollectionDTO | null
|
||||
}) => {
|
||||
if (!collection) {
|
||||
return (
|
||||
|
||||
@@ -12,13 +12,13 @@ import {
|
||||
import { Avatar, Text } from "@medusajs/ui"
|
||||
import * as Collapsible from "@radix-ui/react-collapsible"
|
||||
import { useTranslation } from "react-i18next"
|
||||
import { useV2Store } from "../../../lib/api-v2"
|
||||
|
||||
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 (
|
||||
@@ -46,7 +46,7 @@ const MainSidebar = () => {
|
||||
}
|
||||
|
||||
const Header = () => {
|
||||
const { store, isError, error } = useV2Store({})
|
||||
const { store, isError, error } = useStore()
|
||||
|
||||
const name = store?.name
|
||||
const fallback = store?.name?.slice(0, 1).toUpperCase()
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import type { ProductCollection } from "@medusajs/medusa"
|
||||
import { useTranslation } from "react-i18next"
|
||||
|
||||
import { ProductCollectionDTO } from "@medusajs/types"
|
||||
import { PlaceholderCell } from "../../common/placeholder-cell"
|
||||
|
||||
type CollectionCellProps = {
|
||||
collection?: ProductCollection | null
|
||||
collection?: ProductCollectionDTO | null
|
||||
}
|
||||
|
||||
export const CollectionCell = ({ collection }: CollectionCellProps) => {
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import type { Product } from "@medusajs/medusa"
|
||||
import type { PricedProduct } from "@medusajs/medusa/dist/types/pricing"
|
||||
import { useTranslation } from "react-i18next"
|
||||
|
||||
import { ProductDTO } from "@medusajs/types"
|
||||
import { Thumbnail } from "../../../../common/thumbnail"
|
||||
|
||||
type ProductCellProps = {
|
||||
product: Product | PricedProduct
|
||||
product: ProductDTO
|
||||
}
|
||||
|
||||
export const ProductCell = ({ product }: ProductCellProps) => {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import type { SalesChannel } from "@medusajs/medusa"
|
||||
import { Tooltip } from "@medusajs/ui"
|
||||
import { useTranslation } from "react-i18next"
|
||||
|
||||
import { SalesChannelDTO } from "@medusajs/types"
|
||||
import { PlaceholderCell } from "../../common/placeholder-cell"
|
||||
|
||||
type SalesChannelsCellProps = {
|
||||
salesChannels?: SalesChannel[] | null
|
||||
salesChannels?: SalesChannelDTO[] | null
|
||||
}
|
||||
|
||||
export const SalesChannelsCell = ({
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { ProductVariant } from "@medusajs/medusa"
|
||||
import { useTranslation } from "react-i18next"
|
||||
|
||||
import { ProductVariantDTO } from "@medusajs/types"
|
||||
import { PlaceholderCell } from "../../common/placeholder-cell"
|
||||
|
||||
type VariantCellProps = {
|
||||
variants?: ProductVariant[] | null
|
||||
variants?: ProductVariantDTO[] | null
|
||||
}
|
||||
|
||||
export const VariantCell = ({ variants }: VariantCellProps) => {
|
||||
|
||||
Reference in New Issue
Block a user