feat(disputes): migrate disputes and reviews to backend API
This commit is contained in:
@@ -4,15 +4,14 @@ 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 { getOrderById } from "@/lib/api"
|
||||
import { getOrderById, listReviewsByOrder } from "@/lib/api"
|
||||
import { ORDER_ACCEPT_TIMEOUT_MS, ORDER_CLOSE_TIMEOUT_MS } from "@/lib/config/demo-timers"
|
||||
import { statusLabels } from "@/lib/constants"
|
||||
import type { OrderStatus } from "@/lib/types"
|
||||
import { useChatStore } from "@/store/chat"
|
||||
import { useReviewStore } from "@/store/reviews"
|
||||
import { ArrowLeft, CheckCircle, Clock, Star } from "lucide-react"
|
||||
import Link from "next/link"
|
||||
import { use, useEffect, useMemo, useState } from "react"
|
||||
import { use, useEffect, useState } from "react"
|
||||
|
||||
const normalStatusSteps: OrderStatus[] = [
|
||||
"pending_payment",
|
||||
@@ -36,12 +35,7 @@ const cancelledStatusSteps: OrderStatus[] = ["pending_payment", "pending_accept"
|
||||
export default function OrderDetailPage({ params }: { params: Promise<{ id: string }> }) {
|
||||
const { id } = use(params)
|
||||
const sessions = useChatStore((state) => state.sessions)
|
||||
const allReviews = useReviewStore((state) => state.reviews)
|
||||
// Filtering is deferred to useMemo after reading the raw store array.
|
||||
// Zustand v5 compares selector outputs by reference stability.
|
||||
// Returning a fresh filtered array from the selector can re-trigger updates
|
||||
// and loop under useSyncExternalStore (pmndrs/zustand#1936, #3155).
|
||||
const reviews = useMemo(() => allReviews.filter((item) => item.orderId === id), [allReviews, id])
|
||||
const [reviews, setReviews] = useState<Awaited<ReturnType<typeof listReviewsByOrder>>>([])
|
||||
const [order, setOrder] = useState<Awaited<ReturnType<typeof getOrderById>> | undefined>(
|
||||
undefined,
|
||||
)
|
||||
@@ -70,6 +64,25 @@ export default function OrderDetailPage({ params }: { params: Promise<{ id: stri
|
||||
}
|
||||
}, [id])
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false
|
||||
|
||||
;(async () => {
|
||||
try {
|
||||
const reviews = await Promise.resolve(listReviewsByOrder(id))
|
||||
if (cancelled) return
|
||||
setReviews(reviews)
|
||||
} catch {
|
||||
if (cancelled) return
|
||||
setReviews([])
|
||||
}
|
||||
})()
|
||||
|
||||
return () => {
|
||||
cancelled = true
|
||||
}
|
||||
}, [id])
|
||||
|
||||
useEffect(() => {
|
||||
if (!order) return
|
||||
if (order.status !== "pending_accept" && order.status !== "pending_close") return
|
||||
|
||||
Reference in New Issue
Block a user