Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): show the placeholder while the webhook read is pending
Yudhi Armyndharis3b279f6bf64d
diff --git a/dashboard/src/pages/Dashboard.test.ts b/dashboard/src/pages/Dashboard.test.tsindex c328bd4d4..d4936a955 100644--- a/dashboard/src/pages/Dashboard.test.ts+++ b/dashboard/src/pages/Dashboard.test.ts@@ -16,6 +16,7 @@ let webhookList: unknown[] = [];let sessionList: unknown[] = [];let stopStatus = 200;let sessionsStatus = 200;+let holdWebhooks = false;const requested: string[] = [];function jsonResponse(data: unknown, status = 200): Response {@@ -49,6 +50,7 @@ function installFetchStub(): void {);}if (path === '/api/webhooks') {+ if (holdWebhooks) return new Promise<Response>(() => {});return webhooksStatus === 200? Promise.resolve(jsonResponse(webhookList)): Promise.resolve(jsonResponse({ message: 'Insufficient permissions. Required: operator' }, webhooksStatus));@@ -93,6 +95,7 @@ afterEach(() => {sessionList = [];stopStatus = 200;sessionsStatus = 200;+ holdWebhooks = false;requested.length = 0;window.sessionStorage.setItem('openwa_user_role', 'viewer');});@@ -146,7 +149,18 @@ test('a successful empty webhook read still counts zero', async () => {window.sessionStorage.setItem('openwa_user_role', 'operator');renderDashboard();await rtl.screen.findByText('Webhooks Configured');- await rtl.waitFor(() => assert.equal(statValue('Webhooks Configured'), '0'));+ await rtl.waitFor(() => assert.equal(queryClient!.getQueryState(['webhooks'])?.status, 'success'));+ assert.equal(statValue('Webhooks Configured'), '0');+});++test('a webhook read still in flight shows the placeholder, not zero webhooks', async () => {+ holdWebhooks = true;+ window.sessionStorage.setItem('openwa_user_role', 'operator');+ renderDashboard();+ await rtl.screen.findByText('Webhooks Configured');+ await rtl.waitFor(() => assert.ok(requested.includes('/api/webhooks')));+ assert.equal(statValue('Webhooks Configured'), statValue('Messages Today'));+ assert.notEqual(statValue('Webhooks Configured'), '0');});test('a read-only key is offered no Disconnect', async () => {diff --git a/dashboard/src/pages/Dashboard.tsx b/dashboard/src/pages/Dashboard.tsxindex 8e99cf275..4b3fba8ed 100644--- a/dashboard/src/pages/Dashboard.tsx+++ b/dashboard/src/pages/Dashboard.tsx@@ -37,7 +37,7 @@ export function Dashboard() {// GET /webhooks is OPERATOR-only and /stats/overview ADMIN-only. A key without the role is not sent// them, since the gateway audits every refusal as a failed authentication; their cards show the// unavailable placeholder.- const { data: webhooks, isError: webhooksFailed } = useWebhooksQuery(canWrite);+ const { data: webhooks } = useWebhooksQuery(canWrite);const { data: overview } = useStatsOverviewQuery(isAdmin);const stopMutation = useStopSessionMutation();const unavailable = '—';@@ -51,9 +51,9 @@ export function Dashboard() {? sessionsError.message: t('dashboard.loadError'): null;- // A viewer is not sent the webhook read, and a failed read is not zero webhooks either.+ // A viewer is not sent the webhook read, and a pending or failed read is not zero webhooks either.// A failed background refetch keeps the cached list, which still counts.- const webhookCount = !canWrite || (webhooksFailed && !webhooks) ? unavailable : (webhooks ?? []).length;+ const webhookCount = !canWrite || !webhooks ? unavailable : webhooks.length;const handleDisconnect = async (id: string) => {try {