feat: wire order and chat state flow
This commit is contained in:
@@ -1,13 +1,17 @@
|
||||
"use client"
|
||||
|
||||
import { ArrowLeft, CheckCircle, Clock, Star } from "lucide-react"
|
||||
import Link from "next/link"
|
||||
import { notFound } from "next/navigation"
|
||||
import { use, useEffect } from "react"
|
||||
import OrderActions from "@/components/order-actions"
|
||||
import { Badge } from "@/components/ui/badge"
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
|
||||
import { Separator } from "@/components/ui/separator"
|
||||
import { statusLabels } from "@/lib/constants"
|
||||
import { mockChatSessions, mockOrders, mockReviews } from "@/lib/mock"
|
||||
import { mockReviews } from "@/lib/mock"
|
||||
import type { OrderStatus } from "@/lib/types"
|
||||
import { useChatStore } from "@/store/chat"
|
||||
import { useOrderStore } from "@/store/orders"
|
||||
|
||||
const normalStatusSteps: OrderStatus[] = [
|
||||
"pending_payment",
|
||||
@@ -28,13 +32,28 @@ const disputedStatusSteps: OrderStatus[] = [
|
||||
|
||||
const cancelledStatusSteps: OrderStatus[] = ["pending_payment", "pending_accept", "cancelled"]
|
||||
|
||||
export default async function OrderDetailPage({ params }: { params: Promise<{ id: string }> }) {
|
||||
const { id } = await params
|
||||
const order = mockOrders.find((o) => o.id === id)
|
||||
if (!order) notFound()
|
||||
export default function OrderDetailPage({ params }: { params: Promise<{ id: string }> }) {
|
||||
const { id } = use(params)
|
||||
const order = useOrderStore((state) => state.orders.find((item) => item.id === id))
|
||||
const sessions = useChatStore((state) => state.sessions)
|
||||
const ensureOrderSession = useChatStore((state) => state.ensureOrderSession)
|
||||
|
||||
useEffect(() => {
|
||||
if (!order) return
|
||||
if (order.status === "pending_payment" || order.status === "cancelled") return
|
||||
ensureOrderSession(order)
|
||||
}, [order, ensureOrderSession])
|
||||
|
||||
if (!order) {
|
||||
return (
|
||||
<div className="container mx-auto py-8 px-4 text-center text-muted-foreground">
|
||||
订单不存在
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const reviews = mockReviews.filter((r) => r.orderId === id)
|
||||
const chatSession = mockChatSessions.find((s) => s.orderId === id)
|
||||
const chatSession = sessions.find((session) => session.type === "order" && session.orderId === id)
|
||||
const statusSteps =
|
||||
order.status === "disputed"
|
||||
? disputedStatusSteps
|
||||
|
||||
Reference in New Issue
Block a user