All files / app/features/profile/view UserOverview.tsx

100% Statements 32/32
75% Branches 12/16
100% Functions 7/7
100% Lines 26/26

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 1654x 4x 4x 4x 4x 4x 4x       4x 4x 4x 4x 4x 4x   4x 4x 4x   26x                   4x         26x               52x                 26x                 15x                           26x                     26x       26x 26x                                                                                                                                                
import { Card, CardActions, Link, styled, Typography } from "@mui/material";
import Avatar from "components/Avatar";
import BarWithHelp from "components/Bar/BarWithHelp";
import Divider from "components/Divider";
import { CouchIcon, LocationIcon } from "components/Icons";
import IconText from "components/IconText";
import StrongVerificationBadge from "components/StrongVerificationBadge";
import {
  hostingStatusLabels,
  meetupStatusLabels,
} from "features/profile/constants";
import { useTranslation } from "i18n";
import { GLOBAL, PROFILE } from "i18n/namespaces";
import { HostingStatus, MeetupStatus } from "proto/api_pb";
import React from "react";
import { routeToUser } from "routes";
 
import { useProfileUser } from "../hooks/useProfileUser";
import { Badges } from "./Badges";
import { ReferencesLastActiveLabels, ResponseRateLabel } from "./userLabels";
 
const StyledCard = styled(Card)(({ theme }) => ({
  flexShrink: 0,
  borderRadius: theme.shape.borderRadius * 2,
  padding: theme.spacing(3),
  [theme.breakpoints.down("sm")]: {
    marginBottom: theme.spacing(1),
    width: "100%",
  },
}));
 
const StyledAvatarContainer = styled("div")({
  maxWidth: "75%",
  margin: "0 auto",
});
 
const StyledWrapper = styled("div")(({ theme }) => ({
  marginTop: theme.spacing(2),
  "& h1": {
    textAlign: "center",
    marginBottom: theme.spacing(0.5),
  },
}));
 
const StyledIntro = styled(Typography)(({ theme }) => ({
  display: "flex",
  justifyContent: "center",
  wordBreak: "break-word",
  overflowWrap: "break-word",
  textAlign: "center",
  marginBottom: theme.spacing(1),
}));
 
const StyledLink = styled(Link)(({ theme }) => ({
  display: "flex",
  justifyContent: "center",
  wordBreak: "break-word",
  overflowWrap: "break-word",
  textAlign: "center",
  marginBottom: theme.spacing(1),
}));
 
const StyledCardActions = styled(CardActions)(({ theme }) => ({
  flexDirection: "column",
  justifyContent: "center",
  alignItems: "stretch",
  gap: theme.spacing(0.2),
  padding: theme.spacing(0.5),
  "& > *": {
    margin: theme.spacing(0.5),
  },
  "& > :not(:first-of-type)": {
    marginLeft: theme.spacing(0.5),
  },
}));
 
const StyledInfo = styled("div")(({ theme }) => ({
  marginTop: theme.spacing(0.5),
}));
 
type UserOverviewProps = {
  showHostAndMeetAvailability: boolean;
  actions?: React.ReactNode;
};
 
// @todo: move this into /components and decouple it from features/profile because it's used
//        from the dashboard as well
export default function UserOverview({
  showHostAndMeetAvailability,
  actions,
}: UserOverviewProps) {
  const { t } = useTranslation([GLOBAL, PROFILE]);
  const user = useProfileUser();
 
  return (
    <StyledCard>
      <StyledAvatarContainer>
        <Avatar user={user} highRes grow />
      </StyledAvatarContainer>
 
      <StyledWrapper>
        <StyledIntro variant="h1">
          <span>
            {user.name}
            {user.hasStrongVerification ? <StrongVerificationBadge /> : null}
          </span>
        </StyledIntro>
        <StyledLink href={routeToUser(user.username)} variant="body1">
          @{user.username}
        </StyledLink>
        <StyledIntro variant="body1">{user.city}</StyledIntro>
        <Badges user={user} />
      </StyledWrapper>
 
      <Divider />
 
      {actions && <StyledCardActions>{actions}</StyledCardActions>}
 
      {showHostAndMeetAvailability && (
        <>
          <IconText
            icon={CouchIcon}
            text={
              hostingStatusLabels(t)[
                user.hostingStatus || HostingStatus.HOSTING_STATUS_UNKNOWN
              ]
            }
          />
          <IconText
            icon={LocationIcon}
            text={
              meetupStatusLabels(t)[
                user.meetupStatus || MeetupStatus.MEETUP_STATUS_UNKNOWN
              ]
            }
          />
        </>
      )}
 
      {Boolean(showHostAndMeetAvailability || actions) && (
        <Divider spacing={3} />
      )}
 
      {process.env.NEXT_PUBLIC_IS_VERIFICATION_ENABLED && (
        <>
          <BarWithHelp
            value={user.communityStanding || 0}
            label={t("global:community_standing")}
            description={t("global:community_standing_description")}
          />
          <BarWithHelp
            value={user.verification || 0}
            label={t("global:verification_score")}
            description={t("global:verification_score_description")}
          />
        </>
      )}
      <StyledInfo>
        <ReferencesLastActiveLabels user={user} />
        <ResponseRateLabel user={user} />
      </StyledInfo>
    </StyledCard>
  );
}