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

100% Statements 15/15
100% Branches 7/7
100% Functions 4/4
100% Lines 12/12

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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120  4x 4x 4x   4x   4x 4x     4x   136x       16x       66x                                                         136x                         136x                                                                                                                
import { Group } from "@mui/icons-material";
import { Box, Card, styled, Typography } from "@mui/material";
import Button from "components/Button";
import CursorPagination from "components/CursorPagination";
import { EllipsisMenuItem } from "components/EllipsisMenu";
import UsersList from "components/UsersList";
import { RpcError } from "grpc-web";
import { useTranslation } from "i18n";
import { COMMUNITIES } from "i18n/namespaces";
import { LiteUser } from "proto/api_pb";
import { ListEventAttendeesRes } from "proto/events_pb";
import { theme } from "theme";
 
const StyledWrapper = styled(Card)(() => ({
  padding: theme.spacing(2),
}));
 
const StyledSeeAllButton = styled(Button)(() => ({
  justifySelf: "center",
}));
 
const PaginationWrapper = styled("div")(({ theme }) => ({
  display: "flex",
  justifyContent: "center",
  width: "100%",
  marginTop: theme.spacing(2),
  marginBottom: theme.spacing(2),
}));
 
export interface EventUsersProps {
  emptyState: string;
  error: RpcError | null;
  hasNextPage?: boolean;
  onSeeAllClick?(): void;
  userIds: number[] | undefined;
  title: string;
  layout?: "list" | "grid";
  isLoading?: boolean;
  pagination?: {
    pageIndex: number;
    currentPage: ListEventAttendeesRes.AsObject | undefined;
    handlePreviousPageClick: () => void;
    handleNextPageClick: () => void;
  };
  getUserMenuItems?: (
    user: LiteUser.AsObject,
  ) => EllipsisMenuItem[] | undefined;
  attendeeCount?: number;
}
 
export default function EventUsers({
  emptyState,
  error,
  hasNextPage,
  onSeeAllClick,
  userIds,
  title,
  layout = "list",
  isLoading,
  pagination,
  getUserMenuItems,
  attendeeCount,
}: EventUsersProps) {
  const { t } = useTranslation([COMMUNITIES]);
 
  return (
    <StyledWrapper>
      <Box sx={{ display: "flex", alignItems: "center" }}>
        <Typography variant="h2" component="span" role="heading">
          {title}
        </Typography>
        <Group
          fontSize="small"
          sx={{
            marginLeft: "0.5ch",
            marginRight: "0.15rem",
            color: "var(--mui-palette-text-secondary)",
          }}
        />
        <Box
          component="span"
          sx={{
            color: "var(--mui-palette-text-secondary)",
            fontSize: "0.85em",
          }}
        >
          {attendeeCount?.toString()}
        </Box>
      </Box>
      <UsersList
        error={error}
        userIds={userIds}
        endChildren={
          hasNextPage && !pagination ? (
            <StyledSeeAllButton onClick={onSeeAllClick}>
              {t("communities:see_all")}
            </StyledSeeAllButton>
          ) : null
        }
        emptyListChildren={
          <Typography variant="body1">{emptyState}</Typography>
        }
        getUserMenuItems={getUserMenuItems}
        layout={layout}
      />
      {pagination ? (
        <PaginationWrapper>
          <CursorPagination
            hasNextPage={Boolean(pagination.currentPage?.nextPageToken)}
            onNext={pagination.handleNextPageClick}
            hasPreviousPage={pagination.pageIndex > 0}
            onPrevious={pagination.handlePreviousPageClick}
            isLoading={isLoading}
          />
        </PaginationWrapper>
      ) : null}
    </StyledWrapper>
  );
}