From 3eea8f29b7c9c00280899b8b69e45bd1d6261ca4 Mon Sep 17 00:00:00 2001 From: mlogclub Date: Sat, 2 May 2026 20:36:34 +0800 Subject: [PATCH] fix(ticket): ignore stale assign completions --- .../_components/ticket-assign-dialog.tsx | 38 +++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/web/app/dashboard/tickets/_components/ticket-assign-dialog.tsx b/web/app/dashboard/tickets/_components/ticket-assign-dialog.tsx index ad1e19d..b85b22c 100644 --- a/web/app/dashboard/tickets/_components/ticket-assign-dialog.tsx +++ b/web/app/dashboard/tickets/_components/ticket-assign-dialog.tsx @@ -1,6 +1,6 @@ "use client" -import { useEffect, useState } from "react" +import { useEffect, useRef, useState } from "react" import { zodResolver } from "@hookform/resolvers/zod" import { Controller, Resolver, useForm } from "react-hook-form" import { toast } from "sonner" @@ -84,6 +84,7 @@ function TicketAssignDialogBody({ const [saving, setSaving] = useState(false) const [loading, setLoading] = useState(false) const [agents, setAgents] = useState([]) + const activeRef = useRef(false) const form = useForm< z.input, @@ -102,6 +103,13 @@ function TicketAssignDialogBody({ formState: { errors }, } = form + useEffect(() => { + activeRef.current = true + return () => { + activeRef.current = false + } + }, []) + useEffect(() => { reset({ toUserId: currentAssigneeId ? String(currentAssigneeId) : "", @@ -113,12 +121,22 @@ function TicketAssignDialogBody({ setLoading(true) fetchAgentProfilesAll() .then((agentData) => { + if (!activeRef.current) { + return + } setAgents(Array.isArray(agentData) ? agentData : []) }) .catch((error) => { + if (!activeRef.current) { + return + } toast.error(error instanceof Error ? error.message : "加载处理人失败") }) - .finally(() => setLoading(false)) + .finally(() => { + if (activeRef.current) { + setLoading(false) + } + }) }, []) async function onFormSubmit(values: FormValues) { @@ -135,6 +153,9 @@ function TicketAssignDialogBody({ toUserId: Number(values.toUserId), reason: values.reason.trim() || undefined, }) + if (!activeRef.current) { + return + } toast.success(`已批量指派 ${validTicketIds.length} 张工单`) } else { await assignTicket({ @@ -142,14 +163,25 @@ function TicketAssignDialogBody({ toUserId: Number(values.toUserId), reason: values.reason.trim() || undefined, }) + if (!activeRef.current) { + return + } toast.success("处理人已更新") } + if (!activeRef.current) { + return + } onOpenChange(false) await onSuccess?.() } catch (error) { + if (!activeRef.current) { + return + } toast.error(error instanceof Error ? error.message : "指派工单失败") } finally { - setSaving(false) + if (activeRef.current) { + setSaving(false) + } } }