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 {
|
||||
const data = await chatApi.listConversations()
|
||||
setConversations(data)
|
||||
if (data.length > 0 && !selectedConversation) {
|
||||
setSelectedConversation(data[0])
|
||||
// Guard against null/undefined response
|
||||
const safeData = data || []
|
||||
setConversations(safeData)
|
||||
if (safeData.length > 0 && !selectedConversation) {
|
||||
setSelectedConversation(safeData[0])
|
||||
}
|
||||
setLoading(false)
|
||||
setError(null)
|
||||
|
|
@ -129,7 +131,7 @@ export default function AdminMessagesPage() {
|
|||
}
|
||||
}, [selectedConversation, serviceConfigured])
|
||||
|
||||
const filteredConversations = conversations.filter((conv) =>
|
||||
const filteredConversations = (conversations || []).filter((conv) =>
|
||||
(conv.participantName || "Unknown").toLowerCase().includes(searchTerm.toLowerCase()),
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue