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 | 1x 1x 12x 12x 7x 12x 7x 5x 1x 4x 1x 3x 6x 6x 6x | /**
* Status History Timeline Component (Story 5.4)
*
* Timeline displaying speaker status change history
* Features:
* - Chronological timeline of all status transitions
* - Shows timestamp, organizer, status change, and reason
* - Material-UI Timeline components
* - i18n support (German/English)
* - Color-coded status indicators
*/
import React from 'react';
import {
Timeline,
TimelineItem,
TimelineSeparator,
TimelineConnector,
TimelineContent,
TimelineDot,
TimelineOppositeContent,
} from '@mui/lab';
import { Paper, Typography, Box, Chip, Alert } from '@mui/material';
import { useTranslation } from 'react-i18next';
import { useQuery } from '@tanstack/react-query';
import { speakerStatusService } from '@/services/speakerStatusService';
import { format } from 'date-fns';
import type { SpeakerWorkflowState } from '@/types/speakerPool.types';
export interface StatusHistoryTimelineProps {
speakerId: string;
eventCode: string;
}
// Status color mapping — keyed to the 8 ADR-009 §0.1 states. Partial Record so a
// future state-enum addition surfaces as a missing-key compile error.
const STATUS_COLORS: Partial<Record<SpeakerWorkflowState, string>> = {
IDENTIFIED: '#9e9e9e',
CONTACTED: '#ffc107',
READY: '#ff9800',
INVITED: '#03a9f4',
ACCEPTED: '#4caf50',
CONTENT_SUBMITTED: '#2196f3',
QUALITY_REVIEWED: '#00bcd4',
DECLINED: '#f44336',
};
export const StatusHistoryTimeline: React.FC<StatusHistoryTimelineProps> = ({
speakerId,
eventCode,
}) => {
const { t } = useTranslation(['organizer', 'common']);
const {
data: history,
isLoading,
error,
} = useQuery({
queryKey: ['speakerStatusHistory', eventCode, speakerId],
queryFn: () => speakerStatusService.getStatusHistory(eventCode, speakerId),
});
if (isLoading) {
return (
<Box sx={{ p: 2 }}>
<Typography>{t('common:loading')}</Typography>
</Box>
);
}
if (error) {
return (
<Alert severity="error" sx={{ m: 2 }}>
{t('common:errors.loadFailed')}
</Alert>
);
}
if (!history || history.length === 0) {
return (
<Box sx={{ p: 2 }}>
<Typography color="text.secondary">{t('organizer:speakerStatus.noHistory')}</Typography>
</Box>
);
}
return (
<Box>
<Typography variant="h6" sx={{ mb: 2 }}>
{t('organizer:speakerStatus.historyTitle')}
</Typography>
<Timeline position="alternate">
{history.map((item, index) => {
const isLast = index === history.length - 1;
const statusColor = STATUS_COLORS[item.newStatus || 'IDENTIFIED'];
return (
<TimelineItem key={item.id}>
<TimelineOppositeContent sx={{ m: 'auto 0' }} variant="body2" color="text.secondary">
{item.changedAt ? format(new Date(item.changedAt), 'PPp') : ''}
</TimelineOppositeContent>
<TimelineSeparator>
<TimelineDot sx={{ bgcolor: statusColor }} />
{!isLast && <TimelineConnector />}
</TimelineSeparator>
<TimelineContent sx={{ py: '12px', px: 2 }}>
<Paper elevation={2} sx={{ p: 2 }}>
<Box sx={{ display: 'flex', gap: 1, mb: 1, flexWrap: 'wrap' }}>
<Chip
label={t(`organizer:speakerStatus.${item.previousStatus}`)}
size="small"
sx={{
backgroundColor: STATUS_COLORS[item.previousStatus || 'IDENTIFIED'],
color: 'white',
}}
/>
<Typography variant="body2" sx={{ alignSelf: 'center' }}>
→
</Typography>
<Chip
label={t(`organizer:speakerStatus.${item.newStatus}`)}
size="small"
sx={{
backgroundColor: statusColor,
color: 'white',
}}
/>
</Box>
<Typography variant="caption" color="text.secondary" display="block">
{t('organizer:speakerStatus.changedBy')}: {item.changedByUsername}
</Typography>
{item.changeReason && (
<Typography variant="body2" sx={{ mt: 1, fontStyle: 'italic' }}>
"{item.changeReason}"
</Typography>
)}
</Paper>
</TimelineContent>
</TimelineItem>
);
})}
</Timeline>
</Box>
);
};
export default StatusHistoryTimeline;
|