# Manager Dashboard - Investigation Report

**Date:** Jan 20, 2026

---

## Summary

The Manager Dashboard exists and is fully functional at `/manager`. It provides team oversight, coaching insights, and individual rep drilldowns.

---

## What Exists ✅

### 1. Manager Dashboard Page
- **File:** `admin/src/pages/ManagerDashboard.jsx` (530+ lines)
- **Route:** `/manager`
- **Access:** More menu → "Manager Dashboard"

### 2. Team Overview Stats
| Metric | Description |
|--------|-------------|
| Total Calls | Current period with % change |
| Total SMS | Current period with % change |
| Total Conversions | Current period with % change |
| Avg Response Time | Team average |
| Active Reps | Count with activity |
| Avg Conversion Rate | Team average |
| Avg Call Duration | Team average |

### 3. Period Filtering
- Today
- Week (default)
- Month
- Shows comparison vs previous period

### 4. Coaching Insights
**Top Performers:** Top 3 reps by performance score
**Needs Coaching:** Reps with low conversion, slow response, or low activity

**Performance Score Formula:**
```
score = (calls × 10) + (conversions × 100) + (conversionRate × 5) - slowResponsePenalty
```

### 5. Team Leaderboard
- Sortable by performance score
- Shows: calls, conversions, conversion rate, streak
- Click to drill into individual rep

### 6. Individual Rep Detail View
- Individual stats: calls, SMS, conversions, avg call duration
- Pipeline value (total converted)
- Recent calls with outcomes
- Wins this period (company names + values)
- Activity heatmap by hour (7am-7pm)
- Daily activity chart

### 7. Manager Challenges (Gamification)
- **File:** `admin/src/components/gamification/ManagerChallenges.jsx`
- Create custom team competitions
- Metrics: calls, conversions, response time, talk time
- Rewards: XP multiplier, real prizes, bragging rights

---

## API Endpoints

| Endpoint | Method | Purpose |
|----------|--------|---------|
| `/api/manager/dashboard` | GET | Team overview stats |
| `/api/manager/rep/:userId` | GET | Individual rep details |

**Query Params:** `?period=today|week|month`

**Response Structure:**
```javascript
{
  period,
  periodStart,
  teamOverview: {
    totalCalls,
    totalSMS,
    totalConversions,
    avgCallDuration,
    avgResponseTime,
    avgConversionRate,
    activeReps
  },
  comparison: {
    callsChange,
    smsChange,
    conversionsChange
  },
  reps: [{
    userId, name, level, streak,
    calls, sms, conversions, conversionRate,
    avgCallDuration, avgResponseTime, performanceScore
  }],
  coaching: {
    topPerformers,
    needsAttention
  }
}
```

---

## Access Control

### Current Implementation
- **Email whitelist only** - no role differentiation
- All authenticated users can access `/manager`
- No "manager" vs "rep" role enforcement

### Allowed Users (AuthContext.jsx)
```javascript
ALLOWED_EMAILS = [
  'tonymccabe53@gmail.com',      // Tony
  'angelica@rateright.com.au',   // Angelica
  'admin@rateright.com.au',      // Michael
  'cormick@rateright.com.au',    // Cormick
  'stephen@rftn.com.au',         // Stephen
  'cathyrei@gmail.com',          // Cathy
];
```

---

## What's Missing ❌

| Gap | Description |
|-----|-------------|
| Role-based access | Anyone authenticated can access /manager |
| Lead assignment | Can view but not reassign leads |
| Coaching actions | No send coaching notes, no 1:1 tracking |
| Alerts | No notifications for underperforming reps |
| Goals/Quotas | No target setting per rep |
| Team hierarchy | No manager-to-rep relationships |
| Bulk operations | No bulk lead assignment or messaging |
| Audit trail | No logging of manager actions |

---

## Key Files

| File | Purpose |
|------|---------|
| `admin/src/pages/ManagerDashboard.jsx` | Main dashboard page |
| `src/routes/manager.js` | API endpoints |
| `admin/src/context/AuthContext.jsx` | User authentication |
| `src/middleware/auth.js` | Backend auth middleware |
| `admin/src/components/gamification/ManagerChallenges.jsx` | Challenge creation |

---

## Database Tables Used

| Table | Fields Used |
|-------|-------------|
| `user_xp` | user_id, display_name, level, streak |
| `communications` | type, handled_by, response_time_seconds, duration_seconds |
| `leads` | status, metadata.converted_by |

---

## Future Enhancements

### To Add Role-Based Access:
1. Add `role` column to `user_xp` table
2. Create `requireManagerRole` middleware
3. Protect manager routes
4. Add role check to AuthContext

### To Add Manager Actions:
1. Lead reassignment endpoints
2. Coaching notes system
3. Goal/quota management
4. Alert/notification system
