All files / app/features/team TeamSection.tsx

0% Statements 0/39
0% Branches 0/22
0% Functions 0/15
0% Lines 0/32

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 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189                                                                                                                                                                                                                                                                                                                                                                                         
import {
  Avatar as MuiAvatar,
  Card,
  CardContent,
  Grid,
  styled,
  Typography,
} from "@mui/material";
import { EmailIcon, GlobeIcon, LinkedInIcon, PinIcon } from "components/Icons";
import IconText from "components/IconText";
import StyledLink from "components/StyledLink";
import { GLOBAL } from "i18n/namespaces";
import { Volunteer } from "proto/public_pb";
import { useMemo } from "react";
import { useTranslation } from "react-i18next";
import { theme } from "theme";
 
const TeamMemberCard = styled(Card, {
  shouldForwardProp: (prop) => prop !== "memberType",
})<{ memberType?: "boardMember" | "pastMember" }>(({ memberType }) => ({
  height: `${memberType === "boardMember" ? 15 : 13}rem`,
  border: `1px solid${memberType === "pastMember" ? theme.palette.grey[50] : theme.palette.grey[400]}`,
}));
 
const TeamMemberCardContent = styled(CardContent)(() => ({
  display: "flex",
}));
 
const DetailDiv = styled("div")(() => ({
  display: "flex",
  flexFlow: "column nowrap",
  gap: theme.spacing(0.5),
  padding: theme.spacing(1, 2),
}));
 
const StyledAvatar = styled(MuiAvatar)(() => ({
  width: theme.typography.pxToRem(96),
  height: theme.typography.pxToRem(96),
}));
 
const StyledSection = styled("section")(() => ({
  display: "flex",
  flexFlow: "column nowrap",
  gap: theme.spacing(6),
  margin: theme.spacing(4, 0),
}));
 
const StyledGrid = styled(Grid)(() => ({
  justifyContent: "start",
  margin: theme.spacing(1, 0),
}));
 
const StyleBoardMemberBadgeText = styled("h3")(() => ({
  padding: theme.spacing(0.4, 0.8),
  borderRadius: "0.2rem",
  alignSelf: "start",
  backgroundColor: theme.palette.primary.main,
}));
 
function BoardMemberBadge() {
  const { t } = useTranslation([GLOBAL]);
 
  return (
    <Typography
      variant="h4"
      component={StyleBoardMemberBadgeText}
      color={theme.palette.common.white}
    >
      {t("team.board_member")}
    </Typography>
  );
}
 
interface MemberListProps {
  variant: "current" | "past";
  volunteers: Volunteer.AsObject[] | undefined;
}
 
function MemberList({ variant, volunteers }: MemberListProps) {
  Iif (!volunteers?.length) {
    return <></>;
  }
 
  return (
    <StyledGrid
      container
      maxWidth="xl"
      spacing={2}
      justifyContent="center"
      alignItems="stretch"
    >
      {volunteers?.map(
        ({
          name,
          isBoardMember,
          role,
          location,
          img,
          linkType,
          linkText,
          linkUrl,
        }) => {
          return (
            <Grid key={name} size={{ xs: 12, md: 6, lg: 4 }}>
              <TeamMemberCard
                key={name}
                memberType={
                  variant === "past"
                    ? "pastMember"
                    : isBoardMember
                      ? "boardMember"
                      : undefined
                }
                variant="outlined"
              >
                <TeamMemberCardContent>
                  <StyledAvatar alt={`Headshot of ${name}`} src={img} />
                  <DetailDiv>
                    <Typography variant={"h3"} component="h2">
                      {name}
                    </Typography>
                    {isBoardMember && <BoardMemberBadge />}
                    <Typography variant="body1">{role}</Typography>
                    <div>
                      <IconText icon={PinIcon} text={location} />
                      {linkUrl && (
                        <IconText
                          icon={
                            linkType === "linkedin"
                              ? LinkedInIcon
                              : linkType === "email"
                                ? EmailIcon
                                : GlobeIcon
                          }
                          text={
                            <Typography variant="body1">
                              <StyledLink href={linkUrl}>{linkText}</StyledLink>
                            </Typography>
                          }
                        />
                      )}
                    </div>
                  </DetailDiv>
                </TeamMemberCardContent>
              </TeamMemberCard>
            </Grid>
          );
        },
      )}
    </StyledGrid>
  );
}
 
interface TeamSectionProps {
  variant: "current" | "past";
  volunteers: Volunteer.AsObject[] | undefined;
}
function TeamSection({ variant, volunteers }: TeamSectionProps) {
  const sections = useMemo(() => {
    Iif (variant === "past") {
      return [volunteers];
    }
 
    return (volunteers ?? []).reduce<Volunteer.AsObject[][]>(
      (acc, curr) => {
        Iif (variant)
          if (curr.isBoardMember) {
            acc[0].push(curr);
          } else {
            acc[1].push(curr);
          }
 
        return acc;
      },
      [[], []],
    );
  }, [variant, volunteers]);
 
  return (
    <StyledSection>
      {sections.map((section, index) => (
        <MemberList key={index} volunteers={section} variant={variant} />
      ))}
    </StyledSection>
  );
}
 
export default TeamSection;