refactor(api): add adapter layer for order/chat/review/dispute writes

This commit is contained in:
zetaloop
2026-02-23 11:04:16 +08:00
parent 1dfcd3927d
commit 8e62b15403
10 changed files with 258 additions and 98 deletions
+22 -24
View File
@@ -9,6 +9,7 @@ import { Badge } from "@/components/ui/badge"
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { ScrollArea } from "@/components/ui/scroll-area"
import { sendImageMessage, sendTextMessage } from "@/lib/api/chat"
import { cn } from "@/lib/utils"
import { useAuthStore } from "@/store/auth"
import { useChatStore } from "@/store/chat"
@@ -25,8 +26,6 @@ export default function ChatDetailPage({ params }: { params: Promise<{ id: strin
() => allMessages.filter((item) => item.sessionId === id),
[allMessages, id],
)
const sendTextMessage = useChatStore((state) => state.sendTextMessage)
const sendImageMessage = useChatStore((state) => state.sendImageMessage)
const [input, setInput] = useState("")
const imageInputRef = useRef<HTMLInputElement>(null)
const { user } = useAuthStore()
@@ -39,8 +38,25 @@ export default function ChatDetailPage({ params }: { params: Promise<{ id: strin
)
}
const userId = user?.id ?? session.participants[0].id
const other = session.participants.find((p) => p.id !== userId) ?? session.participants[1]
if (!user?.id) {
return (
<div className="container mx-auto py-8 px-4 text-center text-muted-foreground">
</div>
)
}
const userId = user.id
const isParticipant = session.participants.some((participant) => participant.id === userId)
if (!isParticipant) {
return (
<div className="container mx-auto py-8 px-4 text-center text-muted-foreground">
</div>
)
}
const other = session.participants.find((p) => p.id !== userId) ?? session.participants[0]
return (
<div className="flex flex-col h-[calc(100vh-3.5rem)]">
@@ -130,16 +146,7 @@ export default function ChatDetailPage({ params }: { params: Promise<{ id: strin
onChange={(event) => {
const file = event.target.files?.[0]
if (!file) return
const sender = session.participants.find((participant) => participant.id === userId)
sendImageMessage(
session.id,
{
id: userId,
name: sender?.name ?? user?.nickname ?? "",
avatar: sender?.avatar ?? user?.avatar ?? "",
},
URL.createObjectURL(file),
)
sendImageMessage(session.id, URL.createObjectURL(file))
event.target.value = ""
}}
/>
@@ -150,16 +157,7 @@ export default function ChatDetailPage({ params }: { params: Promise<{ id: strin
const text = input.trim()
if (!text) return
const sender = session.participants.find((participant) => participant.id === userId)
sendTextMessage(
session.id,
{
id: userId,
name: sender?.name ?? user?.nickname ?? "",
avatar: sender?.avatar ?? user?.avatar ?? "",
},
text,
)
sendTextMessage(session.id, text)
setInput("")
}}
>