Files
co-lite/docs/superpowers/specs/2026-12-01-lead-dashboard-design.md
T

5.7 KiB

Lead Dashboard — Design

Date: 2026-12-01. Status: draft for approval.

Why

Co-Lite exists to generate leads for INS and CV marketing. Managers need to see which events, salespeople and interests produce leads and which of those leads convert. Today the portal home page is a welcome line, and the system keeps only each event lead's current status, so it cannot say when a lead was won or how long it took.

Goals

  • A dashboard on the portal home page showing lead capture and conversion for a chosen period.
  • Record every event-lead status change with its time, so the dashboard can count wins in a period and time to win.
  • Gate the dashboard with a new ACL module, BO_DASHBOARD, assigned to roles like every other module.
  • Company scoping as everywhere else: staff see their company, super admins see all or the one picked.

Non-goals

  • New lead statuses or a pipeline editor. The existing statuses stay: OPEN, CONTACTED, QUALIFIED, WON, LOST.
  • Member-app conversion (option 2). It comes later as its own change.
  • Showing the status timeline on the lead or event-lead screens. The data will exist; a later change can show it.
  • Excel export of the dashboard.
  • Demographics (age, gender, state) as in the legacy event statistics: Co-Lite leads carry none of those fields.

Anti-goals

  • Numbers that disagree with the Leads and Event Leads listings for the same filter.
  • SQL built by string replacement (the legacy report service does this; it is an injection risk).
  • A slow home page: every user lands there after sign-in.

Definitions

  • Capture: one event lead (a person captured at one event). A person captured at two events is two captures. Conversion is per capture, because the question is which events convert.
  • Won: an event lead whose current status is WON.
  • Won in period: a won event lead whose latest change into WON falls in the period.
  • Conversion rate: of the captures made in the period, the share that are now WON.
  • Days to win: from capture to the latest change into WON, in whole days. Reported as the median.
  • Overdue follow-up: an event lead that is not WON or LOST and whose next follow-up date is before today. This is a current count, not tied to the period.
  • Clock: Asia/Kuala_Lumpur, as in the legacy dashboard.

What the dashboard shows

  • Period: This month (the default), Last month, or a custom range. A range of up to 62 days is charted by day; a longer one by month (legacy rule).
  • Company picker: the existing picker, for super admins only.
  • Tiles:
    • Captures.
    • New leads (lead type NEW).
    • Won in period.
    • Conversion rate.
    • Median days to win.
    • Overdue follow-ups.
  • Funnel: the period's captures by current status (OPEN, CONTACTED, QUALIFIED, WON, LOST).
  • Trend chart: captures and wins per day or month.
  • By event: each event with captures in the period.
    • Columns: event, captures, new, won, conversion rate.
    • A super admin viewing all companies also gets a Company column.
    • Each row links to that event's leads.
  • By salesperson: for the period's captures, per salesperson.
    • Columns: assigned, worked (status beyond OPEN), won, lost, conversion rate, overdue follow-ups.
    • Captures with no salesperson appear as an "Unassigned" row.
  • By interest: per interest, the captures and wins. A capture with two interests counts under both.
  • Phone width: tiles stack, and the tables become cards, as on the other listings.

Status timing

  • New table event_lead_status_change in services-counter, append-only. Columns:

    • id, company_id, event_lead_id;
    • from_status (null for the first row), to_status;
    • changed_at, changed_by.
  • Capture writes the first row: null → initial status, at captured_at.

  • An edit that changes status writes one row in the same transaction. An edit that keeps the status writes nothing.

  • Backfill for existing event leads, in the change's SQL:

    • one row null → OPEN at captured_at;
    • when the current status is not OPEN, a second row OPEN → status at updated_at, or at captured_at when updated_at is null.

    These times are approximate, and the deployment notes say so.

Access

  • New module BO_DASHBOARD, type M, URL /, id 40050000. The sidebar shows a "Dashboard" link.
  • The home page shows the dashboard to users with BO_DASHBOARD. Everyone else sees today's welcome, not a not-authorised page, because every user lands at home after sign-in.
  • The endpoint answers 403 without the module.
  • Super admins pass as they do for every module.

Approach

Aggregate in services-counter SQL:

  • services-counter gets one endpoint, /counter/dashboard/leads. It takes companyId (null = all), from, to and the bucket, and runs grouped native queries with bind parameters over event_lead, event_lead_status_change, event_lead_interest and event.
  • mobile-api adds GET /api/admin/dashboard/leads under @AdminModule("BO_DASHBOARD"). It applies the company scope, resolves salesperson names in one batch call to services-system, and returns one JSON payload.

Rejected:

  • Aggregating in mobile-api from paged listings: too many calls, and it gets slower as leads grow.
  • A separate report service like legacy: a new deployable for one screen.

Portal

  • Charts: add recharts and copy babyboo's chart.tsx wrapper. babyboo already uses both, and the look then matches.
  • The funnel and tables use existing components (Card, Table, data-table).

Left to the builder

  • Indexes for the dashboard queries, chosen from EXPLAIN on realistic local data: likely event_lead(company_id, captured_at) and event_lead_status_change(event_lead_id, changed_at).
  • Exact tile layout and copy.
  • Message keys for every label (English, as for other screens).