refactor(order): add transition evaluator and timer constants

This commit is contained in:
zetaloop
2026-02-23 11:03:31 +08:00
parent 03fa447864
commit 6517018a9c
6 changed files with 188 additions and 8 deletions
+5 -2
View File
@@ -16,6 +16,7 @@ import {
import { Badge } from "@/components/ui/badge"
import { Button } from "@/components/ui/button"
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
import { DISPUTE_TO_RESOLVED_MS } from "@/lib/config/demo-timers"
import { Label } from "@/components/ui/label"
import { Separator } from "@/components/ui/separator"
import { Textarea } from "@/components/ui/textarea"
@@ -342,7 +343,9 @@ export default function DisputePage({ params }: { params: Promise<{ id: string }
<div className="container mx-auto py-8 px-4 max-w-lg text-center space-y-4">
<AlertTriangle className="h-12 w-12 mx-auto text-yellow-500" />
<h2 className="text-xl font-bold"></h2>
<p className="text-sm text-muted-foreground"> 3 </p>
<p className="text-sm text-muted-foreground">
{Math.floor(DISPUTE_TO_RESOLVED_MS / 1000)}
</p>
<Link href={`/order/${id}`} className="text-sm text-primary hover:underline">
</Link>
@@ -434,7 +437,7 @@ export default function DisputePage({ params }: { params: Promise<{ id: string }
<div className="rounded-md bg-muted/50 p-3 text-xs text-muted-foreground space-y-1">
<p>· </p>
<p>· </p>
<p>· 3 </p>
<p>· {Math.floor(DISPUTE_TO_RESOLVED_MS / 1000)} </p>
<p>· </p>
</div>
+6 -3
View File
@@ -6,6 +6,7 @@ import { use, useEffect, useMemo, useState } from "react"
import OrderActions from "@/components/order-actions"
import { Badge } from "@/components/ui/badge"
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
import { ORDER_ACCEPT_TIMEOUT_MS, ORDER_CLOSE_TIMEOUT_MS } from "@/lib/config/demo-timers"
import { Separator } from "@/components/ui/separator"
import { statusLabels } from "@/lib/constants"
import type { OrderStatus } from "@/lib/types"
@@ -85,11 +86,13 @@ export default function OrderDetailPage({ params }: { params: Promise<{ id: stri
order.status === "pending_accept"
? new Date(order.createdAt).getTime()
: new Date(order.closedAt ?? order.createdAt).getTime()
const remainSeconds = Math.max(0, 30 - Math.floor((nowTs - base) / 1000))
const timeoutMs =
order.status === "pending_accept" ? ORDER_ACCEPT_TIMEOUT_MS : ORDER_CLOSE_TIMEOUT_MS
const remainSeconds = Math.max(0, Math.ceil((timeoutMs - (nowTs - base)) / 1000))
return order.status === "pending_accept"
? `30 秒内无人接单,订单将自动取消(剩余 ${remainSeconds} 秒)`
: `30 秒内未确认,订单将自动进入待评价(剩余 ${remainSeconds} 秒)`
? `${Math.floor(ORDER_ACCEPT_TIMEOUT_MS / 1000)} 秒内无人接单,订单将自动取消(剩余 ${remainSeconds} 秒)`
: `${Math.floor(ORDER_CLOSE_TIMEOUT_MS / 1000)} 秒内未确认,订单将自动进入待评价(剩余 ${remainSeconds} 秒)`
})()
return (