From da4e864ab7ed44aba18f312b9bb6bf56c19eca85 Mon Sep 17 00:00:00 2001 From: Nuwan Date: Fri, 6 Feb 2026 15:45:06 +0530 Subject: [PATCH] fix(15): correct API response field name (chats not messages) The chat history API returns { chats: [...], next: ... } but the fetchChatHistory.fulfilled handler was expecting { messages: [...] }. This caused a TypeError when opening the chat window because `messages` was undefined. Fixed: - sessionChatSlice.js: Extract `chats` from payload, default to [] - Updated all test payloads to use `chats` field name Co-Authored-By: Claude Opus 4.5 --- .../store/features/__tests__/sessionChatSlice.test.js | 10 +++++----- jam-ui/src/store/features/sessionChatSlice.js | 4 +++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/jam-ui/src/store/features/__tests__/sessionChatSlice.test.js b/jam-ui/src/store/features/__tests__/sessionChatSlice.test.js index 5da91d6dc..001c3c84d 100644 --- a/jam-ui/src/store/features/__tests__/sessionChatSlice.test.js +++ b/jam-ui/src/store/features/__tests__/sessionChatSlice.test.js @@ -537,7 +537,7 @@ describe('fetchChatHistory async thunk', () => { meta: { arg: { channel: 'session-abc' } }, payload: { channel: 'session-abc', - messages: [ + chats: [ { id: 'msg-1', message: 'Hello', sender_id: 'user-1', created_at: '2026-01-26T12:00:00Z' } ], next: 20 @@ -576,7 +576,7 @@ describe('fetchChatHistory async thunk', () => { meta: { arg: { channel: 'session-abc' } }, payload: { channel: 'session-abc', - messages: [ + chats: [ { id: 'msg-1', user_id: 'user-1', user: { name: 'User' }, message: 'Hello', created_at: '2026-01-26T12:00:00Z', channel: 'session' }, // Duplicate { id: 'msg-2', user_id: 'user-2', user: { name: 'User2' }, message: 'World', created_at: '2026-01-26T12:01:00Z', channel: 'session' } // New ], @@ -609,7 +609,7 @@ describe('fetchChatHistory async thunk', () => { meta: { arg: { channel: 'session-abc', before: 3 } }, payload: { channel: 'session-abc', - messages: [ + chats: [ { id: 'msg-1', message: 'Oldest', createdAt: '2026-01-26T12:00:00Z' }, { id: 'msg-2', message: 'Middle', createdAt: '2026-01-26T12:01:00Z' } ], @@ -648,7 +648,7 @@ describe('fetchChatHistory async thunk', () => { meta: { arg: { channel: 'session-abc' } }, payload: { channel: 'session-abc', - messages: [ + chats: [ { id: 'msg-1', message: 'Hello', createdAt: '2026-01-26T12:00:00Z' } ], next: null @@ -674,7 +674,7 @@ describe('fetchChatHistory async thunk', () => { meta: { arg: { channel: 'session-abc' } }, payload: { channel: 'session-abc', - messages: [ + chats: [ { id: 'msg-1', user_id: 'user-1', diff --git a/jam-ui/src/store/features/sessionChatSlice.js b/jam-ui/src/store/features/sessionChatSlice.js index 6e9e2a40c..cfc6d911a 100644 --- a/jam-ui/src/store/features/sessionChatSlice.js +++ b/jam-ui/src/store/features/sessionChatSlice.js @@ -306,7 +306,9 @@ const sessionChatSlice = createSlice({ // fetchChatHistory fulfilled .addCase(fetchChatHistory.fulfilled, (state, action) => { const channel = action.meta.arg.channel; - const { messages, next } = action.payload; + // API returns { chats: [...], next: ... } + const { chats, next } = action.payload; + const messages = chats || []; // Initialize channel if not exists if (!state.messagesByChannel[channel]) {