Skip to content

MediaPushai/bobs-sales-tracking

Repository files navigation

Bob's Sales Tracking

Multi-user sales team dashboard with real-time commission visibility and account health monitoring.

A production-ready SaaS application for sales teams to track performance, manage customer relationships, and optimize territory management. Built with React 18, Supabase, and TanStack Query.


πŸš€ Quick Start

For Users

  1. Follow DEPLOY.md for step-by-step production setup (~1 hour)
  2. After setup, open your Vercel URL
  3. Login with test credentials
  4. Upload daily CSV files to sync sales data

For Developers

npm install
cp .env.local.example .env.local
# Fill in VITE_SUPABASE_URL and VITE_SUPABASE_ANON_KEY
npm run dev
# Open http://localhost:5173/login

πŸ“Š Features

Rep Dashboard (PersonalDashboard)

  • KPI Cards: YTD Commission, Revenue, Gross Profit, Active Customers
  • Dormant Account Alerts: Automatic detection of accounts silent 7+ days
  • Product Mix: Category breakdown with revenue % and margin %
  • Real-time Data: Updates automatically when managers upload CSV

Manager Dashboards

  • Team Leaderboard: Rep rankings by commission with team totals
  • Product Mix (Aggregated): Category performance across all reps
  • Opportunity Pipeline: Critical (14+ days) and at-risk (7-13 days) accounts
  • Territory Analysis: Territory revenue with concentration risk flagging

Admin Features

  • CSV Upload: Drag-and-drop daily sales file upload
  • Upload History: Track all uploads with status and error logs
  • Automatic Processing: Edge Function batch-inserts rows in ~10 seconds

πŸ—οΈ Architecture

Frontend

  • React 18 with TypeScript for type safety
  • Vite for fast dev/build (101ms production build)
  • React Router v6 for role-based navigation
  • TanStack Query for data caching and automatic invalidation
  • Recharts ready for advanced visualizations
  • Tailwind CSS for responsive design

Backend

  • Supabase PostgreSQL with Row-Level Security (RLS)
  • 4 SQL views for aggregated metrics
  • Edge Functions (Deno) for CSV processing
  • Automatic Commission Calculation (generated columns)

Security

  • RLS Policies: Reps can only see their own data (enforced at DB layer)
  • Role-Based Access Control: rep β†’ manager β†’ admin with progressive access
  • Auth via Supabase: Email/password with session management

πŸ“ Project Structure

~/bobs-sales-tracking/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ App.tsx                 # Router + auth guards
β”‚   β”œβ”€β”€ hooks/
β”‚   β”‚   β”œβ”€β”€ useAuth.ts         # Session + profile + role
β”‚   β”‚   └── useQueries.ts      # TanStack Query hooks for all views
β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”œβ”€β”€ layout/            # AppShell, Sidebar
β”‚   β”‚   β”œβ”€β”€ ui/                # KPICard, DataTable, StatusBadge
β”‚   β”‚   └── charts/            # Ready for Recharts
β”‚   └── pages/                 # 7 routes (login + 6 dashboards)
β”œβ”€β”€ supabase/
β”‚   β”œβ”€β”€ migrations/            # 3 SQL migrations
β”‚   └── functions/             # Edge Function (CSV processing)
β”œβ”€β”€ scripts/
β”‚   └── seed_from_json.py      # Load 1,981 rows from agchem-tracker
β”œβ”€β”€ PHASE-1-COMPLETE.md        # Foundation build summary
β”œβ”€β”€ PHASE-2-COMPLETE.md        # Upload + dashboards build summary
β”œβ”€β”€ SETUP.md                   # Detailed Supabase configuration
β”œβ”€β”€ DEPLOY.md                  # Step-by-step deployment checklist
└── README.md                  # This file

πŸ“ˆ Data Model

Database Schema

  • profiles: Users with role (rep/manager/admin) and rep_name
  • sales_rows: Individual invoice line items with auto-calculated commission
  • csv_uploads: Audit trail of all uploads
  • 4 SQL views: Aggregated metrics for dashboard efficiency

RLS Policies

  • Reps see only their own rows
  • Managers see all rows
  • Admins control uploads

πŸ”„ CSV Upload Flow

  1. Admin uploads CSV file (Date, Rep, Customer, Product_Category, Revenue, Cost, Territory)
  2. UploadZone validates headers
  3. File uploaded to Supabase Storage
  4. Edge Function fetches β†’ parses β†’ batch inserts (500 rows/call)
  5. React Query auto-invalidates all dashboards
  6. All users see updated metrics

Processing Time: ~10 seconds for 2,000 rows


πŸ“Š Commission Calculation

Formula: (Revenue - Cost) Γ— 0.275

Example:

  • Revenue: $10,000
  • Cost: $7,000
  • Commission: ($10,000 - $7,000) Γ— 0.275 = $825

Calculated automatically in PostgreSQL using generated columns (always in sync).


πŸš€ Deployment

Production Ready

  • Build: 194 KB JS (60 KB gzipped)
  • Load time: <1 second
  • Vercel deployment: Push to main β†’ auto-deploys
  • Supabase free tier supports 2M monthly API calls

Steps (See DEPLOY.md for detailed guide)

  1. Create Supabase project
  2. Run 3 migrations
  3. Create storage bucket
  4. Deploy Edge Function
  5. Create test users
  6. Seed 1,981 rows
  7. Push to GitHub
  8. Import to Vercel
  9. Add env variables
  10. Done! πŸŽ‰

πŸ› οΈ Development

Local Development

npm run dev        # Start dev server on port 5173
npm run build      # Build for production
npm run preview    # Preview production build locally

Database

  • Supabase SQL console for queries
  • View migrations in supabase/migrations/
  • Edit Edge Function in supabase/functions/process-csv/

Adding Features

  • New pages: Add .tsx file in src/pages/
  • New queries: Add hook in src/hooks/useQueries.ts
  • Components: Reuse KPICard, DataTable, StatusBadge

πŸ“‹ Configuration

Environment Variables

VITE_SUPABASE_URL=https://your-project.supabase.co
VITE_SUPABASE_ANON_KEY=your-anon-key

Get these from:

  • Supabase Dashboard β†’ Settings β†’ API

Commission Rate

Currently hardcoded as 0.275 (27.5%) in:

  • Database schema: sales_rows.commission generated column
  • Edge Function: process-csv/index.ts (for future CSV rows)

To change: Update both locations and re-deploy Edge Function.


πŸ› Troubleshooting

Login Not Working

  • Check profiles table has a row for your email
  • Verify .env.local has correct VITE_SUPABASE_URL

CSV Upload Fails

  • Validate column headers (exact match required)
  • Check csv-uploads bucket exists in Supabase Storage
  • Verify Edge Function deployed: supabase functions list

Dashboard Shows No Data

  • Verify seed script completed (1,981 rows inserted)
  • Check profiles table has rep_name matching CSV "Rep" column
  • Verify RLS policies (Settings β†’ SQL β†’ Check policies)

See SETUP.md for detailed troubleshooting.


πŸ“š Documentation


🎯 Future Enhancements (Phase 3)

  • Date range filters (YTD vs custom)
  • Commission rate configuration form
  • Mobile responsive improvements
  • Chart visualizations (Recharts)
  • CSV upload automation (email attachment)
  • Custom branding (logo, colors)
  • Multi-language support
  • Real-time notifications for new orders

πŸ” Security Notes

  • RLS Enforced: Reps cannot query other reps' data (DB-layer security)
  • No Secrets in Code: Environment variables only
  • HTTPS Required: Use only for production
  • Session Management: Supabase Auth handles tokens
  • Backups: Enable in Supabase Settings β†’ Backups

πŸ“ž Support

Questions?

Found a bug?

  1. Check browser console for errors
  2. Check Supabase logs (Dashboard β†’ Logs)
  3. Check Vercel build logs (Deployments tab)

πŸ“„ License

Internal project for Bob's sales team.


Built with: React 18 β€’ Vite β€’ Supabase β€’ Tailwind CSS β€’ TypeScript

Status: βœ… Production ready

Last Updated: 2026-03-27


Quick Links

Next Step: Follow DEPLOY.md to go live!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors