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:
Tiago Yamamoto 2025-12-26 16:17:34 -03:00
parent 786ef42d8a
commit 87aa558a61

View file

@ -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()),
)