DEV Community

Gaurav Guha
Gaurav Guha

Posted on Originally published at thefrontkit.com

How to build a sales dashboard in Next.js

Salesforce, HubSpot, and Pipedrive charge $6-10K/year for a 10-person sales team, and their dashboards often miss the mark. Teams either build their own or complain about the CRM's UI. A custom dashboard that pulls CRM data and presents it the team's way is often the best solution.

What to include

A real sales dashboard needs these elements:

  • Pipeline by stage: Deal count, value, and win probability per stage.
  • Quota progress: Per rep, team, and quarter.
  • Forecast: Committed, best-case, and pipeline coverage.
  • Activity metrics: Calls, emails, meetings, demos.
  • Win/loss analysis: With reason categorization.
  • Deal velocity: Average days per stage and total cycle.
  • Leaderboard: Rep performance.
  • Conversion rates: Between stages.

The data model

Four core entities:

  1. deals: Opportunity details.
  2. deal_stage_history: Stage change log.
  3. activities: Rep actions.
  4. quotas: Per-rep, per-period targets.

Gotcha: Don't skip deal_stage_history. It's essential for computing stage velocity and identifying stuck deals.

CRM integration

Sync data from your CRM (Salesforce, HubSpot, Pipedrive) using:

  • Webhooks (real-time updates).
  • Polling (every 5-15 minutes).
  • Nightly full sync (for correctness).

Gotcha: Handle CRM custom fields by storing them flexibly (e.g., jsonb column).

Pipeline by stage

Use a funnel chart, stacked bar, or Kanban board to visualize pipeline. Here's the query:

SELECT
  stage,
  COUNT(*) as deal_count,
  SUM(amount) as total_amount,
  SUM(amount * probability) as weighted_amount,
  AVG(EXTRACT(EPOCH FROM (NOW() - last_stage_change)) / 86400) as avg_days_in_stage
FROM deals
LEFT JOIN deal_stage_history h ON h.deal_id = deals.id AND h.is_latest = true
WHERE owner_id IN (...) AND closed_at IS NULL
GROUP BY stage
ORDER BY stage_order
Enter fullscreen mode Exit fullscreen mode

Gotcha: The "avg days in stage" column identifies stuck deals.

Quota progress

Calculate attainment, pace, and daily run rate needed. Display a progress bar with color-coded status (green, yellow, red).

Forecast

Show committed, best-case, and pipeline coverage against quota over time. Track forecast accuracy to identify trends.

Activity metrics

Pull data from email servers, calendars, and call tools for accurate activity counts. Treat this as a leading indicator, not a performance review tool.

Win/loss analysis

Categorize loss reasons to turn analysis into action. For example, "Price + competitor X was 30% cheaper" is more actionable than "Price."

Deal velocity

Compute average days per stage and total cycle time. Identify bottlenecks by stage.

Performance tips

  • Index deals, deal_stage_history, and activities tables.
  • Materialize aggregations for large datasets.
  • Cache dashboard views for 5-15 minutes.

Build time estimate

For a single engineer:

  • CRM integration + sync: 2 weeks
  • Pipeline + forecast UI: 2 weeks
  • Quota progress + leaderboard: 1 week
  • Activity metrics ingestion: 2 weeks
  • Win/loss + velocity analytics: 1 week
  • Reporting + exports: 1 week
  • Polish + mobile + permissions: 2 weeks

Total: ~11 weeks. Faster with a pre-built UI kit.

Focus engineering effort on CRM integration and analytics, not rebuilding chart components.


This is a shorter version of a guide I wrote at Frontkit Studio. The full post has the complete walkthrough.

Top comments (0)