From 629a121272336ff232f5d0ee0a3371f65c9ee15d Mon Sep 17 00:00:00 2001 From: zetaloop Date: Mon, 23 Feb 2026 11:10:20 +0800 Subject: [PATCH] refactor(order): move auto-dispatch to store with role-based action visibility --- components/order-actions.tsx | 109 +++++++++++++++-------------------- 1 file changed, 45 insertions(+), 64 deletions(-) diff --git a/components/order-actions.tsx b/components/order-actions.tsx index e3506ba..af354e7 100644 --- a/components/order-actions.tsx +++ b/components/order-actions.tsx @@ -10,17 +10,15 @@ import { XCircle, } from "lucide-react" import Link from "next/link" -import { useCallback, useEffect } from "react" +import { useCallback } from "react" import { Button } from "@/components/ui/button" import { acceptOrder, - acceptOrderAsActor, cancelPreAccept, confirmClose, payOrder, requestClose, } from "@/lib/api/orders" -import type { Actor } from "@/lib/policy/actor" import { notifyInfo, notifySuccess } from "@/lib/toast" import type { OrderStatus } from "@/lib/types" import { useAuthStore } from "@/store/auth" @@ -58,6 +56,8 @@ export default function OrderActions({ sessions.find((session) => session.type === "order" && session.orderId === orderId)?.id const status = order?.status ?? initialStatus + const isConsumer = order?.consumerId === currentUserId + const isPlayer = order?.playerId === currentUserId const handleDecision = useCallback( (okMessage: string, result: { decision: { ok: boolean; message?: string } }) => { @@ -71,28 +71,9 @@ export default function OrderActions({ [], ) - useEffect(() => { - if (!order) return - if (order.status !== "pending_accept") return - if (!order.shopId) return - if (dispatchMode !== "auto") return - - const timer = setTimeout(() => { - const systemActor: Actor = { - userId: order.playerId, - role: "player", - shopId: order.shopId, - } - const result = acceptOrderAsActor(orderId, systemActor) - handleDecision("系统已自动派单", result) - }, 3000) - - return () => clearTimeout(timer) - }, [dispatchMode, handleDecision, order, orderId]) - return (
- {status === "pending_payment" && ( + {status === "pending_payment" && isConsumer && ( <> - {order?.shopId && dispatchMode === "auto" ? ( - - ) : ( + {isConsumer && ( )} + {isPlayer && + (order?.shopId && dispatchMode === "auto" ? ( + + ) : ( + + ))} )} @@ -202,19 +182,20 @@ export default function OrderActions({ {status === "pending_close" && ( <> - + {isConsumer && ( + + )}