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 | 10x 10x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 5x 6x 6x 1x 1x 1x 1x 1x 6x 6x 6x 1x 6x 10x | import { StepViewContainer } from "@features/GiveOnboarding/container/StepViewContainer";
import { IStep } from "@features/GiveOnboarding/types";
import { Box, Stack } from "@mui/material";
import GiveText from "@shared/Text/GiveText";
import React, {
Dispatch,
forwardRef,
SetStateAction,
useEffect,
useImperativeHandle,
useState,
} from "react";
import {
CustomQRCode,
ErrorTextComponent,
InfoSection,
} from "../../pages.atoms";
import { useAppTheme } from "@theme/v2/Provider";
import { TMerchantDocument } from "@components/Merchants/MerchantPreview/data.types";
import {
useGetIdentificationFiles,
useGetSelfieOTC,
} from "@sections/VerifyAccountHolder_v2/hooks/useCamera";
import { isEmpty } from "lodash";
import { useCustomThemeV2 } from "@theme/hooks/useCustomThemeV2";
import SelfieModal from "@features/GiveOnboarding/modals/SelfieModal";
import { IOnSubmitOptions } from "@features/GiveOnboarding/types/handlers";
import { IApiData } from "@features/GiveOnboarding/types/form";
import GiveAlert from "@shared/GiveAlert/GiveAlert";
import { WarningIcon } from "@phosphor-icons/react";
import BankFilesUploader from "../BankFilesUploader";
import useMasqueradeReducer from "@hooks/Reducers/useMasqueradeReducer";
import GiveLink from "@shared/Link/GiveLink";
import NiceModal from "@ebay/nice-modal-react";
import { GIVE_UPLOAD_MODAL } from "modals/modal_names";
import { AcceptAllowedImagesTypes } from "@hooks/upload-api/uploadHooks";
import { FileAttachmentType } from "@hooks/upload-api/uploadHooks";
interface Props {
data_key: IStep;
setIsEmptySelfie: Dispatch<SetStateAction<boolean>>;
bankData: IApiData["data"]["business_bank_connect"];
merchantId: string;
userFullName: string;
id?: number;
}
const filter = `?filter=attTypeName:"${FileAttachmentType.BankAccountConfirm}"%3BisUploaded:true`;
const BankConfirm = forwardRef((props: Props, ref: any) => {
const merchantId = Number(props.merchantId);
const { isMasqueradeMode } = useMasqueradeReducer();
const theme = useAppTheme();
const [ownerFiles, setFiles] = useState<[] | TMerchantDocument[]>([]);
const [isFormError, setIsFormError] = useState(false);
const [openModal, setOpenModal] = useState(false);
const { isMobileView } = useCustomThemeV2();
const isEmptyFiles = isEmpty(ownerFiles);
const bankAccountID = props?.bankData?.bankDataAux?.id || props?.id;
const [isRefetchingManually, setIsRefetchingManually] = useState(false);
const { refetch } = useGetIdentificationFiles({
enablePolling: isEmptyFiles,
onSuccess: async (data: any) => {
const files = (data?.data as TMerchantDocument[]) || [];
setFiles(files);
},
filter: filter,
});
useEffect(() => {
props.setIsEmptySelfie?.(isMobileView && isEmpty(ownerFiles));
}, [ownerFiles, isMobileView]);
const onSuccess = async () => {
setIsRefetchingManually(true);
try {
await refetch();
} catch {
console.log("Error refetching files.");
setIsRefetchingManually(false);
} finally {
setIsRefetchingManually(false);
}
};
useImperativeHandle(
ref,
() => ({
data_key: props.data_key,
submit: ({
onInvalid,
onSubmitValidated,
onValid,
}: IOnSubmitOptions<any>) => {
Iif (ownerFiles.length) {
onValid?.({});
} else {
Iif (isMobileView) {
setOpenModal(true);
} else {
setIsFormError(true);
onInvalid?.({
type: "formValidation",
error: {
account_owner: {
message:
"Uploading Business Bank Account Statement is required",
},
},
});
}
}
},
}),
[props.data_key, ownerFiles, isEmptyFiles],
);
const {
data: otcData,
isLoading,
isError,
} = useGetSelfieOTC({
enabled: isEmptyFiles && !isMasqueradeMode,
});
const LINK = `https://${window.location.hostname}/bank?token=${otcData?.token}&exp_date=${otcData?.expiresdAt}`;
const handleShowUploadModal = () => {
NiceModal.show(GIVE_UPLOAD_MODAL, {
merchantId: merchantId,
resourceID: bankAccountID,
tag: FileAttachmentType.BankAccountConfirm,
onSuccess: onSuccess,
});
};
return (
<>
<StepViewContainer>
<InfoSection />
{isFormError && (
<ErrorTextComponent
sx={{
alignItems: "flex-end",
width: "100%",
margin: 0,
}}
errorText="Confirming access to bank account is required"
/>
)}
{isEmptyFiles &&
!isLoading &&
!isMasqueradeMode &&
(isError || isEmpty(otcData?.token)) ? (
<GiveAlert
label="We ran into an issue, please try uploading the file instead."
Icon={<WarningIcon size={24} />}
type="error"
iconContainerSx={{ display: "flex", alignItems: "center" }}
sx={{ width: "100%" }}
/>
) : (
<>
{!isMobileView && isEmptyFiles && !isMasqueradeMode && (
<Stack gap="24px" width="100%">
<Box width="100%">
<Stack
bgcolor={theme.palette.primitive?.transparent["darken-5"]}
alignItems="center"
flexDirection="row"
gap="24px"
p="24px"
borderRadius="20px"
>
<CustomQRCode
isError={
(isError || isEmpty(otcData?.token)) && !isLoading
}
isLoading={isLoading}
value={LINK}
/>
<GiveText fontSize="14px">
Scan the QR code with your smartphone and capture the
photo.
</GiveText>
</Stack>
</Box>
<Stack alignItems="center" gap="8px">
<GiveText variant="bodyS" color="secondary">
QR Code not working?
</GiveText>
<GiveLink
component="button"
color="secondary"
onClick={handleShowUploadModal}
disabled={isRefetchingManually}
>
Click here to upload a file
</GiveLink>
</Stack>
</Stack>
)}
</>
)}
{Boolean(isMasqueradeMode || !isEmptyFiles) && (
<Box width="100%">
<BankFilesUploader
title="Business Bank Account Statement"
tag={FileAttachmentType.BankAccountConfirm}
isFormError={isFormError}
merchantId={merchantId}
resourceID={bankAccountID}
bankFiles={ownerFiles}
max={1}
accept={AcceptAllowedImagesTypes}
/>
</Box>
)}
</StepViewContainer>
<SelfieModal
uploadType="bankPicture"
setOpenModal={setOpenModal}
open={openModal}
bankAccountID={bankAccountID}
config={{ video: { facingMode: { ideal: "environment" } } }}
/>
</>
);
});
BankConfirm.displayName = "business_bank_confirm";
export default BankConfirm;
|