Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): keep a pending auto-reject toggle off another session
Yudhi Armyndharis92d0a44d62a8
diff --git a/dashboard/src/pages/Sessions.test.ts b/dashboard/src/pages/Sessions.test.tsindex bd1838eec..c9b877da9 100644--- a/dashboard/src/pages/Sessions.test.ts+++ b/dashboard/src/pages/Sessions.test.ts@@ -1654,12 +1654,59 @@ test('a toggle answer that lands after its modal closed does not change anotherconst other = await openDetailFor('stale-engine');assert.equal(other.checked, false);+ assert.equal(other.disabled, false, 'the pending toggle of the closed modal locked this one');release();await waitFor(() => assert.equal(sessionConfig.autoRejectCalls, true));await new Promise(resolve => setTimeout(resolve, 50));assert.equal((screen.getByRole('checkbox') as HTMLInputElement).checked, false);});+test('a session reopened while its toggle saves keeps the toggle locked until that save answers', async () => {+ const { screen, within, fireEvent, waitFor } = rtl;+ resetFetchCalls();+ sessionConfig = { autoRejectCalls: false, maxReconnectAttempts: null, reconnectBaseDelay: 5000 };+ configPatchFails = false;+ let release!: () => void;+ configPatchGate = new Promise<void>(resolve => (release = resolve));+ renderSessions();++ fireEvent.click(await openDetailFor('new-device'));+ await waitFor(() => assert.ok(fetchCalls.some(c => c.method === 'PATCH')));+ fireEvent.click(within(screen.getByRole('dialog')).getAllByRole('button', { name: 'Close' })[0]);+ await waitFor(() => assert.equal(screen.queryByRole('dialog') === null, true));++ const reopened = await openDetailFor('new-device');+ assert.equal(reopened.disabled, true, 'a second write could overlap the one still pending');+ release();+ await waitFor(() => assert.equal((screen.getByRole('checkbox') as HTMLInputElement).disabled, false));+});++test("one session's toggle answer does not unlock another session's pending toggle", async () => {+ const { screen, within, fireEvent, waitFor } = rtl;+ resetFetchCalls();+ sessionConfig = { autoRejectCalls: false, maxReconnectAttempts: null, reconnectBaseDelay: 5000 };+ configPatchFails = false;+ let releaseFirst!: () => void;+ configPatchGate = new Promise<void>(resolve => (releaseFirst = resolve));+ renderSessions();++ fireEvent.click(await openDetailFor('new-device'));+ await waitFor(() => assert.equal(fetchCalls.filter(c => c.method === 'PATCH').length, 1));+ fireEvent.click(within(screen.getByRole('dialog')).getAllByRole('button', { name: 'Close' })[0]);+ await waitFor(() => assert.equal(screen.queryByRole('dialog') === null, true));++ let releaseSecond!: () => void;+ configPatchGate = new Promise<void>(resolve => (releaseSecond = resolve));+ fireEvent.click(await openDetailFor('stale-engine'));+ await waitFor(() => assert.equal(fetchCalls.filter(c => c.method === 'PATCH').length, 2));+ releaseFirst();+ await waitFor(() => assert.equal(sessionConfig.autoRejectCalls, true));+ await new Promise(resolve => setTimeout(resolve, 50));+ assert.equal((screen.getByRole('checkbox') as HTMLInputElement).disabled, true);+ releaseSecond();+ await waitFor(() => assert.equal((screen.getByRole('checkbox') as HTMLInputElement).disabled, false));+});+test('a failed toggle that lands after its modal closed does not revert another session', async () => {const { screen, within, fireEvent, waitFor } = rtl;resetFetchCalls();@@ -1679,6 +1726,7 @@ test('a failed toggle that lands after its modal closed does not revert anothersessionConfig = { autoRejectCalls: true, maxReconnectAttempts: null, reconnectBaseDelay: 5000 };const other = await openDetailFor('stale-engine');assert.equal(other.checked, true);+ assert.equal(other.disabled, false, 'the pending toggle of the closed modal locked this one');release();await screen.findByRole('alert');assert.equal((screen.getByRole('checkbox') as HTMLInputElement).checked, true);diff --git a/dashboard/src/pages/Sessions.tsx b/dashboard/src/pages/Sessions.tsxindex c0af4cfbc..43bf2f3fc 100644--- a/dashboard/src/pages/Sessions.tsx+++ b/dashboard/src/pages/Sessions.tsx@@ -94,7 +94,9 @@ export function Sessions() {// Session config is not on the list payload — the API never returns the config column, so it is// fetched per session when the detail modal opens rather than N times to render the list.const [sessionConfig, setSessionConfig] = useState<SessionConfig | null>(null);- const [savingConfig, setSavingConfig] = useState(false);+ // Ids of sessions with an auto-reject save in flight. Per session, because Close stays enabled while+ // one saves: the modal reopened for that session must stay locked, and another session's must not.+ const [savingConfigIds, setSavingConfigIds] = useState<ReadonlySet<string>>(new Set());const [proxySession, setProxySession] = useState<Session | null>(null);const [proxyInfo, setProxyInfo] = useState<SessionProxy | null>(null);const [proxyLoading, setProxyLoading] = useState(false);@@ -456,7 +458,7 @@ export function Sessions() {const id = selectedSessionId;const previous = sessionConfig;setSessionConfig({ ...sessionConfig, autoRejectCalls: next });- setSavingConfig(true);+ setSavingConfigIds(current => new Set(current).add(id));try {const saved = await sessionApi.updateConfig(id, { autoRejectCalls: next });if (configSessionId.current === id) setSessionConfig(saved);@@ -466,7 +468,11 @@ export function Sessions() {if (configSessionId.current === id) setSessionConfig(previous);toast.error(t('sessions.details.autoRejectCalls'), err instanceof Error ? err.message : t('common.unknownError'));} finally {- setSavingConfig(false);+ setSavingConfigIds(current => {+ const next = new Set(current);+ next.delete(id);+ return next;+ });}};@@ -979,7 +985,7 @@ export function Sessions() {type="checkbox"aria-labelledby="auto-reject-calls-label"checked={sessionConfig.autoRejectCalls}- disabled={!canWrite || savingConfig}+ disabled={!canWrite || savingConfigIds.has(selectedSession.id)}onChange={e => void handleAutoRejectToggle(e.target.checked)}/><span className="toggle-slider"></span>