Skip to content

Commit 05edbca

Browse files
committed
fix: auto-dial stops at end of list and shows clear stop button
- Remove queue wrap-around so auto-dial advances forward only - Stop auto-dial with 'Auto dial complete' toast when last lead is done - Auto-dial toggle shows 'Stop Auto Dial' while a call is active
1 parent 3705f97 commit 05edbca

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

frontend/src/components/campaigns/CampaignDetail.jsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -270,13 +270,15 @@ export default function CampaignDetail({
270270
}, [campaignLeads, leadSearch, execFilter, scheduleFrom, scheduleTo]);
271271

272272
// Keep the auto-dial queue in sync with the current filtered list.
273+
// The queue only moves forward; it never wraps around to leads before the
274+
// starting lead so auto-dial stops cleanly at the end of the list.
273275
useEffect(() => {
274276
if (!autoDialEnabled) return;
275277
const ids = filteredLeads.map(l => l.id);
276278
setAutoDialQueue(prev => {
277279
if (autoDialActiveId && ids.includes(autoDialActiveId)) {
278280
const idx = ids.indexOf(autoDialActiveId);
279-
return [autoDialActiveId, ...ids.slice(idx + 1), ...ids.slice(0, idx)];
281+
return [autoDialActiveId, ...ids.slice(idx + 1)];
280282
}
281283
return ids;
282284
});
@@ -427,7 +429,7 @@ export default function CampaignDetail({
427429
}
428430
if (!autoDialEnabledRef.current || !autoDialActiveIdRef.current) return;
429431
const idx = autoDialQueueRef.current.indexOf(autoDialActiveIdRef.current);
430-
const nextIdx = idx >= 0 ? idx + 1 : 0;
432+
const nextIdx = idx >= 0 ? idx + 1 : autoDialQueueRef.current.length;
431433
const nextId = autoDialQueueRef.current[nextIdx];
432434
if (!nextId) {
433435
toast('Auto dial complete');
@@ -454,7 +456,7 @@ export default function CampaignDetail({
454456
const ids = filteredLeads.map(l => l.id);
455457
const idx = ids.indexOf(lead.id);
456458
if (idx >= 0) {
457-
setAutoDialQueue([lead.id, ...ids.slice(idx + 1), ...ids.slice(0, idx)]);
459+
setAutoDialQueue([lead.id, ...ids.slice(idx + 1)]);
458460
} else {
459461
setAutoDialQueue([lead.id]);
460462
}
@@ -1108,11 +1110,11 @@ export default function CampaignDetail({
11081110
} else {
11091111
setAutoDialActiveId(null);
11101112
setAutoDialQueue([]);
1111-
toast('Auto dial disabled');
1113+
toast('Auto dial stopped');
11121114
}
11131115
}}
1114-
title="After a browser call ends, automatically dial the next filtered lead">
1115-
{autoDialEnabled ? '⏸ Auto Dial On' : '▶ Auto Dial'}
1116+
title={autoDialActiveId ? 'Stop auto-dialing' : 'After a browser call ends, automatically dial the next filtered lead'}>
1117+
{autoDialActiveId ? '⏹ Stop Auto Dial' : autoDialEnabled ? '⏸ Auto Dial On' : '▶ Auto Dial'}
11161118
</button>
11171119
)}
11181120
</div>

0 commit comments

Comments
 (0)