fix(orders): load shop dispatch rules
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
"use client"
|
||||
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { getShopById } from "@/lib/api"
|
||||
import {
|
||||
acceptOrder,
|
||||
cancelPreAccept,
|
||||
@@ -13,7 +14,6 @@ import { notifyInfo, notifySuccess } from "@/lib/toast"
|
||||
import type { Order, OrderStatus } from "@/lib/types"
|
||||
import { useAuthStore } from "@/store/auth"
|
||||
import { useOrderStore } from "@/store/orders"
|
||||
import { useShopStore } from "@/store/shops"
|
||||
import {
|
||||
AlertTriangle,
|
||||
CheckCircle2,
|
||||
@@ -24,7 +24,7 @@ import {
|
||||
XCircle,
|
||||
} from "lucide-react"
|
||||
import Link from "next/link"
|
||||
import { useCallback } from "react"
|
||||
import { useCallback, useEffect, useState } from "react"
|
||||
|
||||
interface OrderActionsProps {
|
||||
orderId: string
|
||||
@@ -50,13 +50,34 @@ export default function OrderActions({
|
||||
const currentUserId = useAuthStore((state) => state.user?.id)
|
||||
const storeOrder = useOrderStore((state) => state.orders.find((item) => item.id === orderId))
|
||||
const order = orderProp ?? storeOrder
|
||||
const dispatchMode = useShopStore((state) => {
|
||||
if (!order?.shopId) return "manual"
|
||||
const shop = state.shops.find((item) => item.id === order.shopId)
|
||||
return shop?.dispatchMode ?? "manual"
|
||||
})
|
||||
const [dispatchMode, setDispatchMode] = useState<"manual" | "auto" | null>(null)
|
||||
const resolvedChatSessionId = chatSessionId
|
||||
|
||||
useEffect(() => {
|
||||
if (!order?.shopId) return
|
||||
|
||||
let cancelled = false
|
||||
|
||||
Promise.resolve()
|
||||
.then(() => {
|
||||
if (cancelled) return undefined
|
||||
setDispatchMode(null)
|
||||
return getShopById(order.shopId ?? "")
|
||||
})
|
||||
.then((shop) => {
|
||||
if (cancelled || !shop) return
|
||||
setDispatchMode(shop.dispatchMode)
|
||||
})
|
||||
.catch(() => {
|
||||
if (cancelled) return
|
||||
setDispatchMode(null)
|
||||
})
|
||||
|
||||
return () => {
|
||||
cancelled = true
|
||||
}
|
||||
}, [order?.shopId])
|
||||
|
||||
const status = order?.status ?? initialStatus
|
||||
const isConsumer = order?.consumerId === currentUserId
|
||||
const isPlayer = order?.playerId === currentUserId
|
||||
@@ -136,10 +157,10 @@ export default function OrderActions({
|
||||
</Button>
|
||||
)}
|
||||
{isPlayer &&
|
||||
(order?.shopId && dispatchMode === "auto" ? (
|
||||
(order?.shopId && dispatchMode !== "manual" ? (
|
||||
<Button disabled>
|
||||
<Clock className="mr-1 h-4 w-4" />
|
||||
系统派单中
|
||||
{dispatchMode === "auto" ? "系统派单中" : "读取派单规则..."}
|
||||
</Button>
|
||||
) : (
|
||||
<Button
|
||||
|
||||
Reference in New Issue
Block a user