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

100% Statements 15/15
100% Branches 19/19
100% Functions 3/3
100% Lines 14/14

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 844x 4x 4x 4x     4x 4x 4x   26x                                                   4x                     173x 173x   173x                 225x 225x                                              
import { Card, CircularProgress, Typography } from "@material-ui/core";
import Alert from "components/Alert";
import Button from "components/Button";
import UserSummary from "components/UserSummary";
import useUsers from "features/userQueries/useUsers";
import { RpcError } from "grpc-web";
import { useTranslation } from "i18n";
import { COMMUNITIES } from "i18n/namespaces";
import makeStyles from "utils/makeStyles";
 
const useStyles = makeStyles((theme) => ({
  cardSection: {
    padding: theme.spacing(2),
  },
  users: {
    display: "grid",
    marginBlockStart: theme.spacing(2),
    rowGap: theme.spacing(1),
  },
  seeAllButton: {
    justifySelf: "center",
  },
}));
 
export interface EventUsersProps {
  emptyState: string;
  error: RpcError | null;
  hasNextPage?: boolean;
  isLoading: boolean;
  isUsersRefetching: boolean;
  onSeeAllClick?(): void;
  userIds: number[];
  users: ReturnType<typeof useUsers>["data"];
  title: string;
}
 
export default function EventUsers({
  emptyState,
  error,
  hasNextPage,
  isLoading,
  isUsersRefetching,
  onSeeAllClick,
  userIds,
  users,
  title,
}: EventUsersProps) {
  const { t } = useTranslation([COMMUNITIES]);
  const classes = useStyles();
 
  return (
    <Card className={classes.cardSection}>
      <Typography variant="h2">{title}</Typography>
      {error && <Alert severity="error">{error.message}</Alert>}
      {isLoading && !users ? (
        <CircularProgress />
      ) : userIds.length > 0 && users ? (
        <div className={classes.users}>
          {userIds.map((userId) => {
            const user = users.get(userId);
            return user || isUsersRefetching ? (
              <UserSummary
                headlineComponent="h3"
                key={userId}
                nameOnly
                smallAvatar
                user={user}
              />
            ) : null;
          })}
          {hasNextPage && (
            <Button className={classes.seeAllButton} onClick={onSeeAllClick}>
              {t("communities:see_all")}
            </Button>
          )}
        </div>
      ) : (
        userIds.length === 0 &&
        !error && <Typography variant="body1">{emptyState}</Typography>
      )}
    </Card>
  );
}