# Team Performance Dashboard

> Multi-user performance views for managers and team leads

**Created:** Jan 20, 2026
**Status:** Plan Ready
**Effort:** 6-8 hours
**Ongoing Cost:** $0

---

## Problem

Current Manager Dashboard shows aggregate stats, but lacks:
- Individual rep comparison
- Performance trends over time
- Activity heatmaps
- Goal tracking per rep
- Coaching recommendations

---

## Solution

Enhanced team performance views with drill-down capabilities.

### Performance Metrics

| Metric | Description |
|--------|-------------|
| Calls Made | Total outbound calls |
| Connect Rate | % of calls that connected |
| Talk Time | Total minutes on calls |
| Conversions | Leads converted |
| Conversion Rate | Conversions / Calls |
| Response Time | Avg time to respond to SMS |
| Pipeline Value | Total $ in their pipeline |
| XP Earned | Gamification points |

---

## Views

### 1. Team Overview
```
┌─────────────────────────────────────────────────────┐
│ TEAM PERFORMANCE - This Week                        │
├─────────────────────────────────────────────────────┤
│ Rep         │ Calls │ Conv │ Rate │ Talk  │ Trend  │
│─────────────│───────│──────│──────│───────│────────│
│ Tony        │   87  │   4  │ 4.6% │ 6.2h  │   ↑    │
│ Angelica    │   62  │   3  │ 4.8% │ 4.1h  │   ↓    │
│ New Rep     │   45  │   1  │ 2.2% │ 2.8h  │   →    │
├─────────────────────────────────────────────────────┤
│ TEAM TOTAL  │  194  │   8  │ 4.1% │ 13.1h │        │
└─────────────────────────────────────────────────────┘
```

### 2. Individual Deep Dive
- Daily/weekly/monthly breakdown
- Activity heatmap (calls by hour/day)
- Best performing lead types
- Common objections encountered
- Win/loss patterns

### 3. Comparison View
- Side-by-side rep comparison
- Benchmark against team average
- Historical trend lines

### 4. Goals & Targets
- Set targets per rep (calls, conversions)
- Track progress vs target
- Alert when falling behind

---

## Database Schema

```sql
-- Rep targets/goals
CREATE TABLE IF NOT EXISTS rep_targets (
  id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  user_id UUID REFERENCES auth.users(id) ON DELETE CASCADE,
  period VARCHAR(20) NOT NULL, -- 'daily', 'weekly', 'monthly'
  metric VARCHAR(50) NOT NULL, -- 'calls', 'conversions', 'talk_time'
  target_value INTEGER NOT NULL,
  start_date DATE NOT NULL,
  end_date DATE,
  created_by UUID REFERENCES auth.users(id),
  created_at TIMESTAMPTZ DEFAULT NOW(),
  UNIQUE(user_id, period, metric, start_date)
);

-- Performance snapshots (for historical trends)
CREATE TABLE IF NOT EXISTS performance_snapshots (
  id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  user_id UUID REFERENCES auth.users(id) ON DELETE CASCADE,
  snapshot_date DATE NOT NULL,
  period VARCHAR(20) NOT NULL, -- 'daily', 'weekly'
  metrics JSONB NOT NULL,
  -- { calls: 45, conversions: 2, talk_time_minutes: 180, ... }
  created_at TIMESTAMPTZ DEFAULT NOW(),
  UNIQUE(user_id, snapshot_date, period)
);

-- Indexes
CREATE INDEX idx_rep_targets_user ON rep_targets(user_id);
CREATE INDEX idx_performance_snapshots_user_date
ON performance_snapshots(user_id, snapshot_date DESC);
```

---

## API Endpoints

```
GET  /api/team/performance?period=week     # Team overview
GET  /api/team/rep/:userId?period=month    # Individual breakdown
GET  /api/team/compare?users=id1,id2       # Side-by-side comparison
GET  /api/team/heatmap/:userId             # Activity heatmap data
GET  /api/team/targets                     # All targets
POST /api/team/targets                     # Set target
GET  /api/team/targets/:userId             # Rep's targets
GET  /api/team/coaching/:userId            # AI coaching suggestions
```

---

## UI Components

### TeamPerformancePage.jsx
- Full page at /team-performance
- Tab navigation: Overview | Individual | Compare | Goals
- Period selector (today/week/month/custom)

### RepPerformanceCard.jsx
- Compact card for each rep
- Click to expand/drill down
- Sparkline trend indicator

### ActivityHeatmap.jsx
- Calendar heatmap of activity
- Darker = more calls
- Click day for details

### GoalProgressBar.jsx
- Visual progress toward target
- Green/yellow/red based on pace
- "X calls to hit target" message

### CoachingInsights.jsx
- AI-generated coaching tips
- Based on performance patterns
- "Tony converts best after 2pm - schedule hot leads then"

---

## Coaching AI

```javascript
async function generateCoachingInsights(userId) {
  const stats = await getRepStats(userId, 'month');
  const patterns = await getRepPatterns(userId);

  const prompt = `
    Analyze this sales rep's performance and give 3 specific coaching tips:

    Stats: ${JSON.stringify(stats)}
    Patterns: ${JSON.stringify(patterns)}

    Focus on actionable improvements, not generic advice.
  `;

  return await openai.chat(prompt);
}
```

---

## Implementation Steps

### Phase 1: Database + API (2-3 hours)
1. [ ] Create migration for targets and snapshots
2. [ ] Create team routes
3. [ ] Implement aggregation queries
4. [ ] Add daily snapshot job

### Phase 2: Team Overview (2 hours)
1. [ ] Create TeamPerformancePage
2. [ ] Create RepPerformanceCard
3. [ ] Add period selector
4. [ ] Add sorting/filtering

### Phase 3: Individual + Compare (2 hours)
1. [ ] Create individual drill-down view
2. [ ] Create ActivityHeatmap
3. [ ] Create comparison view

### Phase 4: Goals + Coaching (2 hours)
1. [ ] Create GoalProgressBar
2. [ ] Add target setting UI
3. [ ] Implement coaching AI
4. [ ] Create CoachingInsights component

---

## Access Control

- **Reps:** Can only see own performance
- **Managers:** Can see all reps, set targets
- **Admin:** Full access, can modify historical data

---

## Success Metrics

- Managers check dashboard daily
- Target completion rate improves 20%
- Coaching insights rated helpful >80%
