All files / app/features/communities/events EventAttendeesDialog.tsx

100% Statements 17/17
100% Branches 14/14
100% Functions 3/3
100% Lines 16/16

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 842x 2x 2x           2x 2x 2x 2x   2x   2x               2x         108x                   108x           108x                             46x   46x                           2x                
import Alert from "components/Alert";
import Button from "components/Button";
import CircularProgress from "components/CircularProgress";
import {
  Dialog,
  DialogActions,
  DialogContent,
  DialogTitle,
} from "components/Dialog";
import UserSummary from "components/UserSummary";
import { useTranslation } from "i18n";
import { COMMUNITIES } from "i18n/namespaces";
 
import { useEventAttendees } from "./hooks";
 
export const ATTENDEES_DIALOG_LABEL_ID = "attendees";
 
interface EventAttendeesDialogProps {
  eventId: number;
  open: boolean;
  onClose(): void;
}
 
export default function EventAttendeesDialog({
  eventId,
  onClose,
  open,
}: EventAttendeesDialogProps) {
  const { t } = useTranslation([COMMUNITIES]);
  const {
    error,
    fetchNextPage,
    hasNextPage,
    isAttendeesRefetching,
    isFetchingNextPage,
    isLoading,
    attendeesIds,
    attendees,
  } = useEventAttendees({
    enabled: open,
    eventId,
    type: "all",
  });
 
  return (
    <Dialog
      aria-labelledby={ATTENDEES_DIALOG_LABEL_ID}
      open={open}
      onClose={onClose}
    >
      <DialogTitle id={ATTENDEES_DIALOG_LABEL_ID}>
        {t("communities:attendees")}
      </DialogTitle>
      <DialogContent>
        {error && <Alert severity="error">{error.message}</Alert>}
        {isLoading ? (
          <CircularProgress />
        ) : !!attendeesIds.length && attendees ? (
          attendeesIds.map((id) => {
            const user = attendees.get(id);
 
            return user || isAttendeesRefetching ? (
              <UserSummary
                headlineComponent="h3"
                key={id}
                nameOnly
                smallAvatar
                user={user}
              />
            ) : null;
          })
        ) : null}
      </DialogContent>
      {hasNextPage && (
        <DialogActions>
          <Button loading={isFetchingNextPage} onClick={() => fetchNextPage()}>
            {t("communities:load_more_attendees")}
          </Button>
        </DialogActions>
      )}
    </Dialog>
  );
}