All files / src/components/organizer/PartnerManagement PartnerOverviewStats.tsx

100% Statements 14/14
91.66% Branches 11/12
100% Functions 3/3
100% Lines 14/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123          4x               4x               4x 10x     10x 1x       3x                             9x 1x                           8x 10x 10x               10x                                                                               40x                        
import React from 'react';
import { Box, Card, CardContent, Skeleton, Typography } from '@mui/material';
import Grid from '@mui/material/Grid';
import { usePartnerStatistics } from '@/hooks/usePartners';
 
const tierEmojis: Record<string, string> = {
  STRATEGIC: '🏆',
  PLATINUM: '💎',
  GOLD: '🥇',
  SILVER: '🥈',
  BRONZE: '🥉',
};
 
const tierLabels: Record<string, string> = {
  STRATEGIC: 'Strategic',
  PLATINUM: 'Platinum',
  GOLD: 'Gold',
  SILVER: 'Silver',
  BRONZE: 'Bronze',
};
 
export const PartnerOverviewStats: React.FC = () => {
  const { data: statistics, isLoading, isError, error } = usePartnerStatistics();
 
  // Loading state
  if (isLoading) {
    return (
      <Box sx={{ mb: 3 }}>
        <Grid container spacing={2}>
          {[1, 2, 3].map((i) => (
            <Grid size={{ xs: 12, sm: 6, md: 3 }} key={i}>
              <Card>
                <CardContent>
                  <Skeleton variant="text" width="60%" />
                  <Skeleton variant="text" width="40%" height={40} />
                </CardContent>
              </Card>
            </Grid>
          ))}
        </Grid>
      </Box>
    );
  }
 
  // Error state
  if (isError) {
    return (
      <Box sx={{ mb: 3 }}>
        <Card>
          <CardContent>
            <Typography color="error">
              Failed to load statistics: {error?.message || 'Unknown error'}
            </Typography>
          </CardContent>
        </Card>
      </Box>
    );
  }
 
  // Default values when no data
  const totalPartners = statistics?.totalPartners || 0;
  const activePartners = statistics?.activePartners || 0;
  const tierDistribution = statistics?.tierCounts || {
    STRATEGIC: 0,
    PLATINUM: 0,
    GOLD: 0,
    SILVER: 0,
    BRONZE: 0,
  };
 
  return (
    <Box sx={{ mb: 3 }}>
      <Grid container spacing={2}>
        {/* Total Partners */}
        <Grid size={{ xs: 12, sm: 6, md: 3 }}>
          <Card data-testid="stats-total-partners">
            <CardContent>
              <Typography color="text.secondary" variant="body2" gutterBottom>
                Total Partners
              </Typography>
              <Typography variant="h4" component="div">
                {totalPartners}
              </Typography>
            </CardContent>
          </Card>
        </Grid>
 
        {/* Active Partners */}
        <Grid size={{ xs: 12, sm: 6, md: 3 }}>
          <Card data-testid="stats-active-partners">
            <CardContent>
              <Typography color="text.secondary" variant="body2" gutterBottom>
                Active Partners
              </Typography>
              <Typography variant="h4" component="div">
                {activePartners}
              </Typography>
            </CardContent>
          </Card>
        </Grid>
 
        {/* Tier Distribution */}
        <Grid size={{ xs: 12, sm: 6, md: 3 }}>
          <Card data-testid="stats-tier-distribution">
            <CardContent>
              <Typography color="text.secondary" variant="body2" gutterBottom>
                Tier Distribution
              </Typography>
              <Box>
                {Object.entries(tierDistribution).map(([tier, count]) => (
                  <Typography key={tier} variant="body2" component="div">
                    {tierEmojis[tier]} {tierLabels[tier]}: {count}
                  </Typography>
                ))}
              </Box>
            </CardContent>
          </Card>
        </Grid>
      </Grid>
    </Box>
  );
};