Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): keep the QR modal off a linked session, and Escape off the room
Yudhi Armyndharis7d72950dd29d
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 601bf1572..563dc9866 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -40,6 +40,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0- An ingress route whose manifest carries a non-string ack body, status or header is answered rather than failing with `500`; a manifest is third-party JSON and the loader does not type-check every leaf.- Uploading a zip whose trailer parses but whose directory does not answers `400`, not `500`.- A `socks5://` or `socks4://` proxy at an IPv6 literal connects: the brackets `URL` keeps were going on the wire as part of a hostname.+- Starting a session that turns out to be linked already no longer opens a QR modal over it, which then polled for a code that could never arrive. The decision now reads the list the dashboard re-reads after the start, not the state it held before it.+- Escape dismisses the Chats emoji picker instead of closing the whole conversation behind it.- A click on a WhatsApp Business prompt quotes the prompt in the stored reply, so the dashboard renders the question above the answer instead of an empty quote box.- A template prompt that numbers only some of its buttons no longer answers the bot with an index belonging to a different button: a template that carries its own numbering is answered with it, and one that carries none is answered by position.- A proxy password no longer reaches the log. A failed SOCKS connect carries the whole proxy config as the error's only property, and `BAILEYS_LOG_LEVEL=debug` wrote it to stdout verbatim.diff --git a/dashboard/src/components/chats/ChatComposer.tsx b/dashboard/src/components/chats/ChatComposer.tsxindex 7368119ba..b7487f80b 100644--- a/dashboard/src/components/chats/ChatComposer.tsx+++ b/dashboard/src/components/chats/ChatComposer.tsx@@ -277,7 +277,17 @@ function ChatComposer({{/* Popular emojis panel */}{showEmojiPicker && (- <div className="chats-emoji-picker">+ // role="menu" is what the page's Escape handler skips, and it owes that handler the+ // behaviour the skip assumes: Escape dismisses the picker rather than the conversation.+ <div+ className="chats-emoji-picker"+ role="menu"+ onKeyDown={event => {+ if (event.key !== 'Escape') return;+ event.preventDefault();+ setShowEmojiPicker(false);+ }}+ ><div className="emoji-grid">{popularEmojis.map(emoji => (<button key={emoji} type="button" className="emoji-btn" onClick={() => handleEmojiClick(emoji)}>diff --git a/dashboard/src/pages/Chats.test.ts b/dashboard/src/pages/Chats.test.tsindex 51d15eae3..5c54930bc 100644--- a/dashboard/src/pages/Chats.test.ts+++ b/dashboard/src/pages/Chats.test.ts@@ -504,6 +504,34 @@ test('a typed draft survives closing and reopening the room', async () => {assert.equal(input.value, 'draft survives');});+test('Escape dismisses the emoji picker instead of the conversation behind it', async () => {+ const { screen, fireEvent, within, waitFor } = rtl;+ resetFetchCalls();+ const { container } = renderChats();++ await screen.findByText('Main (15551234567)');+ fireEvent.click(await screen.findByText('Alice'));+ await within(container.querySelector('.room-messages') as HTMLElement).findByText('hello from alice');++ fireEvent.click(screen.getByTitle('Pick emoji'));+ const picker = await waitFor(() => {+ const found = container.querySelector('.chats-emoji-picker');+ assert.ok(found, 'the emoji picker did not open');+ return found as HTMLElement;+ });++ // The page-level handler listens on document and skips anything with role="menu", so an Escape it+ // sees while the picker is open must leave the conversation alone.+ fireEvent.keyDown(document, { key: 'Escape' });+ assert.ok(screen.queryByRole('button', { name: 'Back' }), 'Escape closed the room while the picker owned it');+ assert.ok(container.querySelector('.chats-emoji-picker'), 'the picker closed on a document-level Escape');++ // And the picker owes that skip the behaviour it assumes: Escape on the picker dismisses it.+ fireEvent.keyDown(picker, { key: 'Escape' });+ await waitFor(() => assert.equal(container.querySelector('.chats-emoji-picker'), null, 'the picker stayed open'));+ assert.ok(screen.queryByRole('button', { name: 'Back' }), 'dismissing the picker also closed the room');+});+test('Escape closes the open room, and is left alone while a dialog owns it', async () => {const { screen, fireEvent, within, waitFor } = rtl;resetFetchCalls();diff --git a/dashboard/src/pages/Sessions.test.ts b/dashboard/src/pages/Sessions.test.tsindex 55b51fe68..62aa368f1 100644--- a/dashboard/src/pages/Sessions.test.ts+++ b/dashboard/src/pages/Sessions.test.ts@@ -546,6 +546,32 @@ test('a start that answers with its engine up opens the QR modal', async () => {}});+// A start of a session that was already linked elsewhere comes back `ready`. The modal's own guard+// reads the sessions state of the render that began the start, which predates both the answer and the+// re-read, so the decision has to be taken from the re-read itself.+test('a start whose re-read shows the session ready opens no QR modal', async () => {+ const { screen, fireEvent, within, waitFor } = rtl;+ resetFetchCalls();+ startResult = {+ answer: { status: 'initializing', engineLoaded: true },+ leaves: { status: 'ready', engineLoaded: true },+ };+ SESSIONS.push({ ...SESSION_QR, id: 'sess-ready-1', name: 'already-linked', status: 'created', engineLoaded: false });+ try {+ renderSessions();++ const card = (await screen.findByText('already-linked')).closest('.session-card') as HTMLElement;+ fireEvent.click(within(card).getByRole('button', { name: 'Start' }));+ await waitFor(() => assert.ok(findFetchCall('POST', '/api/sessions/sess-ready-1/start')));+ // The re-read lands as this card turning Connected, which is also when the handler has decided+ // about the modal; the Start button is gone by then, so it cannot be the settle signal here.+ await waitFor(() => assert.ok(within(card).queryByText('Connected')));+ assert.ok(!screen.queryByRole('dialog'), 'a QR modal opened over a session that came back ready');+ } finally {+ SESSIONS.pop();+ }+});+// A start can answer 200 with an engine that is gone by the time the list is read back: a stop that landed// while it ran retires it, and an engine can fail right after answering. The re-read decides, not the// answer, since a QR modal over that session could only spin.diff --git a/dashboard/src/pages/Sessions.tsx b/dashboard/src/pages/Sessions.tsxindex d208a97ef..dcb8a4709 100644--- a/dashboard/src/pages/Sessions.tsx+++ b/dashboard/src/pages/Sessions.tsx@@ -340,6 +340,11 @@ export function Sessions() {// retires the start, and an engine can fail right after answering. Skip the modal when the re-read// shows the session without one. A failed re-read gives no answer, so the start's success decides.const row = (await fetchSessions()).find(s => s.id === id);+ // A session that came back already linked has nothing to scan. Decided from the re-read rather+ // than left to handleShowQR's own guard, which reads the sessions state this render still+ // holds: that state predates both the start response and the re-read, so it would let the+ // modal open over a connected session and then poll for a QR that can never arrive.+ if (row?.status === 'ready') return;if (!row || isSessionStarted(row)) handleShowQR(id);} catch (err) {console.error('Failed to start:', err);