feat(chat): migrate chat to backend API
This commit is contained in:
@@ -4,7 +4,7 @@ import { Badge } from "@/components/ui/badge"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"
|
||||
import { listOrders } from "@/lib/api"
|
||||
import { listChatSessions, listOrders } from "@/lib/api"
|
||||
import { statusLabels } from "@/lib/constants"
|
||||
import {
|
||||
isActiveOrder,
|
||||
@@ -16,7 +16,6 @@ import { resolveOwnerShop } from "@/lib/domain/resolve-current-shop"
|
||||
import type { OrderStatus, UserRole } from "@/lib/types"
|
||||
import { cn } from "@/lib/utils"
|
||||
import { useAuthStore } from "@/store/auth"
|
||||
import { useChatStore } from "@/store/chat"
|
||||
import { useShopStore } from "@/store/shops"
|
||||
import { Clock, MessageSquare, RefreshCw } from "lucide-react"
|
||||
import Link from "next/link"
|
||||
@@ -83,7 +82,7 @@ function OrderListContent({
|
||||
}) {
|
||||
const [tab, setTab] = useState<TabFilter | "pending">("all")
|
||||
const [orders, setOrders] = useState<Awaited<ReturnType<typeof listOrders>>>([])
|
||||
const sessions = useChatStore((state) => state.sessions)
|
||||
const [sessions, setSessions] = useState<Awaited<ReturnType<typeof listChatSessions>>>([])
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false
|
||||
@@ -104,6 +103,25 @@ function OrderListContent({
|
||||
}
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false
|
||||
|
||||
;(async () => {
|
||||
try {
|
||||
const items = await Promise.resolve(listChatSessions())
|
||||
if (cancelled) return
|
||||
setSessions(items)
|
||||
} catch {
|
||||
if (cancelled) return
|
||||
setSessions([])
|
||||
}
|
||||
})()
|
||||
|
||||
return () => {
|
||||
cancelled = true
|
||||
}
|
||||
}, [])
|
||||
|
||||
const tabs =
|
||||
currentRole === "consumer" ? consumerTabs : currentRole === "player" ? playerTabs : ownerTabs
|
||||
|
||||
|
||||
Reference in New Issue
Block a user