All files / src/components/organizer/UserManagement UserDetailModal.tsx

90% Statements 9/10
57.14% Branches 12/21
66.66% Functions 2/3
90% Lines 9/10

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                                                        1x 11x 11x   11x 1x     10x           10x             10x                                                                                                           20x                                                                                                                                                    
import React from 'react';
import {
  Dialog,
  DialogTitle,
  DialogContent,
  DialogActions,
  Button,
  Box,
  Typography,
  Avatar,
  Chip,
  Grid,
  Divider,
  IconButton,
} from '@mui/material';
import { Close as CloseIcon } from '@mui/icons-material';
import { useTranslation } from 'react-i18next';
import { useBreakpoints } from '@/hooks/useBreakpoints';
import CompanyLogo from '@/components/shared/Company/CompanyLogo';
import type { User } from '../../../types/user.types';
 
interface UserDetailModalProps {
  user: User | null;
  open: boolean;
  onClose: () => void;
  onEdit?: (user: User) => void;
}
 
const UserDetailModal: React.FC<UserDetailModalProps> = ({ user, open, onClose, onEdit }) => {
  const { t } = useTranslation('userManagement');
  const { isMobile } = useBreakpoints();
 
  if (!user) {
    return null;
  }
 
  const fullName = `${user.firstName} ${user.lastName}`;
 
  // Role badge configuration
  const roleConfig: Record<
    string,
    { label: string; color: 'primary' | 'secondary' | 'success' | 'info' }
  > = {
    ORGANIZER: { label: t('common:role.organizer'), color: 'primary' },
    SPEAKER: { label: t('common:role.speaker'), color: 'secondary' },
    PARTNER: { label: t('common:role.partner'), color: 'success' },
    ATTENDEE: { label: t('common:role.attendee'), color: 'info' },
  };
 
  return (
    <Dialog
      open={open}
      onClose={onClose}
      maxWidth="md"
      fullWidth
      fullScreen={isMobile}
      aria-labelledby="user-detail-dialog-title"
    >
      <DialogTitle id="user-detail-dialog-title">
        <Box display="flex" justifyContent="space-between" alignItems="center">
          <Typography variant="h6">{t('modal.userDetail.title')}</Typography>
          <IconButton edge="end" color="inherit" onClick={onClose} aria-label="close">
            <CloseIcon />
          </IconButton>
        </Box>
      </DialogTitle>
 
      <DialogContent dividers>
        <Grid container spacing={3}>
          {/* Profile Section */}
          <Grid size={12}>
            <Box display="flex" alignItems="center" gap={2}>
              <Avatar src={user.profilePictureUrl} alt={fullName} sx={{ width: 80, height: 80 }}>
                {user.firstName[0]}
                {user.lastName[0]}
              </Avatar>
              <Box>
                <Typography variant="h5">{fullName}</Typography>
                <Typography variant="body2" color="text.secondary">
                  {user.email}
                </Typography>
                <Box mt={1}>
                  <Chip
                    label={user.active ? t('filters.status.active') : t('filters.status.inactive')}
                    color={user.active ? 'success' : 'default'}
                    size="small"
                  />
                </Box>
              </Box>
            </Box>
          </Grid>
 
          <Grid size={12}>
            <Divider />
          </Grid>
 
          {/* Roles Section */}
          <Grid size={{ xs: 12, sm: 6 }}>
            <Typography variant="subtitle2" color="text.secondary" gutterBottom>
              {t('table.headers.roles')}
            </Typography>
            <Box display="flex" gap={1} flexWrap="wrap">
              {user.roles.map((role) => (
                <Chip
                  key={role}
                  label={roleConfig[role]?.label || role}
                  color={roleConfig[role]?.color || 'default'}
                />
              ))}
            </Box>
          </Grid>
 
          {/* Company Section */}
          {user.company && (
            <Grid size={{ xs: 12, sm: 6 }}>
              <Typography variant="subtitle2" color="text.secondary" gutterBottom>
                {t('table.headers.company')}
              </Typography>
              {user.company.name ? (
                <CompanyLogo companyName={user.company.name} variant="avatar" avatarSize={32} />
              ) : (
                <Typography variant="body1">{user.company.displayName}</Typography>
              )}
              {user.company.website && (
                <Typography variant="body2" color="text.secondary">
                  {user.company.website}
                </Typography>
              )}
            </Grid>
          )}
 
          {/* Bio Section */}
          {user.bio && (
            <Grid size={12}>
              <Typography variant="subtitle2" color="text.secondary" gutterBottom>
                {t('modal.userDetail.bio', 'Bio')}
              </Typography>
              <Typography variant="body2" sx={{ whiteSpace: 'pre-wrap' }}>
                {user.bio}
              </Typography>
            </Grid>
          )}
 
          {/* Additional Info Section */}
          <Grid size={12}>
            <Divider />
          </Grid>
 
          <Grid size={{ xs: 12, sm: 6 }}>
            <Typography variant="subtitle2" color="text.secondary" gutterBottom>
              {t('modal.userDetail.createdAt')}
            </Typography>
            <Typography variant="body2">{new Date(user.createdAt).toLocaleDateString()}</Typography>
          </Grid>
 
          <Grid size={{ xs: 12, sm: 6 }}>
            <Typography variant="subtitle2" color="text.secondary" gutterBottom>
              {t('modal.userDetail.updatedAt')}
            </Typography>
            <Typography variant="body2">{new Date(user.updatedAt).toLocaleDateString()}</Typography>
          </Grid>
        </Grid>
      </DialogContent>
 
      <DialogActions>
        <Button onClick={onClose} variant="outlined">
          {t('common:actions.close')}
        </Button>
        <Button variant="contained" color="primary" onClick={() => user && onEdit && onEdit(user)}>
          {t('common:actions.edit')}
        </Button>
      </DialogActions>
    </Dialog>
  );
};
 
export default UserDetailModal;