All files / src/components/ProfileMenu/Tabs ProfileAccountDetails.tsx

94.11% Statements 16/17
68.42% Branches 13/19
66.66% Functions 2/3
94.11% Lines 16/17

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 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234                                                              7x 353x 353x 353x 353x   353x   353x   353x   353x     353x       353x                                                                                                                                                                                                                                                     353x 87x           266x                                           2394x                                                     7x        
// mui
import Box from "@mui/material/Box";
import Grid from "@mui/material/Grid";
import useMediaQuery from "@mui/material/useMediaQuery";
import { NameInput } from "@common/BusinessProfileInputs";
import { useTheme } from "@mui/material/styles";
 
import { BirthDatePicker } from "@common/DatePickers";
import { RHFInput, RHFTelInput } from "@common/Input";
// localization
import { useTranslation } from "react-i18next";
import { namespaces } from "localization/resources/i18n.constants";
// hooks
import { useAccount } from "hooks/common/useAccount";
 
import { BEStatus } from "../components/NewEmailCard";
// redux
import { useAppSelector } from "@redux/hooks";
import { useGetUser } from "@services/api/onboarding/user";
import { selectUser } from "@redux/slices/auth/auth";
 
import FadeUpWrapper from "@components/animation/FadeUpWrapper";
import MyAccountLoadingSkeleton from "@components/Settings/MyAccount/MyAccountLoadingSkeleton";
import NewEmailCard from "../components/NewEmailCard";
import { useCustomTheme } from "@theme/hooks/useCustomTheme";
import AvatarUpload from "@components/AvatarUpload/AvatarUpload";
import avatarImage from "@assets/images/AvatarReb.png";
import { WithTooltipWrapper } from "@common/Menu/NewDropdownMenu";
import { addSizeToImage } from "@utils/image.helpers";
import { OFAC_MATCH_MESSAGE } from "@constants/permissions";
 
export const ProfileAccountDetails = () => {
  const { isMobileView } = useCustomTheme();
  const theme = useTheme();
  const isDesktop = useMediaQuery(theme.breakpoints.up("sm"));
  const { t } = useTranslation(namespaces.pages.settings);
 
  const { handleChangeStatus, removeImage } = useAccount();
 
  const { img, globalName } = useAppSelector(selectUser);
 
  const { data, isLoading } = useGetUser();
 
  const isOFACMatch = data?.ofacCheckStatusName === "confirmed_match";
 
  const checkPendingEmail =
    typeof data?.pendingEmail === "string"
      ? data.pendingEmail.length > 0
      : false;
 
  const nodeList = [
    {
      node: (
        <NewEmailCard
          email={data?.email}
          status={{ status: BEStatus.valid }}
          disabled={isOFACMatch}
        />
      ),
      hidden: checkPendingEmail,
      sm: 12,
      md: 12,
      lg: 12,
    },
    {
      node: (
        <NewEmailCard
          email={data?.pendingEmail}
          status={{ status: BEStatus.pending }}
          disabled={isOFACMatch}
        />
      ),
      hidden: !checkPendingEmail,
      sm: 12,
      md: 12,
      lg: 12,
    },
    {
      node: <></>,
      hidden: !checkPendingEmail,
      sm: 12,
      md: 12,
      lg: 12,
    },
    {
      node: (
        <NameInput
          name="firstName"
          placeholder="Enter First Name"
          label={t("firstName")}
          disabled={isOFACMatch}
        />
      ),
      sm: 12,
      md: 12,
      lg: 12,
      hasTooltip: true,
    },
    {
      node: (
        <NameInput
          name="lastName"
          placeholder="Enter Last Name"
          label={t("lastName")}
          disabled={isOFACMatch}
        />
      ),
      sm: 12,
      md: 12,
      lg: 12,
      hasTooltip: true,
    },
    {
      node: (
        <BirthDatePicker
          name="date"
          placeholder="MM/DD/YYYY"
          fullWidth
          label={t("dateOfBirth")}
          disabled={isOFACMatch}
        />
      ),
      sm: 12,
      md: 12,
      lg: 12,
      hasTooltip: true,
    },
    {
      node: (
        <RHFTelInput
          name="phone"
          fullWidth
          label={t("phoneNumber")}
          disabled={isOFACMatch}
        />
      ),
      sm: 12,
      md: 12,
      lg: 12,
      hasTooltip: true,
    },
    {
      node: (
        <NameInput
          name="occupation"
          placeholder="Add Job Title"
          label={"Job Title"}
          disabled={isOFACMatch}
        />
      ),
      sm: 12,
      md: 12,
      lg: 12,
      hasTooltip: true,
    },
    {
      node: (
        <RHFInput
          name="employer"
          fullWidth
          type="text"
          placeholder="Add Employer"
          label={t("employer")}
          disabled={isOFACMatch}
        />
      ),
      sm: 12,
      md: 12,
      lg: 12,
      hasTooltip: true,
    },
  ];
 
  if (isLoading)
    return (
      <Box sx={{ width: "100%" }}>
        <MyAccountLoadingSkeleton />
      </Box>
    );
 
  return (
    <Box
      sx={{ ...container, ...(!isDesktop && { padding: "3px 8px" }) }}
      data-testid="account-details-container"
    >
      <FadeUpWrapper delay={100}>
        <AvatarUpload
          rounded
          size={isMobileView ? 80 : 56}
          defaultImageURL={addSizeToImage(img, "thumb")}
          onUpload={(file: File) => handleChangeStatus({ file })}
          onDelete={removeImage}
          subTitle={`${globalName?.firstName} ${globalName?.lastName}`}
          placeholder={avatarImage}
          canUpload
          canDelete
          disabled={isOFACMatch}
          tooltipMessage={OFAC_MATCH_MESSAGE}
        />
      </FadeUpWrapper>
      <Grid mt={0.5} container rowSpacing={2} columnSpacing={3}>
        {nodeList.map(({ node, hidden, lg, md, sm, hasTooltip }, index) => (
          <Grid
            key={index}
            item
            xs={12}
            sm={sm || 6}
            md={md || sm || 6}
            lg={lg || md || sm || 6}
            sx={{ ...(hidden && { display: "none" }) }}
          >
            <WithTooltipWrapper
              hasTooltip={!!hasTooltip}
              tooltipProps={{
                show: isOFACMatch,
                message: OFAC_MATCH_MESSAGE,
              }}
            >
              <FadeUpWrapper delay={100 + 50 * (index + 1)}>
                {node}
              </FadeUpWrapper>
            </WithTooltipWrapper>
          </Grid>
        ))}
      </Grid>
    </Box>
  );
};
 
const container = {
  width: "100%",
  padding: "8px 16px",
};