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