Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): show why the webhook list failed instead of an empty list

Yudhi Armyndharisa32aeebeab47
diff --git a/dashboard/src/i18n/locales/ar.json b/dashboard/src/i18n/locales/ar.json
index efc469821..1ff3414a5 100644
--- a/dashboard/src/i18n/locales/ar.json
+++ b/dashboard/src/i18n/locales/ar.json
@@ -481,7 +481,10 @@
},
"empty": {
"title": "لا توجد ويب هوك مُهيّأة",
- "description": "أضف ويب هوك لتلقي إشعارات فورية بالأحداث"
+ "description": "أضف ويب هوك لتلقي إشعارات فورية بالأحداث",
+ "loadErrorTitle": "تعذر تحميل الويب هوك",
+ "forbiddenTitle": "لا يوجد وصول إلى الويب هوك",
+ "forbiddenDesc": "يتطلب الويب هوك مفتاح API بدور المشغل أو المسؤول."
},
"toasts": {
"created": "تم إنشاء الويب هوك بنجاح",
diff --git a/dashboard/src/i18n/locales/de.json b/dashboard/src/i18n/locales/de.json
index 0d9e69b40..de73c76fc 100644
--- a/dashboard/src/i18n/locales/de.json
+++ b/dashboard/src/i18n/locales/de.json
@@ -466,7 +466,10 @@
},
"empty": {
"title": "Keine Webhooks konfiguriert",
- "description": "Füge einen Webhook hinzu, um Ereignisbenachrichtigungen in Echtzeit zu erhalten"
+ "description": "Füge einen Webhook hinzu, um Ereignisbenachrichtigungen in Echtzeit zu erhalten",
+ "loadErrorTitle": "Webhooks konnten nicht geladen werden",
+ "forbiddenTitle": "Kein Zugriff auf Webhooks",
+ "forbiddenDesc": "Webhooks erfordern einen API-Schlüssel mit der Rolle Operator oder Admin."
},
"toasts": {
"created": "Webhook wurde erfolgreich erstellt",
diff --git a/dashboard/src/i18n/locales/en.json b/dashboard/src/i18n/locales/en.json
index 91df9d29d..170f22c55 100644
--- a/dashboard/src/i18n/locales/en.json
+++ b/dashboard/src/i18n/locales/en.json
@@ -466,7 +466,10 @@
},
"empty": {
"title": "No webhooks configured",
- "description": "Add a webhook to receive real-time event notifications"
+ "description": "Add a webhook to receive real-time event notifications",
+ "loadErrorTitle": "Could not load webhooks",
+ "forbiddenTitle": "No access to webhooks",
+ "forbiddenDesc": "Webhooks require an API key with the operator or admin role."
},
"toasts": {
"created": "Webhook created successfully",
diff --git a/dashboard/src/i18n/locales/es.json b/dashboard/src/i18n/locales/es.json
index ae7208da1..75b14246b 100644
--- a/dashboard/src/i18n/locales/es.json
+++ b/dashboard/src/i18n/locales/es.json
@@ -466,7 +466,10 @@
},
"empty": {
"title": "No hay webhooks configurados",
- "description": "Añade un webhook para recibir notificaciones de eventos en tiempo real"
+ "description": "Añade un webhook para recibir notificaciones de eventos en tiempo real",
+ "loadErrorTitle": "No se pudieron cargar los webhooks",
+ "forbiddenTitle": "Sin acceso a los webhooks",
+ "forbiddenDesc": "Los webhooks requieren una clave API con el rol de operador o administrador."
},
"toasts": {
"created": "Webhook creado correctamente",
diff --git a/dashboard/src/i18n/locales/fr.json b/dashboard/src/i18n/locales/fr.json
index 5764c83d4..74d53d2b9 100644
--- a/dashboard/src/i18n/locales/fr.json
+++ b/dashboard/src/i18n/locales/fr.json
@@ -466,7 +466,10 @@
},
"empty": {
"title": "Aucun webhook configuré",
- "description": "Ajoutez un webhook pour recevoir des notifications d'événements en temps réel"
+ "description": "Ajoutez un webhook pour recevoir des notifications d'événements en temps réel",
+ "loadErrorTitle": "Impossible de charger les webhooks",
+ "forbiddenTitle": "Aucun accès aux webhooks",
+ "forbiddenDesc": "Les webhooks nécessitent une clé API avec le rôle opérateur ou administrateur."
},
"toasts": {
"created": "Webhook créé avec succès",
diff --git a/dashboard/src/i18n/locales/he.json b/dashboard/src/i18n/locales/he.json
index 4c1886788..fcfd18288 100644
--- a/dashboard/src/i18n/locales/he.json
+++ b/dashboard/src/i18n/locales/he.json
@@ -475,7 +475,10 @@
},
"empty": {
"title": "לא הוגדרו Webhooks",
- "description": "יש להוסיף Webhook כדי לקבל התראות בזמן אמת"
+ "description": "יש להוסיף Webhook כדי לקבל התראות בזמן אמת",
+ "loadErrorTitle": "לא ניתן לטעון את ה-Webhooks",
+ "forbiddenTitle": "אין גישה ל-Webhooks",
+ "forbiddenDesc": "Webhooks דורשים מפתח API עם תפקיד מפעיל או מנהל."
},
"toasts": {
"created": "ה-Webhook נוצר בהצלחה",
diff --git a/dashboard/src/i18n/locales/it.json b/dashboard/src/i18n/locales/it.json
index 1c913b5d2..7636b0235 100644
--- a/dashboard/src/i18n/locales/it.json
+++ b/dashboard/src/i18n/locales/it.json
@@ -466,7 +466,10 @@
},
"empty": {
"title": "Nessun webhook configurato",
- "description": "Aggiungi un webhook per ricevere le notifiche degli eventi in tempo reale"
+ "description": "Aggiungi un webhook per ricevere le notifiche degli eventi in tempo reale",
+ "loadErrorTitle": "Impossibile caricare i webhook",
+ "forbiddenTitle": "Nessun accesso ai webhook",
+ "forbiddenDesc": "I webhook richiedono una chiave API con ruolo operatore o amministratore."
},
"toasts": {
"created": "Webhook creato con successo",
diff --git a/dashboard/src/i18n/locales/ko.json b/dashboard/src/i18n/locales/ko.json
index b33974b54..c83ac5e05 100644
--- a/dashboard/src/i18n/locales/ko.json
+++ b/dashboard/src/i18n/locales/ko.json
@@ -466,7 +466,10 @@
},
"empty": {
"title": "설정된 웹훅이 없습니다",
- "description": "실시간 이벤트 알림을 받으려면 웹훅을 추가하세요"
+ "description": "실시간 이벤트 알림을 받으려면 웹훅을 추가하세요",
+ "loadErrorTitle": "웹훅을 불러올 수 없습니다",
+ "forbiddenTitle": "웹훅에 접근할 수 없습니다",
+ "forbiddenDesc": "웹훅을 사용하려면 운영자 또는 관리자 역할의 API 키가 필요합니다."
},
"toasts": {
"created": "웹훅이 생성되었습니다",
diff --git a/dashboard/src/i18n/locales/pt-BR.json b/dashboard/src/i18n/locales/pt-BR.json
index 2deec1b0b..08588ae91 100644
--- a/dashboard/src/i18n/locales/pt-BR.json
+++ b/dashboard/src/i18n/locales/pt-BR.json
@@ -466,7 +466,10 @@
},
"empty": {
"title": "Nenhum webhook configurado",
- "description": "Adicione um webhook para receber notificações de eventos em tempo real"
+ "description": "Adicione um webhook para receber notificações de eventos em tempo real",
+ "loadErrorTitle": "Não foi possível carregar os webhooks",
+ "forbiddenTitle": "Sem acesso aos webhooks",
+ "forbiddenDesc": "Os webhooks exigem uma chave de API com a função de operador ou administrador."
},
"toasts": {
"created": "Webhook criado com sucesso",
diff --git a/dashboard/src/i18n/locales/te.json b/dashboard/src/i18n/locales/te.json
index 61133447e..c086c0ef7 100644
--- a/dashboard/src/i18n/locales/te.json
+++ b/dashboard/src/i18n/locales/te.json
@@ -466,7 +466,10 @@
},
"empty": {
"title": "ఎలాంటి వెబ్‌హుక్స్ కాన్ఫిగర్ చేయబడలేదు",
- "description": "నిజ-సమయ ఈవెంట్ నోటిఫికేషన్‌లను పొందడానికి ఒక వెబ్‌హుక్‌ను జోడించండి"
+ "description": "నిజ-సమయ ఈవెంట్ నోటిఫికేషన్‌లను పొందడానికి ఒక వెబ్‌హుక్‌ను జోడించండి",
+ "loadErrorTitle": "వెబ్‌హుక్స్‌ను లోడ్ చేయడం సాధ్యం కాలేదు",
+ "forbiddenTitle": "వెబ్‌హుక్స్‌కు యాక్సెస్ లేదు",
+ "forbiddenDesc": "వెబ్‌హుక్స్‌కు ఆపరేటర్ లేదా అడ్మిన్ పాత్ర ఉన్న API కీ అవసరం."
},
"toasts": {
"created": "వెబ్‌హుక్ విజయవంతంగా సృష్టించబడింది",
diff --git a/dashboard/src/i18n/locales/tr.json b/dashboard/src/i18n/locales/tr.json
index 75ab25b2c..c1ca21a4a 100644
--- a/dashboard/src/i18n/locales/tr.json
+++ b/dashboard/src/i18n/locales/tr.json
@@ -466,7 +466,10 @@
},
"empty": {
"title": "Yapılandırılmış webhook yok",
- "description": "Gerçek zamanlı olay bildirimleri almak için bir webhook ekleyin"
+ "description": "Gerçek zamanlı olay bildirimleri almak için bir webhook ekleyin",
+ "loadErrorTitle": "Webhook'lar yüklenemedi",
+ "forbiddenTitle": "Webhook'lara erişim yok",
+ "forbiddenDesc": "Webhook'lar, operatör veya yönetici rolüne sahip bir API anahtarı gerektirir."
},
"toasts": {
"created": "Webhook başarıyla oluşturuldu",
diff --git a/dashboard/src/i18n/locales/zh-CN.json b/dashboard/src/i18n/locales/zh-CN.json
index fd1fecff7..e30a3a8f4 100644
--- a/dashboard/src/i18n/locales/zh-CN.json
+++ b/dashboard/src/i18n/locales/zh-CN.json
@@ -466,7 +466,10 @@
},
"empty": {
"title": "尚未配置 Webhook",
- "description": "添加 Webhook 以接收实时事件通知"
+ "description": "添加 Webhook 以接收实时事件通知",
+ "loadErrorTitle": "无法加载 Webhook",
+ "forbiddenTitle": "无权访问 Webhook",
+ "forbiddenDesc": "Webhook 需要具有操作员或管理员角色的 API 密钥。"
},
"toasts": {
"created": "Webhook 创建成功",
diff --git a/dashboard/src/i18n/locales/zh-HK.json b/dashboard/src/i18n/locales/zh-HK.json
index 16a8a6ee1..3b3e35bd5 100644
--- a/dashboard/src/i18n/locales/zh-HK.json
+++ b/dashboard/src/i18n/locales/zh-HK.json
@@ -466,7 +466,10 @@
},
"empty": {
"title": "尚未設定 Webhook",
- "description": "新增 Webhook 以接收即時事件通知"
+ "description": "新增 Webhook 以接收即時事件通知",
+ "loadErrorTitle": "無法載入 Webhook",
+ "forbiddenTitle": "無權存取 Webhook",
+ "forbiddenDesc": "Webhook 需要具有操作員或管理員角色的 API 金鑰。"
},
"toasts": {
"created": "Webhook 建立成功",
diff --git a/dashboard/src/pages/Webhooks.test.ts b/dashboard/src/pages/Webhooks.test.ts
new file mode 100644
index 000000000..a125eb017
--- /dev/null
+++ b/dashboard/src/pages/Webhooks.test.ts
@@ -0,0 +1,101 @@
+// Render test for the Webhooks page under the bare `node --test` runner, on the Templates.test.ts
+// harness. GET /webhooks is OPERATOR-only, so a viewer key always gets 403 there; a failed read must
+// say so instead of rendering the "no webhooks configured" empty state.
+import '../test-helpers/register-hooks.ts';
+import { test, before, afterEach } from 'node:test';
+import assert from 'node:assert/strict';
+import { createElement } from 'react';
+import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
+
+let webhooksStatus = 200;
+let webhookList: unknown[] = [];
+
+function jsonResponse(data: unknown, status = 200): Response {
+ return new Response(JSON.stringify(data), { status, headers: { 'Content-Type': 'application/json' } });
+}
+
+function installFetchStub(): void {
+ globalThis.fetch = ((input: RequestInfo | URL): Promise<Response> => {
+ const url = typeof input === 'string' ? input : input instanceof URL ? input.href : input.url;
+ const path = url.replace(/^https?:\/\/[^/]+/, '');
+ if (path === '/api/sessions') return Promise.resolve(jsonResponse([]));
+ if (path === '/api/webhooks') {
+ if (webhooksStatus === 403) {
+ return Promise.resolve(jsonResponse({ message: 'Insufficient permissions. Required: operator' }, 403));
+ }
+ if (webhooksStatus !== 200) return Promise.resolve(jsonResponse({ message: 'database offline' }, 500));
+ return Promise.resolve(jsonResponse(webhookList));
+ }
+ return Promise.resolve(jsonResponse({ message: `unstubbed ${path}` }, 404));
+ }) as typeof fetch;
+}
+
+let rtl: typeof import('@testing-library/react');
+let Webhooks: (typeof import('./Webhooks.tsx'))['Webhooks'];
+let RoleProvider: (typeof import('../components/RoleProvider.tsx'))['RoleProvider'];
+let ToastProvider: (typeof import('../components/Toast.tsx'))['ToastProvider'];
+let queryClient: QueryClient | undefined;
+
+before(async () => {
+ const { installJsdomGlobals } = await import('../test-helpers/jsdom.ts');
+ await installJsdomGlobals();
+ installFetchStub();
+ window.localStorage.setItem('openwa_user_role', 'viewer');
+ const { i18nReady } = await import('../i18n/index.ts');
+ await i18nReady;
+ rtl = await import('@testing-library/react');
+ ({ RoleProvider } = await import('../components/RoleProvider.tsx'));
+ ({ ToastProvider } = await import('../components/Toast.tsx'));
+ ({ Webhooks } = await import('./Webhooks.tsx'));
+});
+
+afterEach(() => {
+ rtl.cleanup();
+ queryClient?.clear();
+ queryClient = undefined;
+ webhookList = [];
+});
+
+function renderWebhooks(): void {
+ queryClient = new QueryClient({ defaultOptions: { queries: { retry: false, gcTime: 1_000 } } });
+ rtl.render(
+ createElement(
+ QueryClientProvider,
+ { client: queryClient },
+ createElement(RoleProvider, null, createElement(ToastProvider, null, createElement(Webhooks))),
+ ),
+ );
+}
+
+test('a 403 on the webhook list shows a permission state, not an empty list', async () => {
+ webhooksStatus = 403;
+ renderWebhooks();
+ await rtl.screen.findByText('No access to webhooks');
+ assert.ok(!rtl.screen.queryByText('No webhooks configured'), 'a refused read claimed there are no webhooks');
+});
+
+test('any other failed read shows the error, not an empty list', async () => {
+ webhooksStatus = 500;
+ renderWebhooks();
+ await rtl.screen.findByText('Could not load webhooks');
+ rtl.screen.getByText('database offline');
+ assert.ok(!rtl.screen.queryByText('No webhooks configured'), 'a failed read claimed there are no webhooks');
+});
+
+test('a successful empty read still shows the empty state', async () => {
+ webhooksStatus = 200;
+ renderWebhooks();
+ await rtl.screen.findByText('No webhooks configured');
+});
+
+test('a failed refetch keeps the cached list and flags the error above it', async () => {
+ webhooksStatus = 200;
+ webhookList = [{ id: 'w1', sessionId: 'sess-1', url: 'https://example.test/hook', events: [], active: true }];
+ renderWebhooks();
+ await rtl.screen.findByText('https://example.test/hook');
+
+ webhooksStatus = 500;
+ await rtl.act(() => queryClient!.refetchQueries({ queryKey: ['webhooks'] }));
+ await rtl.screen.findByText('Failed to load data');
+ rtl.screen.getByText('https://example.test/hook');
+});
diff --git a/dashboard/src/pages/Webhooks.tsx b/dashboard/src/pages/Webhooks.tsx
index 6a9131b32..c1efcb4f2 100644
--- a/dashboard/src/pages/Webhooks.tsx
+++ b/dashboard/src/pages/Webhooks.tsx
@@ -119,7 +119,7 @@ export function Webhooks() {
const { t } = useTranslation();
useDocumentTitle(t('webhooks.title'));
const { canWrite } = useRole();
- const { data: webhooks = [], isLoading: loadingWebhooks, isError: webhooksError } = useWebhooksQuery();
+ const { data: webhooks = [], isLoading: loadingWebhooks, error: webhooksError } = useWebhooksQuery();
const { data: sessions = [] } = useSessionsQuery();
const loading = loadingWebhooks;
const createMutation = useCreateWebhookMutation();
@@ -285,7 +285,9 @@ export function Webhooks() {
}
/>
- {webhooksError && (
+ {/* With nothing cached the list area itself explains the failure; this banner covers a failed
+ background refetch that keeps the cached list on screen. */}
+ {webhooksError && webhooks.length > 0 && (
<div className="error-banner" role="alert">
<AlertCircle size={20} />
<span className="error-banner-text">{t('dashboard.loadError')}</span>
@@ -462,7 +464,24 @@ export function Webhooks() {
<div className="webhooks-content">
<div className="webhooks-list-container">
- {webhooks.length === 0 ? (
+ {webhooksError && webhooks.length === 0 ? (
+ // A failed read is not an empty list: a viewer key always gets 403 here (the route is
+ // OPERATOR-only), and a gateway error would otherwise read as "no webhooks configured".
+ <div className="empty-table-state" role="alert">
+ <AlertCircle size={48} strokeWidth={1} />
+ {(webhooksError as { status?: number }).status === 403 ? (
+ <>
+ <h3>{t('webhooks.empty.forbiddenTitle')}</h3>
+ <p>{t('webhooks.empty.forbiddenDesc')}</p>
+ </>
+ ) : (
+ <>
+ <h3>{t('webhooks.empty.loadErrorTitle')}</h3>
+ <p>{webhooksError.message}</p>
+ </>
+ )}
+ </div>
+ ) : webhooks.length === 0 ? (
<div className="empty-table-state">
<WebhookIcon size={48} strokeWidth={1} />
<h3>{t('webhooks.empty.title')}</h3>