All files / src/app/HamburgerMenu/ProfileSettings ProfileRoleDisplay.tsx

100% Statements 61/61
100% Branches 4/4
100% Functions 1/1
100% Lines 61/61

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 621x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 3x 3x 3x 3x 3x 3x 3x 13x 13x 13x 13x 13x  
/**
 * @file ProfileRoleDisplay.tsx
 * @module app/HamburgerMenu/ProfileSettings/ProfileRoleDisplay
 *
 * @summary
 * Displays user's role with optional demo badge.
 * Capitalizes role name and shows demo indicator if applicable.
 *
 * @example
 * ```tsx
 * <ProfileRoleDisplay role="admin" isDemo={true} />
 * ```
 */
 
import { Box, Stack, Typography, Chip } from '@mui/material';
import { useTranslation } from 'react-i18next';
 
interface ProfileRoleDisplayProps {
  /** User's role string */
  role?: string;
 
  /** Whether this is a demo account */
  isDemo: boolean;
}
 
/**
 * Profile role display component.
 *
 * Displays capitalized role with demo badge if user is on demo account.
 *
 * @param props - Component props
 * @returns JSX element displaying role and demo badge
 */
export default function ProfileRoleDisplay({ role, isDemo }: ProfileRoleDisplayProps) {
  const { t } = useTranslation(['common', 'auth']);
 
  // Capitalize role: convert "admin" to "Admin"
  const displayRole = role ? role.charAt(0).toUpperCase() + role.slice(1) : 'User';
 
  return (
    <Box>
      <Typography variant="caption" color="text.secondary" sx={{ fontWeight: 600 }}>
        {t('common:role', 'Role')}
      </Typography>
      <Stack direction="row" spacing={0.5} alignItems="center">
        <Typography variant="body2">
          {displayRole}
        </Typography>
        {isDemo && (
          <Chip
            size="small"
            label={t('auth:demoBadge', 'DEMO')}
            color="warning"
            variant="outlined"
            sx={{ height: 20 }}
          />
        )}
      </Stack>
    </Box>
  );
}