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.
- Follow DEPLOY.md for step-by-step production setup (~1 hour)
- After setup, open your Vercel URL
- Login with test credentials
- Upload daily CSV files to sync sales data
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- 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
- 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
- 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
- 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
- Supabase PostgreSQL with Row-Level Security (RLS)
- 4 SQL views for aggregated metrics
- Edge Functions (Deno) for CSV processing
- Automatic Commission Calculation (generated columns)
- 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
~/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
- 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
- Reps see only their own rows
- Managers see all rows
- Admins control uploads
- Admin uploads CSV file (Date, Rep, Customer, Product_Category, Revenue, Cost, Territory)
- UploadZone validates headers
- File uploaded to Supabase Storage
- Edge Function fetches β parses β batch inserts (500 rows/call)
- React Query auto-invalidates all dashboards
- All users see updated metrics
Processing Time: ~10 seconds for 2,000 rows
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).
- 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
- Create Supabase project
- Run 3 migrations
- Create storage bucket
- Deploy Edge Function
- Create test users
- Seed 1,981 rows
- Push to GitHub
- Import to Vercel
- Add env variables
- Done! π
npm run dev # Start dev server on port 5173
npm run build # Build for production
npm run preview # Preview production build locally- Supabase SQL console for queries
- View migrations in
supabase/migrations/ - Edit Edge Function in
supabase/functions/process-csv/
- New pages: Add
.tsxfile insrc/pages/ - New queries: Add hook in
src/hooks/useQueries.ts - Components: Reuse
KPICard,DataTable,StatusBadge
VITE_SUPABASE_URL=https://your-project.supabase.co
VITE_SUPABASE_ANON_KEY=your-anon-key
Get these from:
- Supabase Dashboard β Settings β API
Currently hardcoded as 0.275 (27.5%) in:
- Database schema:
sales_rows.commissiongenerated column - Edge Function:
process-csv/index.ts(for future CSV rows)
To change: Update both locations and re-deploy Edge Function.
- Check profiles table has a row for your email
- Verify .env.local has correct VITE_SUPABASE_URL
- Validate column headers (exact match required)
- Check csv-uploads bucket exists in Supabase Storage
- Verify Edge Function deployed:
supabase functions list
- 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.
- DEPLOY.md β Step-by-step deployment (1 hour, ~1000 lines)
- SETUP.md β Detailed configuration guide
- PHASE-1-COMPLETE.md β Foundation architecture
- PHASE-2-COMPLETE.md β Dashboard build details
- 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
- 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
Questions?
- Check the relevant guide: DEPLOY.md, SETUP.md, or PHASE-2-COMPLETE.md
- Review Supabase docs: https://supabase.com/docs
- Check React docs: https://react.dev
Found a bug?
- Check browser console for errors
- Check Supabase logs (Dashboard β Logs)
- Check Vercel build logs (Deployments tab)
Internal project for Bob's sales team.
Built with: React 18 β’ Vite β’ Supabase β’ Tailwind CSS β’ TypeScript
Status: β Production ready
Last Updated: 2026-03-27
- π Deployment Guide
- π§ Setup Instructions
- π Architecture
- π» Local Dev
Next Step: Follow DEPLOY.md to go live!