import React from 'react'; import { makeStyles } from '@material-ui/core/styles'; import { Card, CardHeader, CardContent, CardActions, Button } from '@material-ui/core'; import { FiberManualRecord as RunningIcon, Close as FailedIcon, Done as CompleteIcon, Timer as NotStartedIcon } from '@material-ui/icons'; import { Event } from '../../types'; import requests from '../../requests'; import { useAuth } from '../../hooks/useAuth'; interface PropTypes { event: Event; mutate: () => void; } const useStyles = makeStyles(theme => ({ actions: { display: 'flex', justifyContent: 'space-between' }, title: { display: 'flex', alignItems: 'center', justifyContent: 'flex-start', '& svg': { marginLeft: theme.spacing(1) } }, running: { color: theme.palette.warning.main }, complete: { color: theme.palette.success.main }, })); const EventCard: React.FC = ({ event, mutate }) => { const classes = useStyles(); const { user } = useAuth(); const { status, data: { name, date, participants, conferenceId, attendanceId } } = event; const joined = participants.findIndex(x => x === user?.username) >= 0; const handleJoin = () => { if (user) { const update = { data: { participants: [...participants, user.username] }}; return requests .patch(`/events/${event._id}`, update) .then(() => mutate()); } }; const handleRemove = () => { return requests .delete(`/events/${event._id}`) .then(() => mutate()); }; const title = (
{name} {status === 'running' && } {status === 'complete' && } {status === 'failed' && } {!status && }
); return ( {conferenceId &&
ConferenceID: {conferenceId}
} {attendanceId &&
AttendanceID: {attendanceId}
}
Participants ({participants?.length || 0} / 3)
    {participants?.map(username => (
  • {username} {username === user?.username && (you)}
  • ))}
{!joined && (participants?.length || 0) < 3 && ( )}
); }; export default EventCard;