fix: add null guards to messages page
- Guard against null response from chatApi.listConversations() - Use fallback empty array for conversations state - Prevents 'Cannot read properties of null' errors
This commit is contained in:
parent
786ef42d8a
commit
87aa558a61
1 changed files with 6 additions and 4 deletions
|
|
@ -50,9 +50,11 @@ export default function AdminMessagesPage() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const data = await chatApi.listConversations()
|
const data = await chatApi.listConversations()
|
||||||
setConversations(data)
|
// Guard against null/undefined response
|
||||||
if (data.length > 0 && !selectedConversation) {
|
const safeData = data || []
|
||||||
setSelectedConversation(data[0])
|
setConversations(safeData)
|
||||||
|
if (safeData.length > 0 && !selectedConversation) {
|
||||||
|
setSelectedConversation(safeData[0])
|
||||||
}
|
}
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
setError(null)
|
setError(null)
|
||||||
|
|
@ -129,7 +131,7 @@ export default function AdminMessagesPage() {
|
||||||
}
|
}
|
||||||
}, [selectedConversation, serviceConfigured])
|
}, [selectedConversation, serviceConfigured])
|
||||||
|
|
||||||
const filteredConversations = conversations.filter((conv) =>
|
const filteredConversations = (conversations || []).filter((conv) =>
|
||||||
(conv.participantName || "Unknown").toLowerCase().includes(searchTerm.toLowerCase()),
|
(conv.participantName || "Unknown").toLowerCase().includes(searchTerm.toLowerCase()),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue