|
| 1 | +import { Link } from 'react-router-dom'; |
| 2 | + |
| 3 | +interface CompetitionsTabProps { |
| 4 | + competitions: ApiCompetition[]; |
| 5 | + assignmentStatus: Record<string, boolean> | undefined; |
| 6 | + isCheckingAssignments: boolean; |
| 7 | +} |
| 8 | + |
| 9 | +const formatCompetitionDates = (competition: ApiCompetition) => { |
| 10 | + const start = new Date(`${competition.start_date}T00:00:00`); |
| 11 | + const end = new Date(`${competition.end_date}T00:00:00`); |
| 12 | + |
| 13 | + if (competition.start_date === competition.end_date) { |
| 14 | + return start.toLocaleDateString(undefined, { |
| 15 | + month: 'short', |
| 16 | + day: 'numeric', |
| 17 | + year: 'numeric', |
| 18 | + }); |
| 19 | + } |
| 20 | + |
| 21 | + return `${start.toLocaleDateString(undefined, { |
| 22 | + month: 'short', |
| 23 | + day: 'numeric', |
| 24 | + })} - ${end.toLocaleDateString(undefined, { |
| 25 | + month: 'short', |
| 26 | + day: 'numeric', |
| 27 | + year: 'numeric', |
| 28 | + })}`; |
| 29 | +}; |
| 30 | + |
| 31 | +export function CompetitionsTab({ |
| 32 | + competitions, |
| 33 | + assignmentStatus, |
| 34 | + isCheckingAssignments, |
| 35 | +}: CompetitionsTabProps) { |
| 36 | + if (competitions.length === 0) { |
| 37 | + return <p className="type-body-sm text-muted">No upcoming competitions.</p>; |
| 38 | + } |
| 39 | + |
| 40 | + return ( |
| 41 | + <div className="space-y-2"> |
| 42 | + {competitions.map((competition) => { |
| 43 | + const hasAssignments = assignmentStatus?.[competition.id]; |
| 44 | + const statusText = |
| 45 | + hasAssignments == null && isCheckingAssignments |
| 46 | + ? 'Checking assignments' |
| 47 | + : hasAssignments |
| 48 | + ? 'Assignments generated' |
| 49 | + : 'No assignments yet'; |
| 50 | + |
| 51 | + return ( |
| 52 | + <Link |
| 53 | + key={competition.id} |
| 54 | + to={`/competitions/${competition.id}`} |
| 55 | + className="block rounded-md border border-tertiary-weak bg-panel px-3 py-2 shadow-sm hover-bg-tertiary"> |
| 56 | + <div className="flex items-start justify-between gap-3"> |
| 57 | + <div className="min-w-0 space-y-1"> |
| 58 | + <div className="type-label text-default">{competition.name}</div> |
| 59 | + <div className="type-body-sm text-subtle"> |
| 60 | + {competition.city}, {competition.country_iso2} -{' '} |
| 61 | + {formatCompetitionDates(competition)} |
| 62 | + </div> |
| 63 | + </div> |
| 64 | + <span |
| 65 | + className={ |
| 66 | + hasAssignments |
| 67 | + ? 'shrink-0 text-right type-body-sm text-green-600' |
| 68 | + : 'shrink-0 text-right type-body-sm text-muted' |
| 69 | + }> |
| 70 | + {statusText} |
| 71 | + </span> |
| 72 | + </div> |
| 73 | + </Link> |
| 74 | + ); |
| 75 | + })} |
| 76 | + </div> |
| 77 | + ); |
| 78 | +} |
0 commit comments