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 964x 4x 4x   4x   4x 4x     4x   114x       16x       55x                                                       114x                       114x                                                                      
import { 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;
}
 
export default function EventUsers({
  emptyState,
  error,
  hasNextPage,
  onSeeAllClick,
  userIds,
  title,
  layout = "list",
  isLoading,
  pagination,
  getUserMenuItems,
}: EventUsersProps) {
  const { t } = useTranslation([COMMUNITIES]);
 
  return (
    <StyledWrapper>
      <Typography variant="h2">{title}</Typography>
      <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>
  );
}