fix(shop): use backend shop in navigation
This commit is contained in:
@@ -12,11 +12,10 @@ import {
|
|||||||
isDisputedOrder,
|
isDisputedOrder,
|
||||||
isPendingDispatch,
|
isPendingDispatch,
|
||||||
} from "@/lib/domain/order-filters"
|
} from "@/lib/domain/order-filters"
|
||||||
import { resolveOwnerShop } from "@/lib/domain/resolve-current-shop"
|
import { useMyShop } from "@/lib/hooks/use-my-shop"
|
||||||
import type { OrderStatus, UserRole } from "@/lib/types"
|
import type { OrderStatus, UserRole } from "@/lib/types"
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils"
|
||||||
import { useAuthStore } from "@/store/auth"
|
import { useAuthStore } from "@/store/auth"
|
||||||
import { useShopStore } from "@/store/shops"
|
|
||||||
import { Clock, MessageSquare, RefreshCw } from "lucide-react"
|
import { Clock, MessageSquare, RefreshCw } from "lucide-react"
|
||||||
import Link from "next/link"
|
import Link from "next/link"
|
||||||
import { useEffect, useState } from "react"
|
import { useEffect, useState } from "react"
|
||||||
@@ -65,8 +64,19 @@ function getOrderRole(role: UserRole): "consumer" | "player" | "owner" | undefin
|
|||||||
|
|
||||||
export default function OrderListPage() {
|
export default function OrderListPage() {
|
||||||
const { currentRole, user } = useAuthStore()
|
const { currentRole, user } = useAuthStore()
|
||||||
const shops = useShopStore((state) => state.shops)
|
const {
|
||||||
const ownerShop = resolveOwnerShop(user?.id, shops)
|
shop: ownerShop,
|
||||||
|
loading: shopLoading,
|
||||||
|
error: shopError,
|
||||||
|
} = useMyShop(currentRole === "owner")
|
||||||
|
|
||||||
|
if (currentRole === "owner" && shopLoading) {
|
||||||
|
return <div className="text-sm text-muted-foreground">加载中...</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentRole === "owner" && shopError) {
|
||||||
|
return <div className="text-sm text-muted-foreground">{shopError}</div>
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<OrderListContent
|
<OrderListContent
|
||||||
|
|||||||
@@ -15,12 +15,12 @@ import {
|
|||||||
import { Sheet, SheetContent, SheetHeader, SheetTitle, SheetTrigger } from "@/components/ui/sheet"
|
import { Sheet, SheetContent, SheetHeader, SheetTitle, SheetTrigger } from "@/components/ui/sheet"
|
||||||
import { getCurrentUserForLogin, logout as logoutRequest, switchCurrentRole } from "@/lib/api"
|
import { getCurrentUserForLogin, logout as logoutRequest, switchCurrentRole } from "@/lib/api"
|
||||||
import { toApiError } from "@/lib/errors"
|
import { toApiError } from "@/lib/errors"
|
||||||
|
import { useMyShop } from "@/lib/hooks/use-my-shop"
|
||||||
import { notifyInfo } from "@/lib/toast"
|
import { notifyInfo } from "@/lib/toast"
|
||||||
import type { UserRole } from "@/lib/types"
|
import type { UserRole } from "@/lib/types"
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils"
|
||||||
import { useAuthStore } from "@/store/auth"
|
import { useAuthStore } from "@/store/auth"
|
||||||
import { useNotificationStore } from "@/store/notifications"
|
import { useNotificationStore } from "@/store/notifications"
|
||||||
import { useShopStore } from "@/store/shops"
|
|
||||||
import {
|
import {
|
||||||
Bell,
|
Bell,
|
||||||
Gamepad2,
|
Gamepad2,
|
||||||
@@ -57,10 +57,8 @@ export function Header() {
|
|||||||
logout: clearAuth,
|
logout: clearAuth,
|
||||||
user,
|
user,
|
||||||
} = useAuthStore()
|
} = useAuthStore()
|
||||||
const ownerShop = useShopStore((state) =>
|
|
||||||
user ? state.shops.find((shop) => shop.owner.id === user.id) : undefined,
|
|
||||||
)
|
|
||||||
const canOpenDashboard = currentRole === "player" || currentRole === "owner"
|
const canOpenDashboard = currentRole === "player" || currentRole === "owner"
|
||||||
|
const { shop: ownerShop } = useMyShop(isAuthenticated && currentRole === "owner")
|
||||||
|
|
||||||
const navLinks =
|
const navLinks =
|
||||||
currentRole === "consumer"
|
currentRole === "consumer"
|
||||||
|
|||||||
Reference in New Issue
Block a user