Unified Dashboard

Overview

The Unified Earnings Dashboard combines all three earning systems (Referrals, Rewards, and Points) into a single, cohesive interface. It provides users with a complete view of their earnings, progress, and engagement across the Med.Fun platform.

Purpose

Instead of navigating to separate dashboards for each system, users can:

  • View total earnings from all sources in one place

  • Switch between detailed views using tabs

  • Track combined pending and claimed amounts

  • Refresh all data simultaneously

  • Access all earning systems from a single modal

Architecture

Component Structure

UnifiedEarningsDashboard
├── useEarnings (combined data hook)
│   ├── useReferrals
│   ├── useRewards
│   └── usePoints
├── Tabs (navigation)
│   ├── Overview (aggregated summary)
│   ├── Rewards (trading cashback)
│   ├── Referrals (commission earnings)
│   └── Points (gamification)
└── Mobile/Desktop Rendering
    ├── Sheet (mobile)
    └── Dialog (desktop)

Data Flow

useEarnings Hook

Location: /src/hooks/useEarnings.tsx

Purpose

Combines data from all three earning systems into a single, easy-to-use hook.

Implementation

Usage

Benefits

  1. Single Import: Only need to import one hook

  2. Aggregated Data: Automatic calculation of combined totals

  3. Unified Loading: Single loading state for all systems

  4. Batch Refresh: Refresh all data with one function call

  5. Type Safety: Full TypeScript support

  6. Performance: Hooks run in parallel, not sequentially

Component: UnifiedEarningsDashboard

Location: /src/components/UnifiedEarningsDashboard.tsx

Props

Features

  • Responsive Design: Adapts to mobile and desktop

  • Tabbed Interface: Easy navigation between systems

  • Real-time Updates: Live data via Supabase subscriptions

  • Summary Cards: Quick overview of key metrics

  • Detailed Views: Deep dive into each system

  • Claim Actions: Direct access to claim buttons

  • Progress Tracking: Visual progress bars for tiers and levels

Tab Structure

Tab 1: Overview (Default)

Purpose: High-level summary of all earning systems

Content:

  • Total Earnings card (referral + rewards)

  • Pending Earnings card (claimable amount)

  • Claimed Earnings card (historical)

  • Trading Rewards summary (tier, cashback)

  • Referral Program summary (code, tier, earnings)

  • Points & Level summary (level, progress, badges)

UI Layout:

Tab 2: Rewards

Purpose: Detailed trading rewards and cashback

Content:

  • Current tier badge

  • Pending cashback with claim button

  • Claimed cashback total

  • Trading stats (volume, trade count)

  • Progress to next tier

  • Cashback earnings history

Features:

  • Interactive claim button (min $1.00)

  • Color-coded tier display

  • Progress bar with percentage

  • Scrollable earnings list

  • Real-time balance updates

Tab 3: Referrals

Purpose: Referral program details

Content:

  • Referral code display

  • Share link functionality

  • Total earnings (pending + claimed)

  • Referral stats (active referrals, volume)

  • Current tier and benefits

  • Referral list

Features:

  • Copy referral link button

  • Share via native share API

  • Generate custom code option

  • Claim earnings button

  • Tier progress visualization

Tab 4: Points

Purpose: Gamification and level progression

Content:

  • Current level display

  • Total points earned

  • Progress to next level

  • Earned badges showcase

  • Recent point transactions

  • Action history

Features:

  • Animated progress bar

  • Badge gallery

  • Transaction timeline

  • Point breakdown by action

  • Level-up celebrations

Responsive Behavior

Desktop (≥768px)

  • Renders as Dialog component

  • Modal overlay with backdrop blur

  • Fixed width (600px max-width)

  • Centered on screen

  • Smooth fade-in animation

Mobile (<768px)

  • Renders as Sheet component (bottom sheet)

  • Slides up from bottom

  • Full-width layout

  • Swipe-to-dismiss gesture

  • Native-feeling interactions

Implementation

Integration Examples

Open Dashboard from Button

Display Earnings Summary

Quick Claim Button

User Flows

Flow 1: Check Total Earnings

Flow 2: Claim Pending Earnings

Flow 3: Track Progress

Flow 4: Deep Dive into System

Best Practices

For Developers

1. Always pass userWallet prop:

2. Handle loading states:

3. Use aggregated totals:

4. Refresh all data together:

For Product

1. Overview tab as default

  • Most users want quick summary first

  • Deep dives available via tabs

  • Progressive disclosure of information

2. Clear visual hierarchy

  • Largest numbers (totals) most prominent

  • System summaries secondary

  • Details accessible via tabs

3. Action buttons prominent

  • Claim buttons easily accessible

  • Clear minimum thresholds

  • Disabled state when below minimum

4. Mobile-first design

  • Bottom sheet on mobile feels native

  • Swipe gestures intuitive

  • Content scrolls within sheet

Performance Optimization

Data Fetching

Memoization

Real-time Updates

  • Each system manages its own subscriptions

  • Updates propagate through hook return values

  • No additional subscriptions needed in dashboard

  • Automatic UI refresh on data changes

Troubleshooting

Data Not Loading

Check:

  1. Is userWallet prop provided?

  2. Check browser console for errors

  3. Verify all three hooks working individually

  4. Check network tab for failed requests

Totals Incorrect

Check:

  1. Verify useEarnings aggregation logic

  2. Check individual hook return values

  3. Ensure all values are numbers (not strings)

  4. Look for null/undefined values

Check:

  1. Is open prop being controlled?

  2. Verify onOpenChange callback

  3. Check for z-index conflicts

  4. Ensure Dialog/Sheet components imported

Tabs Not Switching

Check:

  1. Verify Tabs defaultValue matches TabsTrigger values

  2. Check for JavaScript errors

  3. Ensure TabsContent value matches triggers

  4. Test individual tab components

Future Enhancements

Potential Features

  • Export Data: Download earnings report as CSV/PDF

  • Analytics: Charts showing earnings over time

  • Notifications: Alert when claim threshold reached

  • Filters: Filter earnings by date range

  • Search: Search transaction history

  • Breakdown: Pie chart of earnings by source

  • Goals: Set and track earning goals

  • Achievements: Special badges for milestones

Technical Improvements

  • Caching: Cache aggregated data for faster loads

  • Pagination: Paginate transaction histories

  • Virtual Scrolling: For long transaction lists

  • Optimistic Updates: Instant UI feedback

  • Offline Support: View data while offline

  • Progressive Loading: Load overview first, details later

Last updated

Was this helpful?