Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): keep a webhook modal open while its request runs
Yudhi Armyndharisb6e31cd634b8
diff --git a/dashboard/src/pages/Webhooks.test.ts b/dashboard/src/pages/Webhooks.test.tsindex ab2836291..e3443de0f 100644--- a/dashboard/src/pages/Webhooks.test.ts+++ b/dashboard/src/pages/Webhooks.test.ts@@ -552,3 +552,46 @@ test('a second click on the delete confirm while the first delete is in flight sawait screen.findByText('Webhook deleted successfully');assert.equal(screen.queryByRole('alert'), null);});++// A late success resets whichever modal is open by then, so a modal must not close and give way to+// another while its own request is in flight.+test('the edit modal stays open while its save is in flight', async () => {+ const { screen, fireEvent, waitFor, within } = rtl;+ const save = await openEditModal();+ fireEvent.click(save);+ await waitFor(() => assert.equal(updateCalls, 1));+ const dialog = screen.getByRole('dialog');+ const cancel = within(dialog).getByRole<HTMLButtonElement>('button', { name: 'Cancel' });+ assert.equal(cancel.disabled, true);+ fireEvent.keyDown(document, { key: 'Escape' });+ fireEvent.click(within(dialog).getByRole('button', { name: 'Close' }));+ assert.ok(screen.queryByRole('dialog'), 'the edit modal closed mid-save');+});++test('the create modal stays open while its create is in flight', async () => {+ const { screen, fireEvent, waitFor, within } = rtl;+ fireEvent.click(await openCreateModal());+ await waitFor(() => assert.equal(createCalls, 1));+ const dialog = screen.getByRole('dialog');+ assert.equal(within(dialog).getByRole<HTMLButtonElement>('button', { name: 'Cancel' }).disabled, true);+ fireEvent.keyDown(document, { key: 'Escape' });+ assert.ok(screen.queryByRole('dialog'), 'the create modal closed mid-create');+});++test('the delete confirmation stays open while its delete is in flight', async () => {+ const { screen, fireEvent, waitFor, within } = rtl;+ webhooksStatus = 200;+ webhookList = [{ id: 'w1', sessionId: 'sess-1', url: 'https://example.test/hook', events: [], active: true }];+ window.sessionStorage.setItem('openwa_user_role', 'operator');+ holdRequests();+ renderWebhooks();+ fireEvent.click(await screen.findByTitle('Delete'));+ const dialog = screen.getByRole('dialog');+ fireEvent.click(within(dialog).getByRole('button', { name: 'Delete' }));+ await waitFor(() => assert.equal(deleteCalls.length, 1));+ assert.equal(within(dialog).getByRole<HTMLButtonElement>('button', { name: 'Cancel' }).disabled, true);+ fireEvent.keyDown(document, { key: 'Escape' });+ assert.ok(screen.queryByRole('dialog'), 'the delete confirmation closed mid-delete');+ releaseRequests();+ await screen.findByText('Webhook deleted successfully');+});diff --git a/dashboard/src/pages/Webhooks.tsx b/dashboard/src/pages/Webhooks.tsxindex 00a00e075..6c6be3200 100644--- a/dashboard/src/pages/Webhooks.tsx+++ b/dashboard/src/pages/Webhooks.tsx@@ -416,15 +416,21 @@ export function Webhooks() {</div>)}+ {/* Each modal stays open while its request is in flight: the success resets the modal's state, which+ by then could hold another webhook opened after a close. */}{showCreateModal && (<Modalopen- onClose={() => setShowCreateModal(false)}+ onClose={() => !createMutation.isPending && setShowCreateModal(false)}title={t('webhooks.createTitle')}closeLabel={t('common.close')}footer={<>- <button className="btn-secondary" onClick={() => setShowCreateModal(false)}>+ <button+ className="btn-secondary"+ onClick={() => setShowCreateModal(false)}+ disabled={createMutation.isPending}+ >{t('common.cancel')}</button><button className="btn-primary" onClick={handleCreate} disabled={!canCreate}>@@ -517,12 +523,16 @@ export function Webhooks() {{showEditModal && editWebhook && (<Modalopen- onClose={() => setShowEditModal(false)}+ onClose={() => !updateMutation.isPending && setShowEditModal(false)}title={t('webhooks.editTitle')}closeLabel={t('common.close')}footer={<>- <button className="btn-secondary" onClick={() => setShowEditModal(false)}>+ <button+ className="btn-secondary"+ onClick={() => setShowEditModal(false)}+ disabled={updateMutation.isPending}+ >{t('common.cancel')}</button><button className="btn-primary" onClick={handleEdit} disabled={!canSave}>@@ -642,13 +652,17 @@ export function Webhooks() {{showDeleteModal && deleteTarget && (<Modalopen- onClose={() => setShowDeleteModal(false)}+ onClose={() => !deleteMutation.isPending && setShowDeleteModal(false)}title={t('webhooks.deleteTitle')}className="modal-sm"closeLabel={t('common.close')}footer={<>- <button className="btn-secondary" onClick={() => setShowDeleteModal(false)}>+ <button+ className="btn-secondary"+ onClick={() => setShowDeleteModal(false)}+ disabled={deleteMutation.isPending}+ >{t('common.cancel')}</button><button className="btn-danger" onClick={handleDelete} disabled={deleteMutation.isPending}>