All files / src/componentsV2/AccountProfile/AccountDetails AccountDetails.tsx

85% Statements 17/20
55.55% Branches 10/18
50% Functions 3/6
84.21% Lines 16/19

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                                                  5x 5x 5x 5x 5x 5x 5x 5x   5x   5x             5x   5x                   5x                                                                                                                                                                                                                             5x                                 35x                                 20x      
import { Box, Grid, Stack } from "@mui/material";
import { ArrowLineUpIcon } from "@phosphor-icons/react";
import GiveAvatar from "@shared/Avatar/GiveAvatar";
import GiveLink from "@shared/Link/GiveLink";
import { styled } from "@theme/v2/Provider";
import Email from "./Email";
import { FormProvider, useFormContext } from "react-hook-form";
import GiveDatePicker from "@shared/DatePicker/GiveDatePicker";
import { HFGiveInput } from "@shared/HFInputs/HFGiveInput/HFGiveInput";
import { HFGiveTelephone } from "@shared/HFInputs/HFGiveTelephone/HFGiveTelephone";
import { addSizeToImage } from "@components/UploadAvatar/UploadAvatar";
import { useAppSelector } from "@redux/hooks";
import { selectUser } from "@redux/slices/auth/auth";
import { useAccount } from "@hooks/common/useAccount";
import NiceModal from "@ebay/nice-modal-react";
import { EDIT_PROFILE_IMAGE_MODAL } from "modals/modal_names";
import {
  MAXIMUM_REQUIRED_AGE,
  MINIMUM_REQUIRED_AGE,
} from "@constants/constants";
import { subYears } from "date-fns";
import { useGetMerchantById } from "@hooks/enterprise-api/account/useGetMerchants";
import useCheckPAH from "@hooks/common/useCheckPAH";
 
export default function AccountDetails() {
  const methods = useFormContext();
  const values = methods?.watch();
  const { img, globalName } = useAppSelector(selectUser);
  const { handleChangeStatus, removeImage, userData } = useAccount();
  const { isApprovedPAH } = useGetMerchantById();
  const name = `${globalName?.firstName} ${globalName?.lastName}`;
  const imageUrl = addSizeToImage(img, "thumb");
  const { isLoggedInPAH } = useCheckPAH();
 
  const isOFACMatch = userData?.ofacCheckStatusName === "confirmed_match";
 
  const uploadActions = {
    onUpload: (file: File) => handleChangeStatus({ file }),
    onDelete: removeImage,
    canUpload: !isOFACMatch,
    canDelete: !isOFACMatch && !!imageUrl,
  };
 
  const isDisabledApproved = isOFACMatch || (isApprovedPAH && isLoggedInPAH);
 
  const handleUploadPhoto = () => {
    NiceModal.show(EDIT_PROFILE_IMAGE_MODAL, {
      defaultImageURL: imageUrl,
      rounded: false,
      subTitle: name,
      actions: uploadActions,
      thumbnailType: "avatar",
    });
  };
 
  const nodeList = [
    {
      node: (
        <Email
          email={userData?.pendingEmail || values?.email}
          status={userData?.pendingEmail ? "pending" : "verified"}
        />
      ),
      sm: 12,
      md: 12,
      lg: 12,
    },
    {
      node: (
        <StyledInput
          name="firstName"
          placeholder="First Name"
          label="First Name"
          color="primary"
          disabled={isDisabledApproved}
          fullWidth
          hidePlaceholder
        />
      ),
      sm: 12,
      md: 12,
      lg: 12,
    },
    {
      node: (
        <StyledInput
          name="lastName"
          label="Last Name"
          placeholder="Last Name"
          color="primary"
          disabled={isDisabledApproved}
          fullWidth
          hidePlaceholder
        />
      ),
      sm: 12,
      md: 12,
      lg: 12,
    },
    {
      node: (
        <GiveDatePicker
          name="date"
          label="Date of Birth"
          placeholder="Date of Birth"
          disableFuture
          maxDate={subYears(new Date(), MINIMUM_REQUIRED_AGE)}
          minDate={subYears(new Date(), MAXIMUM_REQUIRED_AGE)}
          onSetDate={(val) => {
            methods.setValue("date", val, { shouldDirty: true });
          }}
          disabled={isDisabledApproved}
          openYear={!values?.date}
          hidePlaceholder
        />
      ),
      sm: 12,
      md: 12,
      lg: 12,
    },
    {
      node: (
        <HFGiveTelephone
          label="Phone Number"
          placeholder="Phone Number"
          name="phone"
          disabled={isOFACMatch}
          data-testid="phoneNumber"
        />
      ),
      sm: 12,
      md: 12,
      lg: 12,
    },
    {
      node: (
        <StyledInput
          name="occupation"
          label="Job Title"
          placeholder="Job Title"
          disabled={isOFACMatch}
          fullWidth
          hidePlaceholder
        />
      ),
      sm: 12,
      md: 12,
      lg: 12,
    },
    {
      node: (
        <StyledInput
          name="employer"
          fullWidth
          type="text"
          label="Employer"
          placeholder="Employer"
          disabled={isOFACMatch}
          hidePlaceholder
        />
      ),
      sm: 12,
      md: 12,
      lg: 12,
    },
  ];
  return (
    <Box sx={{ width: "100%" }}>
      <FormProvider {...methods}>
        <Stack direction="row" gap="16px">
          <GiveAvatar size="56px" imageUrl={imageUrl} name={name} />
          <GiveLink
            Icon={ArrowLineUpIcon}
            color="secondary"
            sx={{ alignItems: "center" }}
            link="#"
            onClick={handleUploadPhoto}
          >
            Upload Photo
          </GiveLink>
        </Stack>
        <Grid mt={0.5} container rowSpacing="24px" columnSpacing={3}>
          {nodeList.map(({ node, lg, md, sm }, index) => (
            <Grid
              key={index}
              item
              xs={12}
              sm={sm || 6}
              md={md || sm || 6}
              lg={lg || md || sm || 6}
            >
              {node}
            </Grid>
          ))}
        </Grid>
      </FormProvider>
    </Box>
  );
}
 
const StyledInput = styled(HFGiveInput)(() => ({
  width: "100%",
}));