Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): keep the locked session select on the run's session

Yudhi Armyndharise88a07b262fc
diff --git a/dashboard/src/pages/NumberChecker.test.ts b/dashboard/src/pages/NumberChecker.test.ts
index c60723daa..066bd6859 100644
--- a/dashboard/src/pages/NumberChecker.test.ts
+++ b/dashboard/src/pages/NumberChecker.test.ts
@@ -884,6 +884,50 @@ test('NumberChecker: a chosen session that leaves the ready list is replaced by
assert.match(checked[0], /\/sessions\/sess-a\/contacts\/check\//);
});
+// The select is locked during a run, so what it shows has to stay the session the run uses, whatever the ready list does.
+test('NumberChecker: a locked select keeps naming the run session when the chosen session drops out and returns', async () => {
+ const checked: string[] = [];
+ globalThis.fetch = ((input: RequestInfo | URL) => {
+ const url = String(input);
+ if (url.includes('/contacts/check/')) {
+ checked.push(url);
+ return url.endsWith('/919999999999')
+ ? Promise.resolve(registered('919999999999'))
+ : new Promise<Response>(() => {});
+ }
+ return Promise.resolve(jsonResponse(twoSessions('ready')));
+ }) as typeof fetch;
+ const client = createTestQueryClient();
+ renderComponent('operator', client);
+ await rtl.screen.findByRole('option', { name: /Beta/ });
+ const select = () => rtl.screen.getByRole('combobox', { name: 'WhatsApp Session' }) as HTMLSelectElement;
+ const options = () => [...select().options].map(option => option.value);
+
+ // Beta is chosen, drops out (the select falls back to Alpha), and the run starts on Alpha.
+ rtl.fireEvent.change(select(), { target: { value: 'sess-b' } });
+ await rtl.act(async () => client.setQueryData(['sessions'], twoSessions('disconnected')));
+ await rtl.waitFor(() => assert.deepEqual(options(), ['sess-a']));
+ rtl.fireEvent.click(rtl.screen.getByRole('tab', { name: /Bulk/i }));
+ rtl.fireEvent.change(rtl.screen.getByPlaceholderText(/9612345678/i), { target: { value: THREE_NUMBERS } });
+ startBatch();
+ await rtl.waitFor(() => assert.equal(checked.length, 1));
+ assert.match(checked[0], /\/sessions\/sess-a\//);
+
+ // Beta returns while the run is going: the select still names the session the lookups go to.
+ await rtl.act(async () => client.setQueryData(['sessions'], twoSessions('ready')));
+ await rtl.waitFor(() => assert.deepEqual(options(), ['sess-a', 'sess-b']));
+ assert.equal(select().value, 'sess-a');
+ assert.equal(select().disabled, true);
+
+ // A single check made meanwhile goes to the session the select shows too.
+ rtl.fireEvent.click(rtl.screen.getByRole('tab', { name: /Single Check/i }));
+ assert.equal(select().value, 'sess-a');
+ rtl.fireEvent.change(rtl.screen.getByPlaceholderText(/9876543210/), { target: { value: '919999999999' } });
+ rtl.fireEvent.click(rtl.screen.getByRole('button', { name: 'Check' }));
+ await rtl.waitFor(() => assert.equal(checked.length, 2));
+ assert.match(checked[1], /\/sessions\/sess-a\/contacts\/check\/919999999999/);
+});
+
test('NumberChecker: the session cannot be switched from the Single tab while a bulk run is going', async () => {
globalThis.fetch = ((input: RequestInfo | URL) => {
if (String(input).includes('/contacts/check/')) return new Promise<Response>(() => {});
diff --git a/dashboard/src/pages/NumberChecker.tsx b/dashboard/src/pages/NumberChecker.tsx
index b05bd76a5..cb86bf845 100644
--- a/dashboard/src/pages/NumberChecker.tsx
+++ b/dashboard/src/pages/NumberChecker.tsx
@@ -102,6 +102,10 @@ export function NumberChecker() {
const [batchInput, setBatchInput] = useState('');
const [batchDelay, setBatchDelay] = useState<number>(1000);
const [isCheckingBatch, setIsCheckingBatch] = useState(false);
+ // The session a running bulk run is bound to. Both selects are locked meanwhile, so they keep showing it even if
+ // the chosen session leaves the ready list and returns during the run, and a single check goes to it too.
+ const [runSession, setRunSession] = useState('');
+ const shownSession = isCheckingBatch ? runSession : currentSession;
const [batchResults, setBatchResults] = useState<CheckResultItem[]>([]);
const [batchProgress, setBatchProgress] = useState({ current: 0, total: 0 });
const [batchFilter, setBatchFilter] = useState<'all' | 'registered' | 'unregistered' | 'failed'>('all');
@@ -204,18 +208,18 @@ export function NumberChecker() {
toast.error(t('numberChecker.toast.enterNumber'));
return;
}
- if (!currentSession) {
+ if (!shownSession) {
toast.error(t('numberChecker.toast.noSession'));
return;
}
setIsCheckingSingle(true);
try {
- const res = await contactApi.checkNumber(currentSession, formatted);
+ const res = await contactApi.checkNumber(shownSession, formatted);
let avatar: string | null = null;
if (res.exists && res.whatsappId) {
try {
- const pic = await contactApi.profilePicture(currentSession, res.whatsappId);
+ const pic = await contactApi.profilePicture(shownSession, res.whatsappId);
avatar = pic.url;
} catch {
// Profile picture is optional
@@ -266,6 +270,7 @@ export function NumberChecker() {
}
const runId = ++batchRunIdRef.current;
+ setRunSession(currentSession);
setIsCheckingBatch(true);
setBatchResults([]);
setBatchFilter('all');
@@ -327,6 +332,7 @@ export function NumberChecker() {
if (batchRunIdRef.current !== runId) return;
setIsCheckingBatch(false);
+ setRunSession('');
if (refusedWith !== undefined) {
const stop = { status: refusedWith, attempted: results.length, total: numbers.length };
setBatchStop(stop);
@@ -343,6 +349,7 @@ export function NumberChecker() {
const handleStopBatch = () => {
batchRunIdRef.current++;
setIsCheckingBatch(false);
+ setRunSession('');
};
// Filter batch results
@@ -446,7 +453,7 @@ export function NumberChecker() {
id="nc-single-session"
aria-label={t('numberChecker.session.label')}
className="nc-input"
- value={currentSession}
+ value={shownSession}
onChange={e => setSelectedSession(e.target.value)}
disabled={readySessions.length === 0 || isCheckingBatch}
>
@@ -718,7 +725,7 @@ export function NumberChecker() {
id="nc-batch-session"
aria-label={t('numberChecker.session.label')}
className="nc-input"
- value={currentSession}
+ value={shownSession}
onChange={e => setSelectedSession(e.target.value)}
disabled={readySessions.length === 0 || isCheckingBatch}
>