All files / src/features/GiveSignup/components OrganizationDetails.tsx

82.35% Statements 14/17
84.21% Branches 16/19
40% Functions 2/5
82.35% Lines 14/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                                        1x                 1x           26x                             26x           26x       26x         26x           26x   26x           26x                 26x     26x                                                                                                                                                     26x                                                 130x                                    
import { Box, Grid, Stack } from "@mui/material";
// form
import { FormProvider } from "react-hook-form";
import { EDIT_PROFILE_IMAGE_MODAL } from "modals/modal_names";
import NiceModal from "@ebay/nice-modal-react";
import { BUSINESS_PURPOSE_FIELD } from "@constants/constants";
import { generateNameLabelPlaceholder } from "../helpers";
import { HFGiveInput } from "@shared/HFInputs/HFGiveInput/HFGiveInput";
import GiveText from "@shared/Text/GiveText";
import GiveLink from "@shared/Link/GiveLink";
import { HFCheckbox } from "@shared/HFInputs/HFGiveCheckbox/HFGiveCheckbox";
import SignupNavigation from "./SignupNavigation";
import GiveBusinessTypeSelect from "@common/BusinessProfileInputs/GiveBusinessTypeSelect";
import GiveTaxIdInput from "@shared/GiveInputs/GiveTaxIdInput";
import GiveThumbnail from "@shared/Thumbnail/GiveThumbnail";
import useFetchImage from "@hooks/useFetchImage";
import { useSignupOrganizationDetails } from "../hooks/useSignupOrganizationDetails";
import { useCustomThemeV2 } from "@theme/hooks/useCustomThemeV2";
import ScrollableContent from "./ScrollableContent";
 
const MAX_PURPOSE_MISSION_CHARS = 600;
 
type Props = {
  handleNext: () => void;
  handleBack: () => void;
  handleUpdateStatusValue: (value: number) => void;
  organizationDetailsStatusBar: number;
};
 
const OrganizationDetails = ({
  handleBack,
  handleNext,
  handleUpdateStatusValue,
  organizationDetailsStatusBar,
}: Props) => {
  const { isMobileView } = useCustomThemeV2();
 
  const {
    methods,
    values,
    formData,
    merchantLogo,
    isValid,
    isLoading,
    isSuccess,
    onSubmit,
    handleChangeStatus,
    goBackHandler,
    openTermsConditions,
    errors,
  } = useSignupOrganizationDetails({
    handleNext,
    handleBack,
    handleUpdateStatusValue,
  });
 
  const { data: imageURL, isFetching: isImageLoading } = useFetchImage(
    merchantLogo ?? "",
  );
 
  const labelPlaceholder = generateNameLabelPlaceholder(
    formData?.classification.name,
  );
 
  const isDisabled =
    !isValid ||
    !values.termsConditions ||
    isLoading ||
    organizationDetailsStatusBar < 100 ||
    isSuccess;
  const helperTextValue =
    MAX_PURPOSE_MISSION_CHARS - (values.businessPurpose?.length || 0);
 
  const uploadActions = {
    onUpload: handleChangeStatus,
    onDelete: () => methods.setValue("logo", ""),
    canUpload: true,
    canDelete: true,
  };
  const handleUploadPhoto = () => {
    NiceModal.show(EDIT_PROFILE_IMAGE_MODAL, {
      defaultImageURL: imageURL,
      rounded: false,
      actions: uploadActions,
      thumbnailType: "merchant",
    });
  };
 
  const usedHelperText = errors?.businessPurpose
    ? errors?.businessPurpose?.message
    : `${values.businessPurpose?.length || 0}/${helperTextValue}`;
  const nodeList = [
    {
      node: (
        <HFGiveInput
          name="name"
          label={`${labelPlaceholder} Name`}
          placeholder={`${labelPlaceholder} Name`}
          fullWidth
        />
      ),
      sm: 12,
    },
    {
      node: (
        <GiveBusinessTypeSelect name="businessType" label="Business Type" />
      ),
      sm: 12,
    },
    {
      node: (
        <GiveTaxIdInput
          label="Tax ID"
          ssnName="ssn"
          taxIdName="taxId"
          businessTypeName="businessType"
          tinType="tinType"
          data-testid="business-tax-id"
        />
      ),
      sm: 12,
    },
    {
      node: (
        <HFGiveInput
          name="businessPurpose"
          label={BUSINESS_PURPOSE_FIELD}
          placeholder={BUSINESS_PURPOSE_FIELD}
          multiline
          rows={6}
          fullWidth
          inputProps={{
            maxLength: MAX_PURPOSE_MISSION_CHARS,
          }}
          helperText={usedHelperText}
        />
      ),
      sm: 12,
    },
    {
      node: (
        <HFCheckbox
          name="termsConditions"
          label={
            <Stack direction="row" gap="3px">
              <GiveText variant="bodyS">I accept the</GiveText>
              <GiveLink
                variant="bodyS"
                component="button"
                onClick={(e: any) => openTermsConditions(e)}
                sx={{
                  textDecoration: "underline",
                  textUnderlineOffset: "3px",
                  "& span:before": { display: "none" },
                  "&:hover span:before": { display: "none" },
                }}
              >
                Terms & Conditions
              </GiveLink>
            </Stack>
          }
        />
      ),
    },
  ];
 
  return (
    <FormProvider {...methods}>
      <Stack component="form" onSubmit={methods.handleSubmit(onSubmit)}>
        <ScrollableContent>
          <Box paddingLeft={0} mb={4}>
            <GiveThumbnail
              imageUrl={imageURL}
              isLoading={isImageLoading || isLoading}
              disabled={isLoading}
              name={"logo"}
              size="extra_large"
              type="image-logo"
              onClick={handleUploadPhoto}
              containerSx={{
                backgroundColor: "transparent !important",
                borderRadius: "12px",
              }}
            />
          </Box>
          <Grid
            direction={isMobileView ? "column" : undefined}
            container
            spacing={1.5}
          >
            {nodeList.map(({ node, sm }, index) => (
              <Grid key={index} item sm={sm || 6}>
                {node}
              </Grid>
            ))}
          </Grid>
        </ScrollableContent>
 
        <SignupNavigation
          disabled={isDisabled}
          handleGoBack={goBackHandler}
          submitLabel="Create Account"
        />
      </Stack>
    </FormProvider>
  );
};
 
export default OrganizationDetails;