import type { VisitAttendee, VisitHost } from '../../types/visitInvitation'; const ANSWER: Record = { accepted: 'Accepted', declined: 'Declined', awaiting: 'Not answered yet', }; /** "2 accepted, 1 declined, 1 not answered yet", from the same list it summarises and nothing else. */ export const attendeeCounts = (attendees: VisitAttendee[]): string => { const count = (response: VisitAttendee['response']) => attendees.filter((attendee) => attendee.response === response).length; return [ [count('accepted'), 'accepted'], [count('declined'), 'declined'], [count('awaiting'), 'not answered yet'], ].filter(([n]) => (n as number) > 0).map(([n, word]) => `${n} ${word}`).join(', '); }; /** * Who hosts the visit and who else it has invited, read-only, exactly as the server lets an invitee see them: names * and saved answers. Nothing here can be changed, and nobody's reason or contact is shown. A name the server could not * read is said to be unavailable, never guessed. Renders nothing when the server sent neither (an older server, or a * caller not shown the team). */ export const VisitAttendeeSummary = ({ host, attendees }: { host?: VisitHost | null; attendees?: VisitAttendee[] }) => { if (host === undefined && attendees === undefined) return null; return (
{host &&

Hosted by {host.display ?? a host whose name is not available}

} {attendees && attendees.length === 0 &&

No one else is invited yet.

} {attendees && attendees.length > 0 && (
Also invited: {attendeeCounts(attendees)}
    {attendees.map((attendee, index) => (
  • {attendee.display ?? Name not available} {ANSWER[attendee.response]}
  • ))}
)}
); }; export default VisitAttendeeSummary;