Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): keep the create-key modal open while it saves
Yudhi Armyndharisf2de1d80e682
diff --git a/dashboard/src/pages/ApiKeys.test.ts b/dashboard/src/pages/ApiKeys.test.tsindex d1696f541..9c790bfeb 100644--- a/dashboard/src/pages/ApiKeys.test.ts+++ b/dashboard/src/pages/ApiKeys.test.ts@@ -24,6 +24,8 @@ const billingBot = {};let keyList: Record<string, unknown>[] = [billingBot];let createBody: Record<string, unknown> | undefined;+// When set, POST /auth/api-keys answers only once this settles.+let createGate: Promise<void> | undefined;let updateBodies: Record<string, unknown>[] = [];let updateStatus = 200;@@ -34,7 +36,8 @@ function installFetchStub(): void {if (path === '/api/sessions') return Promise.resolve(jsonResponse([]));if (init?.method === 'POST' && path === '/api/auth/api-keys') {createBody = JSON.parse(String(init.body));- return Promise.resolve(jsonResponse({ ...billingBot, id: 'key-new', apiKey: 'owa_k1_new' }, 201));+ const created = jsonResponse({ ...billingBot, id: 'key-new', apiKey: 'owa_k1_new' }, 201);+ return createGate ? createGate.then(() => created) : Promise.resolve(created);}if (init?.method === 'PUT' && path.startsWith('/api/auth/api-keys/')) {updateBodies.push(JSON.parse(String(init.body)));@@ -76,6 +79,7 @@ afterEach(() => {listStatus = 200;keyList = [billingBot];createBody = undefined;+ createGate = undefined;updateBodies = [];updateStatus = 200;window.sessionStorage.removeItem('openwa_api_key');@@ -177,6 +181,27 @@ test('a create sends the IP allow-list, chats and expiry only when filled in', a});});+// The key exists once the request lands; a modal closed meanwhile would leave its one-time secret+// unseen and pop it up on the next Create API Key click.+test('the create modal stays open until the request settles and then shows the secret', async () => {+ const { screen, fireEvent } = rtl;+ let release = (): void => {};+ createGate = new Promise(resolve => {+ release = resolve;+ });+ const create = await openCreate();+ fireEvent.change(screen.getByLabelText('Name'), { target: { value: 'crm-bot' } });+ fireEvent.click(create);+ const cancel = await screen.findByRole<HTMLButtonElement>('button', { name: 'Cancel' });+ await rtl.waitFor(() => assert.equal(cancel.disabled, true, 'Cancel is live while the key is being created'));+ assert.equal(screen.queryByRole('button', { name: 'Close' }), null, 'the close button is live mid-request');+ fireEvent.keyDown(document, { key: 'Escape' });+ fireEvent.mouseDown(document.querySelector('.modal-overlay') as HTMLElement);+ screen.getByRole('dialog');+ release();+ await screen.findByText('owa_k1_new');+});+// A production gateway refuses a name over 100 characters with a bare "Bad Request".test('the key name cannot exceed the 100 characters the gateway takes', async () => {await openCreate();diff --git a/dashboard/src/pages/ApiKeys.tsx b/dashboard/src/pages/ApiKeys.tsxindex 04746c678..57413aad7 100644--- a/dashboard/src/pages/ApiKeys.tsx+++ b/dashboard/src/pages/ApiKeys.tsx@@ -522,13 +522,16 @@ export function ApiKeys() {{showModal && (<Modalopen- onClose={closeCreateModal}+ // The key exists once the request lands, and its secret is shown only here, so the modal+ // cannot be dismissed until the request settles.+ onClose={createMutation.isPending ? () => {} : closeCreateModal}+ hideCloseButton={createMutation.isPending}title={createdKey ? t('apiKeys.createdTitle') : t('apiKeys.modalTitle')}closeLabel={t('common.close')}footer={!createdKey ? (<>- <button className="btn-secondary" onClick={closeCreateModal}>+ <button className="btn-secondary" onClick={closeCreateModal} disabled={createMutation.isPending}>{t('common.cancel')}</button><button className="btn-primary" onClick={handleCreate} disabled={!canCreate}>