Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): do not call a failed chat list empty
Yudhi Armyndharisf30888826cba
diff --git a/dashboard/src/pages/Chats.test.ts b/dashboard/src/pages/Chats.test.tsindex b45151af7..b3b797cfb 100644--- a/dashboard/src/pages/Chats.test.ts+++ b/dashboard/src/pages/Chats.test.ts@@ -3656,3 +3656,19 @@ test('a failed session list says so and offers the read again, not the no-sessioawait screen.findByText('Alice');assert.equal(screen.queryByRole('alert') === null, true);});++// A chat list that could not be read is not an empty one: the sidebar alone would read "No chats".+test('a failed chat list says so and offers the read again, then clears once a read lands', async () => {+ const { screen, fireEvent, within } = rtl;+ chatsResponder = () => Promise.resolve(jsonResponse({ message: 'gateway timeout' }, 504));+ renderChats();++ const alert = await screen.findByRole('alert');+ assert.match(alert.textContent ?? '', /Failed to load chats/);+ assert.match(alert.textContent ?? '', /gateway timeout/);++ chatsResponder = null;+ fireEvent.click(within(alert).getByRole('button', { name: 'Retry' }));+ await screen.findByText('Alice');+ assert.equal(screen.queryByRole('alert') === null, true, 'the failure stayed after the list was read');+});diff --git a/dashboard/src/pages/Chats.tsx b/dashboard/src/pages/Chats.tsxindex e031ab106..f575c5bee 100644--- a/dashboard/src/pages/Chats.tsx+++ b/dashboard/src/pages/Chats.tsx@@ -179,6 +179,9 @@ export function Chats() {// Chats listconst [chats, setChats] = useState<Chat[]>([]);const [loadingChats, setLoadingChats] = useState<boolean>(false);+ // Why the list on screen is not the session's: its last foreground read failed. A list that could not be read+ // is told apart from one that is empty, which the sidebar alone would render the same way.+ const [chatsFailure, setChatsFailure] = useState<string | null>(null);const [searchQuery, setSearchQuery] = useState<string>('');const [chatFilter, setChatFilter] = useState<ChatListFilter>('all');@@ -452,10 +455,14 @@ export function Chats() {// so this session's list on screen is as fresh as this call's would have been.const overtaken = () => !controller.signal.aborted && sessionId === chatsSessionRef.current;try {- if (!background) setLoadingChats(true);+ if (!background) {+ setLoadingChats(true);+ setChatsFailure(null);+ }const data = await sessionApi.getChats(sessionId, controller.signal);if (stale()) return overtaken();chatsAppliedRef.current = request;+ setChatsFailure(null);// A live frame can move a row past the snapshot a background refetch was built from while it is// out. That row is kept, or its preview and unread badge would roll back until the next message.const moved = (id: string) => (liveRowsRef.current.get(id) ?? 0) >= request;@@ -492,7 +499,7 @@ export function Chats() {if (stale()) return overtaken();// A background refetch only refreshes summaries: keep the list it would have replaced.if (background) return false;- showLoadError('chats.errors.loadChats', err);+ setChatsFailure(err instanceof Error ? err.message : '');listedSessionRef.current = sessionId;setChats([]);return false;@@ -504,7 +511,7 @@ export function Chats() {if (!background && !controller.signal.aborted && sessionId === chatsSessionRef.current) setLoadingChats(false);}},- [showLoadError],+ [],);// A reload walks every page of the list, and each live event the sidebar cannot apply locally asks for@@ -1673,6 +1680,19 @@ export function Chats() {</div>)}+ {chatsFailure !== null && !loadingChats && (+ <div className="chats-reconnect-banner" role="alert">+ <AlertCircle size={16} />+ <span>+ {t('chats.errors.loadChats')}+ {chatsFailure && ` (${chatsFailure})`}+ </span>+ <button className="btn-secondary" onClick={() => void loadChats(selectedSessionId)}>+ {t('common.retry')}+ </button>+ </div>+ )}+{loadingSessions ? (<div className="chats-loading-container"><Loader2 className="animate-spin" size={32} />