Menu ▾ ▴

#194 fix(audience-lists): decouple stat counters from pagination and enable full dataset CSV exports

open
nobody
2026-11-20
2026-11-20
Anonymous
No

Originally created by: sumamakhan761

Problem Description

  1. Counters skew on "Load More":
    In AudienceListDashboard.tsx, the top metric cards (Captured Contacts, Verified Emails, Phone Numbers) and the "All Contacts" master card compute their values using contacts.length and contacts.reduce(...).
    Because contacts are paginated (limit=15), the counters initially display only 15, and arbitrarily increment every time a user clicks "Load More".

  2. CSV Export is capped to client DOM:
    ExportConfigModal only exports the contacts stored in the browser's React state. If a tenant has 150 leads, exporting produces a CSV with only the 15 currently loaded contacts unless they repeatedly click "Load More" first.


Expected Behavior

  1. Metric cards should reflect the true database totals (totalContacts, totalEmails, totalPhones) regardless of pagination state or how many rows are rendered on screen.
  2. Clicking "Export" should export the complete contact dataset matching the active filters, not just the currently loaded page.

Solution / Implementation Guide

  1. Backend (crm-export.service.ts & email-list-query.dto.ts):
  2. Add an optional export?: string field to EmailListQueryDto.
  3. In crm-export.service.ts:

    • If query.export === 'true', raise limit cap to e.g. 10,000 and set offset = 0.
    • In getEmailList, compute global email/phone stats across all matching contacts and return:
      ts stats: { totalContacts: total, totalEmails, totalPhones, }
  4. Frontend Dashboard (AudienceListDashboard.tsx):

  5. Store stats returned by /api/audience-contacts in component state.
  6. Bind "Captured Contacts", "Verified Emails", "Phone Numbers", and the "All Contacts" master card to stats instead of contacts.length or contacts.reduce(...).
  7. Pass an onFetchAllForExport callback to <ExportConfigModal /> that queries /api/audience-contacts?export=true with active filters.

  8. Export Modal (ExportConfigModal.tsx):

  9. Accept totalCount?: number and onFetchAllForExport?: () => Promise<Contact[]>.
  10. When the user triggers download, await onFetchAllForExport() to compile and download all rows matching the tenant scope.

Discussion


Log in to post a comment.