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 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | 3x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 1x 1x 1x 52x 52x 1x 52x 3x | /**
* EventCard Component
*
* Story 2.5.3 - Task 8b (GREEN Phase)
* AC: 1 (Event Dashboard Display)
* Wireframe: docs/wireframes/story-1.16-event-management-dashboard.md v1.0
*
* Displays individual event card with:
* - Progress bar (workflow completion %)
* - Workflow step indicator (Step X/16)
* - Event details (title, date, type)
* - Quick actions (Edit, Topic Selection)
* - Status badge
* - Attendee information
*/
import React, { useState } from 'react';
import {
Card,
CardContent,
CardActions,
Typography,
LinearProgress,
IconButton,
Box,
Stack,
} from '@mui/material';
import {
Edit as EditIcon,
Event as EventIcon,
People as PeopleIcon,
Topic as TopicIcon,
} from '@mui/icons-material';
import { useTranslation } from 'react-i18next';
import { useNavigate } from 'react-router-dom';
import { format } from 'date-fns';
import { de, enUS } from 'date-fns/locale';
import type { Event, EventUI } from '@/types/event.types';
import {
WORKFLOW_STATE_ORDER,
getWorkflowProgress,
getProgressColor,
getWorkflowStateLabel,
getWorkflowStepNumber,
} from '@/utils/workflow/workflowState';
interface EventCardProps {
event: Event;
onEdit?: (eventCode: string) => void;
onCardClick?: (eventCode: string) => void;
}
export const EventCard: React.FC<EventCardProps> = ({ event, onEdit, onCardClick }) => {
const { t, i18n } = useTranslation('events');
const navigate = useNavigate();
const [isHovered, setIsHovered] = useState(false);
const eventUI = event as EventUI;
// Use new workflowState from Story 5.1a (fallback to 'CREATED')
const workflowState = event.workflowState || 'CREATED';
const progress = getWorkflowProgress(workflowState);
const workflowLabel = getWorkflowStateLabel(workflowState, t);
const workflowStep = getWorkflowStepNumber(workflowState);
const capacity = eventUI.capacity || event.venueCapacity || 0;
const attendeePercentage =
capacity > 0 ? Math.round((event.currentAttendeeCount / capacity) * 100) : 0;
const locale = i18n.language === 'de' ? de : enUS;
const eventDate = eventUI.eventDate || event.date;
const formattedDate = format(new Date(eventDate), 'dd MMM yyyy', { locale });
const handleEdit = (e: React.MouseEvent) => {
e.preventDefault();
e.stopPropagation();
onEdit?.(event.eventCode);
};
const handleSelectTopic = (e: React.MouseEvent) => {
e.preventDefault();
e.stopPropagation();
const targetUrl = `/organizer/topics?eventCode=${event.eventCode}`;
console.log('[EventCard] handleSelectTopic called', {
eventCode: event.eventCode,
targetUrl,
event: event.title,
});
navigate(targetUrl);
};
const handleCardClick = () => {
onCardClick?.(event.eventCode);
};
return (
<Card
data-testid={`event-card-${event.eventCode}`}
onMouseEnter={() => setIsHovered(true)}
onMouseLeave={() => setIsHovered(false)}
onClick={handleCardClick}
tabIndex={0}
aria-label={t('dashboard.eventCard.ariaLabel', { title: event.title })}
sx={{
height: '100%',
display: 'flex',
flexDirection: 'column',
transition: 'all 0.3s ease',
cursor: 'pointer',
'&:hover': {
boxShadow: 6,
transform: 'translateY(-4px)',
},
}}
>
{/* Theme Image Banner (Story 2.5.3a) */}
{event.themeImageUrl && (
<Box
component="img"
src={event.themeImageUrl}
alt={`${event.title} theme`}
sx={{
width: '100%',
height: 160,
objectFit: 'cover',
borderTopLeftRadius: 'inherit',
borderTopRightRadius: 'inherit',
}}
/>
)}
<CardContent data-testid="event-card-content" sx={{ flexGrow: 1 }}>
{/* Header with Event Code */}
<Stack direction="row" justifyContent="flex-start" alignItems="center" mb={2}>
<Typography variant="caption" color="text.secondary" fontWeight="medium">
#{event.eventCode}
</Typography>
</Stack>
{/* Event Title */}
<Typography variant="h6" component="h3" gutterBottom noWrap data-testid="event-title">
{event.title}
</Typography>
{/* Event Details */}
<Stack spacing={1} mb={2}>
<Stack direction="row" spacing={1} alignItems="center">
<EventIcon fontSize="small" color="action" />
<Typography variant="body2" color="text.secondary">
{formattedDate}
{eventUI.eventType && ` • ${t(`dashboard.eventType.${eventUI.eventType}`)}`}
</Typography>
</Stack>
<Stack direction="row" spacing={1} alignItems="center">
<PeopleIcon fontSize="small" color="action" />
<Typography
variant="body2"
color={attendeePercentage === 100 ? 'error' : 'text.secondary'}
>
{event.currentAttendeeCount}/{capacity} ({attendeePercentage}% full)
</Typography>
</Stack>
</Stack>
{/* Workflow Progress (Story 5.1a) */}
<Box>
{/* Status and Step Indicator */}
<Stack direction="row" justifyContent="space-between" alignItems="center" mb={0.5}>
<Typography variant="caption" color="text.secondary">
{workflowLabel}
</Typography>
<Typography
variant="caption"
color="text.secondary"
data-testid="workflow-step-indicator"
>
{t('workflow.stepIndicator', {
current: workflowStep,
total: WORKFLOW_STATE_ORDER.length,
})}
</Typography>
</Stack>
{/* Progress Bar with Percentage */}
<Stack direction="row" alignItems="center" spacing={1}>
<LinearProgress
data-testid="workflow-progress-bar"
variant="determinate"
value={progress}
color={getProgressColor(progress)}
aria-label={t('dashboard.eventCard.progressAriaLabel', { progress })}
aria-valuenow={progress}
sx={{ height: 8, borderRadius: 1, flex: 1 }}
/>
<Typography
variant="caption"
fontWeight="bold"
sx={{ minWidth: '35px' }}
data-testid="progress-percentage"
>
{progress}%
</Typography>
</Stack>
</Box>
</CardContent>
{/* Quick Actions */}
<CardActions sx={{ justifyContent: 'flex-end', px: 2, pb: 2 }}>
{isHovered && (
<>
<IconButton
size="small"
onClick={handleSelectTopic}
aria-label={t('dashboard.eventCard.selectTopicAriaLabel', { title: event.title })}
color="primary"
>
<TopicIcon />
</IconButton>
<IconButton
size="small"
onClick={handleEdit}
aria-label={t('dashboard.eventCard.editAriaLabel', { title: event.title })}
color="primary"
data-testid="event-card-edit-button"
>
<EditIcon />
</IconButton>
</>
)}
</CardActions>
</Card>
);
};
|