refactor: remove demo timers and client-side timeout simulation
Remove lib/config/demo-timers.ts and all usages across stores and pages. Order timeout scheduling, dispute auto-progression, and hardcoded countdown displays are removed — timeouts are now handled server-side by the backend.
This commit is contained in:
+1
-78
@@ -1,5 +1,4 @@
|
||||
import type { Actor } from "@/lib/actor"
|
||||
import { DISPUTE_TO_RESOLVED_MS, DISPUTE_TO_REVIEWING_MS } from "@/lib/config/demo-timers"
|
||||
import { allow, deny } from "@/lib/decision"
|
||||
import type { ApiDecision } from "@/lib/errors"
|
||||
import { generateId } from "@/lib/id"
|
||||
@@ -50,17 +49,6 @@ interface DisputeState {
|
||||
submitAppeal: (disputeId: string, actorId: string, reason: string) => ApiDecision
|
||||
}
|
||||
|
||||
const progressTimers = new Map<string, ReturnType<typeof setTimeout>[]>()
|
||||
|
||||
function clearProgressTimers(disputeId: string) {
|
||||
const timers = progressTimers.get(disputeId)
|
||||
if (!timers) return
|
||||
timers.forEach((timer) => {
|
||||
clearTimeout(timer)
|
||||
})
|
||||
progressTimers.delete(disputeId)
|
||||
}
|
||||
|
||||
function resolveParticipantActor(orderId: string, userId: string): Actor | null {
|
||||
const order = useOrderStore.getState().orders.find((item) => item.id === orderId)
|
||||
if (!order) return null
|
||||
@@ -98,71 +86,8 @@ function notifyDispute(orderId: string, title: string, content: string) {
|
||||
}
|
||||
|
||||
export const useDisputeStore = create<DisputeState>((set, get) => {
|
||||
const scheduleProgress = (disputeId: string) => {
|
||||
clearProgressTimers(disputeId)
|
||||
|
||||
const toReviewing = setTimeout(() => {
|
||||
set((state) => ({
|
||||
disputes: state.disputes.map((dispute) => {
|
||||
if (dispute.id !== disputeId) return dispute
|
||||
if (dispute.status !== "open" && dispute.status !== "appealed") return dispute
|
||||
|
||||
return {
|
||||
...dispute,
|
||||
status: "reviewing",
|
||||
timeline: [
|
||||
...dispute.timeline,
|
||||
{
|
||||
id: generateId("timeline"),
|
||||
type: "reviewing",
|
||||
content: "平台已受理并进入审核",
|
||||
createdAt: new Date().toISOString(),
|
||||
},
|
||||
],
|
||||
}
|
||||
}),
|
||||
}))
|
||||
}, DISPUTE_TO_REVIEWING_MS)
|
||||
|
||||
const toResolved = setTimeout(() => {
|
||||
let resolvedOrderId: string | null = null
|
||||
set((state) => ({
|
||||
disputes: state.disputes.map((dispute) => {
|
||||
if (dispute.id !== disputeId) return dispute
|
||||
if (dispute.status !== "reviewing" && dispute.status !== "appealed") return dispute
|
||||
|
||||
resolvedOrderId = dispute.orderId
|
||||
|
||||
return {
|
||||
...dispute,
|
||||
status: "resolved",
|
||||
result: dispute.result ?? "partial_refund",
|
||||
timeline: [
|
||||
...dispute.timeline,
|
||||
{
|
||||
id: generateId("timeline"),
|
||||
type: "resolved",
|
||||
content: "平台已给出仲裁结果",
|
||||
createdAt: new Date().toISOString(),
|
||||
},
|
||||
],
|
||||
}
|
||||
}),
|
||||
}))
|
||||
|
||||
if (resolvedOrderId) {
|
||||
notifyDispute(resolvedOrderId, "争议已处理", "平台已给出争议处理结果")
|
||||
useOrderStore.getState().resolveDispute(resolvedOrderId)
|
||||
}
|
||||
|
||||
clearProgressTimers(disputeId)
|
||||
}, DISPUTE_TO_RESOLVED_MS)
|
||||
|
||||
progressTimers.set(disputeId, [toReviewing, toResolved])
|
||||
}
|
||||
|
||||
return {
|
||||
disputes: [],
|
||||
disputes: [],
|
||||
getDisputeByOrderId: (orderId) => get().disputes.find((dispute) => dispute.orderId === orderId),
|
||||
submitDispute: (input) => {
|
||||
const order = useOrderStore.getState().orders.find((item) => item.id === input.orderId)
|
||||
@@ -208,7 +133,6 @@ export const useDisputeStore = create<DisputeState>((set, get) => {
|
||||
}
|
||||
|
||||
set((state) => ({ disputes: [dispute, ...state.disputes] }))
|
||||
scheduleProgress(dispute.id)
|
||||
return { decision: allow(), dispute }
|
||||
},
|
||||
submitResponse: (disputeId, actorId, reason, evidence) => {
|
||||
@@ -311,7 +235,6 @@ export const useDisputeStore = create<DisputeState>((set, get) => {
|
||||
|
||||
notifyDispute(dispute.orderId, "争议已申诉", "申诉已提交,平台将继续复核")
|
||||
|
||||
scheduleProgress(disputeId)
|
||||
return allow()
|
||||
},
|
||||
}
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
import type { Actor } from "@/lib/actor"
|
||||
import {
|
||||
ORDER_ACCEPT_TIMEOUT_MS,
|
||||
ORDER_CLOSE_TIMEOUT_MS,
|
||||
ORDER_REVIEW_TIMEOUT_MS,
|
||||
} from "@/lib/config/demo-timers"
|
||||
import { allow, deny } from "@/lib/decision"
|
||||
import { evaluateOrderTransition, type OrderAction } from "@/lib/domain/order-machine"
|
||||
import type { ApiDecision } from "@/lib/errors"
|
||||
@@ -48,16 +43,8 @@ interface OrderState {
|
||||
resolveDispute: (orderId: string) => OrderMutationResult
|
||||
}
|
||||
|
||||
const orderTimeouts = new Map<string, ReturnType<typeof setTimeout>>()
|
||||
const pendingCreations = new Set<string>()
|
||||
|
||||
function clearOrderTimeout(orderId: string) {
|
||||
const timer = orderTimeouts.get(orderId)
|
||||
if (!timer) return
|
||||
clearTimeout(timer)
|
||||
orderTimeouts.delete(orderId)
|
||||
}
|
||||
|
||||
function isParticipant(order: Order, userId: string) {
|
||||
return order.consumerId === userId || order.playerId === userId
|
||||
}
|
||||
@@ -149,42 +136,6 @@ function syncChatSession(order: Order, previousStatus: OrderStatus) {
|
||||
}
|
||||
}
|
||||
|
||||
function scheduleOrderTimeout(orderId: string, status: OrderStatus) {
|
||||
clearOrderTimeout(orderId)
|
||||
|
||||
if (status !== "pending_accept" && status !== "pending_close" && status !== "pending_review") {
|
||||
return
|
||||
}
|
||||
|
||||
const timeoutMap: Record<"pending_accept" | "pending_close" | "pending_review", number> = {
|
||||
pending_accept: ORDER_ACCEPT_TIMEOUT_MS,
|
||||
pending_close: ORDER_CLOSE_TIMEOUT_MS,
|
||||
pending_review: ORDER_REVIEW_TIMEOUT_MS,
|
||||
}
|
||||
const timeoutMs = timeoutMap[status]
|
||||
|
||||
const timer = setTimeout(() => {
|
||||
const state = useOrderStore.getState()
|
||||
const order = state.orders.find((item) => item.id === orderId)
|
||||
if (!order || order.status !== status) {
|
||||
orderTimeouts.delete(orderId)
|
||||
return
|
||||
}
|
||||
|
||||
if (status === "pending_accept") {
|
||||
state.autoTimeoutPendingAccept(orderId)
|
||||
} else if (status === "pending_close") {
|
||||
state.autoTimeoutPendingClose(orderId)
|
||||
} else if (status === "pending_review") {
|
||||
state.autoTimeoutPendingReview(orderId)
|
||||
}
|
||||
|
||||
orderTimeouts.delete(orderId)
|
||||
}, timeoutMs)
|
||||
|
||||
orderTimeouts.set(orderId, timer)
|
||||
}
|
||||
|
||||
function notifyOrderStatus(order: Order) {
|
||||
if (!useAuthStore.getState().notificationPrefs.order) {
|
||||
return
|
||||
@@ -346,7 +297,6 @@ export const useOrderStore = create<OrderState>((set, get) => {
|
||||
orders: [order, ...state.orders],
|
||||
}))
|
||||
|
||||
scheduleOrderTimeout(order.id, order.status)
|
||||
return { decision: allow(), order }
|
||||
},
|
||||
createPaidOrder: (input, actor) => {
|
||||
@@ -437,17 +387,3 @@ export const useOrderStore = create<OrderState>((set, get) => {
|
||||
resolveDispute: (orderId) => applyTransition(orderId, "RESOLVE_DISPUTE"),
|
||||
}
|
||||
})
|
||||
|
||||
useOrderStore.subscribe((state, prevState) => {
|
||||
state.orders.forEach((order) => {
|
||||
const prevOrder = prevState.orders.find((item) => item.id === order.id)
|
||||
if (!prevOrder || prevOrder.status !== order.status) {
|
||||
scheduleOrderTimeout(order.id, order.status)
|
||||
}
|
||||
})
|
||||
prevState.orders.forEach((order) => {
|
||||
if (!state.orders.some((item) => item.id === order.id)) {
|
||||
clearOrderTimeout(order.id)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user