Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): hold Send while a bulk batch cancel is in flight

Yudhi Armyndharisf2857ce8c6e1
diff --git a/dashboard/src/pages/MessageTester.test.ts b/dashboard/src/pages/MessageTester.test.ts
index 54e64c162..4ce0dd7a6 100644
--- a/dashboard/src/pages/MessageTester.test.ts
+++ b/dashboard/src/pages/MessageTester.test.ts
@@ -703,3 +703,47 @@ test('a failed groups read is reported, not shown as "no groups found"', async (
rtl.within(alert).getByText(/Failed to load data/);
assert.equal(rtl.screen.queryByText('No groups found'), null);
});
+
+test('Send stays disabled while a batch cancel is in flight, so its answer cannot land on a newer batch', async () => {
+ const progress = { total: 1, sent: 0, failed: 0, pending: 1, cancelled: 0 };
+ let answerCancel: (response: Response) => void = () => {};
+ globalThis.fetch = ((input: RequestInfo | URL): Promise<Response> => {
+ const url = typeof input === 'string' ? input : input instanceof URL ? input.href : input.url;
+ if (url.endsWith('/sessions')) {
+ return Promise.resolve(jsonResponse([{ id: 's1', name: 'Main', status: 'ready', phone: '15550000000' }]));
+ }
+ if (url.endsWith('/messages/send-bulk')) {
+ return Promise.resolve(jsonResponse({ batchId: 'b1', status: 'pending', totalMessages: 1 }, 202));
+ }
+ if (url.endsWith('/messages/batch/b1/cancel')) {
+ return new Promise<Response>(resolve => {
+ answerCancel = resolve;
+ });
+ }
+ if (url.endsWith('/messages/batch/b1')) {
+ return Promise.resolve(jsonResponse({ batchId: 'b1', status: 'processing', progress, results: [] }));
+ }
+ return Promise.resolve(jsonResponse([]));
+ }) as typeof fetch;
+ const container = await renderBulkAsWriter();
+ type(container, '#mt-11', '15550000001');
+ rtl.fireEvent.change(rtl.screen.getByPlaceholderText('Enter your message here...'), { target: { value: 'hi' } });
+ await rtl.waitFor(() => assert.equal(sendButton().disabled, false));
+ rtl.fireEvent.click(sendButton());
+ rtl.fireEvent.click(await rtl.screen.findByRole('button', { name: 'Cancel Batch' }));
+ await rtl.screen.findByRole('button', { name: 'Cancelling...' });
+
+ assert.equal(sendButton().disabled, true, 'a new batch could start while the cancel was unanswered');
+ await rtl.act(async () => {
+ answerCancel(
+ jsonResponse({
+ batchId: 'b1',
+ status: 'cancelled',
+ progress: { ...progress, pending: 0, cancelled: 1 },
+ results: [],
+ }),
+ );
+ await new Promise(resolve => setTimeout(resolve, 20));
+ });
+ assert.equal(sendButton().disabled, false);
+});
diff --git a/dashboard/src/pages/MessageTester.tsx b/dashboard/src/pages/MessageTester.tsx
index 13911e6ba..9761b1e63 100644
--- a/dashboard/src/pages/MessageTester.tsx
+++ b/dashboard/src/pages/MessageTester.tsx
@@ -366,9 +366,12 @@ export function MessageTester() {
(delayMs === undefined || (!Number.isNaN(delayMs) && delayMs >= 1000 && delayMs <= 60000));
}
+ // A new send replaces the batch on screen, so it waits for an in-flight cancel: the cancel's answer
+ // would otherwise be merged into the newer batch and stop its progress polling.
const isSendDisabled =
!canWrite ||
isLoading ||
+ batchCancelling ||
!session ||
!formValid ||
(messageType !== 'bulk' && (recipientType === 'group' ? selectedGroups.length === 0 : !recipient));