refactor(api): add adapter layer for order/chat/review/dispute writes
This commit is contained in:
@@ -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("")
|
||||
}}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user