All files / src/components/organizer/SpeakerOutreach OutreachHistoryTimeline.tsx

0% Statements 0/29
0% Branches 0/26
0% Functions 0/5
0% Lines 0/29

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                                                                                                                                                                                                                                                                                                                                           
/**
 * Outreach History Timeline Component (Story 5.3 - Task 6b)
 *
 * Displays chronological contact history for a speaker
 * Features:
 * - Material-UI Timeline visualization
 * - Contact method icons
 * - Chronological ordering (most recent first)
 * - Contact notes display
 * - Organizer information
 */
 
import React from 'react';
import {
  Timeline,
  TimelineItem,
  TimelineSeparator,
  TimelineConnector,
  TimelineContent,
  TimelineDot,
  TimelineOppositeContent,
} from '@mui/lab';
import { Box, Typography, Paper, Chip, Alert } from '@mui/material';
import { Email as EmailIcon, Phone as PhoneIcon, Person as PersonIcon } from '@mui/icons-material';
import { BATbernLoader } from '@components/shared/BATbernLoader';
import { useTranslation } from 'react-i18next';
import { format } from 'date-fns';
import { useSpeakerOutreachHistory } from '../../../hooks/useSpeakerOutreach';
import type { ContactMethod } from '../../../types/speakerOutreach.types';
 
interface OutreachHistoryTimelineProps {
  eventCode: string;
  speakerId: string;
}
 
const OutreachHistoryTimeline: React.FC<OutreachHistoryTimelineProps> = ({
  eventCode,
  speakerId,
}) => {
  const { t } = useTranslation('organizer');
  const { data: history, isLoading, isError } = useSpeakerOutreachHistory(eventCode, speakerId);
 
  // Get icon for contact method
  const getContactMethodIcon = (method: ContactMethod) => {
    switch (method) {
      case 'email':
        return <EmailIcon />;
      case 'phone':
        return <PhoneIcon />;
      case 'in_person':
        return <PersonIcon />;
      default:
        return <EmailIcon />;
    }
  };
 
  // Get color for TimelineDot (supports 'grey' but not 'default')
  const getTimelineDotColor = (
    method: ContactMethod
  ): 'primary' | 'secondary' | 'success' | 'grey' => {
    switch (method) {
      case 'email':
        return 'primary';
      case 'phone':
        return 'secondary';
      case 'in_person':
        return 'success';
      default:
        return 'grey';
    }
  };
 
  // Get color for Chip (supports 'default' but not 'grey')
  const getChipColor = (method: ContactMethod): 'primary' | 'secondary' | 'success' | 'default' => {
    switch (method) {
      case 'email':
        return 'primary';
      case 'phone':
        return 'secondary';
      case 'in_person':
        return 'success';
      default:
        return 'default';
    }
  };
 
  if (isLoading) {
    return (
      <Box display="flex" justifyContent="center" p={3}>
        <BATbernLoader size={64} />
      </Box>
    );
  }
 
  if (isError) {
    return (
      <Alert severity="error">{t('speakerOutreach.markContactedModal.error.loadHistory')}</Alert>
    );
  }
 
  if (!history || history.length === 0) {
    return (
      <Paper sx={{ p: 3 }}>
        <Typography variant="body2" color="text.secondary" textAlign="center">
          No contact history yet
        </Typography>
      </Paper>
    );
  }
 
  return (
    <Box>
      <Typography variant="h6" gutterBottom>
        {t('speakerOutreach.contactHistory')}
      </Typography>
 
      <Timeline position="right" data-testid="outreach-timeline">
        {history.map((item, index) => (
          <TimelineItem key={item.id}>
            <TimelineOppositeContent color="text.secondary" sx={{ flex: 0.3 }}>
              <Typography variant="caption" display="block">
                {format(new Date(item.contactDate), 'MMM dd, yyyy')}
              </Typography>
              <Typography variant="caption" display="block">
                {format(new Date(item.contactDate), 'h:mm a')}
              </Typography>
            </TimelineOppositeContent>
 
            <TimelineSeparator>
              <TimelineDot color={getTimelineDotColor(item.contactMethod)}>
                {getContactMethodIcon(item.contactMethod)}
              </TimelineDot>
              {index < history.length - 1 && <TimelineConnector />}
            </TimelineSeparator>
 
            <TimelineContent>
              <Paper elevation={1} sx={{ p: 2, mb: 2 }}>
                <Box display="flex" gap={1} mb={1} alignItems="center">
                  <Chip
                    label={t(
                      `speakerOutreach.markContactedModal.method.${item.contactMethod === 'in_person' ? 'inPerson' : item.contactMethod}`
                    )}
                    size="small"
                    color={getChipColor(item.contactMethod)}
                  />
                  <Typography variant="caption" color="text.secondary">
                    by {item.organizerUsername}
                  </Typography>
                </Box>
 
                {item.notes && (
                  <Typography variant="body2" color="text.secondary">
                    {item.notes}
                  </Typography>
                )}
              </Paper>
            </TimelineContent>
          </TimelineItem>
        ))}
      </Timeline>
    </Box>
  );
};
 
export default OutreachHistoryTimeline;