From 42d7c50dc06fba6ea7466a09638fd5c05f89e4b0 Mon Sep 17 00:00:00 2001 From: zetaloop Date: Sat, 25 Apr 2026 15:05:03 +0800 Subject: [PATCH] fix(orders): load shop dispatch rules --- components/order-actions.tsx | 39 +++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/components/order-actions.tsx b/components/order-actions.tsx index 85124ee..e231379 100644 --- a/components/order-actions.tsx +++ b/components/order-actions.tsx @@ -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({ )} {isPlayer && - (order?.shopId && dispatchMode === "auto" ? ( + (order?.shopId && dispatchMode !== "manual" ? ( ) : (