All files / src/components/AlertMessage AlertMessage.tsx

100% Statements 12/12
100% Branches 6/6
100% Functions 1/1
100% Lines 12/12

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                  61x   61x   50x 50x   9x 9x   1x 1x   1x 1x     61x   61x                    
import Typography from '@mui/material/Typography';
import { useTheme } from '@mui/material/styles';
 
interface AlertMessageProps {
  message: string;
  severity: 'error' | 'success' | 'info';
}
 
export default function AlertMessage({ message, severity }: AlertMessageProps) {
  const theme = useTheme();
  let colorValue: string;
  switch (severity) {
    case 'error':
      colorValue = theme.palette.error.main;
      break;
    case 'success':
      colorValue = theme.palette.success.main;
      break;
    case 'info':
      colorValue = theme.palette.info.main;
      break;
    default:
      colorValue = theme.palette.text.primary;
      break;
  }
 
  const roleValue = severity === 'error' ? 'alert' : 'status';
 
  return (
    <Typography
      variant="body2"
      sx={{ mb: 2, textAlign: 'center', color: colorValue }}
      role={roleValue}
    >
      {message}
    </Typography>
  );
}