Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): offer Disconnect wherever the session has an engine
Yudhi Armyndharisfe3592637d89
diff --git a/dashboard/src/pages/Dashboard.test.ts b/dashboard/src/pages/Dashboard.test.tsindex 4ea8a1d19..ea9fc14cd 100644--- a/dashboard/src/pages/Dashboard.test.ts+++ b/dashboard/src/pages/Dashboard.test.ts@@ -171,6 +171,23 @@ test('a failed stop is reported, not swallowed', async () => {);});+// Stop needs a live engine, which the gateway reports as engineLoaded: a status cannot tell a session+// reconnecting with its engine from a stopped one.+test('Disconnect is offered exactly where the gateway holds an engine', async () => {+ webhooksStatus = 200;+ window.sessionStorage.setItem('openwa_user_role', 'operator');+ sessionList = [{ ...READY_SESSION, status: 'disconnected', engineLoaded: true }];+ renderDashboard();+ await rtl.screen.findByRole('button', { name: 'Disconnect' });++ rtl.cleanup();+ queryClient?.clear();+ sessionList = [{ ...READY_SESSION, status: 'initializing', engineLoaded: false }];+ renderDashboard();+ await rtl.screen.findByText('Main');+ assert.ok(!rtl.screen.queryByRole('button', { name: 'Disconnect' }), 'a session with no engine offered Disconnect');+});+test('a failed background refetch of the sessions keeps the cached page', async () => {webhooksStatus = 200;sessionList = [READY_SESSION];diff --git a/dashboard/src/pages/Dashboard.tsx b/dashboard/src/pages/Dashboard.tsxindex 5e79c7449..5ea5e3003 100644--- a/dashboard/src/pages/Dashboard.tsx+++ b/dashboard/src/pages/Dashboard.tsx@@ -14,6 +14,7 @@ import {useStatsOverviewQuery,} from '../hooks/queries';import { PageHeader } from '../components/PageHeader';+import { isSessionStarted } from '../utils/sessionActions';import './Dashboard.css';// recharts is heavy (~116 kB gzip); load the analytics section on demand so it never bloats the@@ -179,7 +180,7 @@ export function Dashboard() {{t('dashboard.view')}</button>{/* Stopping a session is an operator write; a read-only key would only collect a 403. */}- {canWrite && ['ready', 'initializing', 'qr_ready'].includes(session.status) && (+ {canWrite && isSessionStarted(session) && (<button className="btn-sm danger" onClick={() => handleDisconnect(session.id)}>{t('dashboard.disconnect')}</button>