All files / src/components/shared/Company CompanyCard.tsx

81.81% Statements 9/11
90.62% Branches 29/32
60% Functions 3/5
81.81% Lines 9/11

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 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192                                                  7x         97x   97x 2x     97x 2x 2x 2x       97x                                                                                                                                                                                                                                                                                                        
/**
 * CompanyCard Component
 *
 * Individual company card display with:
 * - Company logo (CloudFront CDN via ?include=logo)
 * - Verified status (✅)
 * - Company details (name, industry)
 *
 * Story: 2.5.1 - Company Management Frontend
 */
 
import React from 'react';
import { Card, CardContent, CardActionArea, Typography, Box, Chip, Link } from '@mui/material';
import BusinessIcon from '@mui/icons-material/Business';
import LanguageIcon from '@mui/icons-material/Language';
import CategoryIcon from '@mui/icons-material/Category';
import { useTranslation } from 'react-i18next';
import type { CompanyListItem } from '@/types/company.types';
 
export interface CompanyCardProps {
  company: CompanyListItem;
  onClick: (companyId: string) => void;
  viewMode?: 'grid' | 'list';
}
 
export const CompanyCard: React.FC<CompanyCardProps> = ({
  company,
  onClick,
  viewMode = 'grid',
}) => {
  const { t } = useTranslation('common');
 
  const handleClick = () => {
    onClick(company.name);
  };
 
  const handleKeyDown = (event: React.KeyboardEvent) => {
    Eif (event.key === 'Enter' || event.key === ' ') {
      event.preventDefault();
      onClick(company.name);
    }
  };
 
  return (
    <Card
      data-testid={`company-card-${company.name}`}
      sx={{
        height: '100%',
        display: 'flex',
        flexDirection: 'column',
      }}
    >
      <CardActionArea
        onClick={handleClick}
        onKeyDown={handleKeyDown}
        role="button"
        aria-label={t('company.viewDetails', { name: company.displayName || company.name })}
        tabIndex={0}
        sx={{
          height: '100%',
          display: 'flex',
          flexDirection: viewMode === 'grid' ? 'column' : 'row',
          alignItems: 'flex-start',
        }}
      >
        {/* Logo Section */}
        <Box
          sx={{
            p: 2,
            display: 'flex',
            justifyContent: 'center',
            alignItems: 'center',
            minHeight: viewMode === 'grid' ? 180 : 120,
          }}
        >
          {company.logo?.url ? (
            <Box
              component="img"
              src={company.logo.url}
              alt={`${company.name} logo`}
              loading="lazy"
              data-testid="company-logo"
              sx={{
                maxWidth: viewMode === 'grid' ? 150 : 100,
                maxHeight: viewMode === 'grid' ? 150 : 100,
                objectFit: 'contain',
              }}
            />
          ) : (
            <Box
              data-testid="company-logo-fallback"
              sx={{
                width: viewMode === 'grid' ? 150 : 100,
                height: viewMode === 'grid' ? 150 : 100,
                bgcolor: 'grey.200',
                borderRadius: 1,
                display: 'flex',
                justifyContent: 'center',
                alignItems: 'center',
              }}
            >
              <BusinessIcon sx={{ fontSize: 60, color: 'grey.500' }} />
            </Box>
          )}
        </Box>
 
        {/* Content Section */}
        <CardContent sx={{ flexGrow: 1, width: '100%' }}>
          {/* Badges Row */}
          {company.isVerified && (
            <Box sx={{ mb: 1 }}>
              <Chip
                label={`✅ ${t('company.badges.verified')}`}
                size="small"
                aria-label={t('company.badges.verified')}
                sx={{ height: 20, fontSize: '0.75rem' }}
              />
            </Box>
          )}
 
          {/* Company Name (display name preferred) */}
          <Typography
            variant="h6"
            component="h2"
            gutterBottom
            sx={{
              fontSize: '1rem',
              fontWeight: 600,
              overflow: 'hidden',
              textOverflow: 'ellipsis',
              whiteSpace: 'nowrap',
            }}
          >
            {company.displayName || company.name}
          </Typography>
 
          {/* Legal Name (if different from display name) */}
          {company.displayName && company.displayName !== company.name && (
            <Typography
              variant="body2"
              color="text.secondary"
              sx={{
                fontSize: '0.875rem',
                overflow: 'hidden',
                textOverflow: 'ellipsis',
                whiteSpace: 'nowrap',
                mb: 1,
              }}
            >
              {t('company.fields.legalName', { name: company.name })}
            </Typography>
          )}
 
          {/* Industry */}
          {company.industry && (
            <Box sx={{ display: 'flex', alignItems: 'center', gap: 0.5, mb: 0.5 }}>
              <CategoryIcon sx={{ fontSize: 16, color: 'text.secondary' }} />
              <Typography variant="body2" color="text.secondary">
                {company.industry}
              </Typography>
            </Box>
          )}
 
          {/* Website */}
          {company.website && (
            <Box
              sx={{ display: 'flex', alignItems: 'center', gap: 0.5 }}
              onClick={(e) => e.stopPropagation()}
            >
              <LanguageIcon sx={{ fontSize: 16, color: 'text.secondary' }} />
              <Link
                href={company.website}
                target="_blank"
                rel="noopener noreferrer"
                variant="body2"
                sx={{
                  overflow: 'hidden',
                  textOverflow: 'ellipsis',
                  whiteSpace: 'nowrap',
                }}
                onClick={(e) => e.stopPropagation()}
              >
                {company.website.replace(/^https?:\/\/(www\.)?/, '')}
              </Link>
            </Box>
          )}
        </CardContent>
      </CardActionArea>
    </Card>
  );
};