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 | 22x 22x 221x 221x 221x 221x 221x 221x 221x 221x 221x 232x 232x 232x 4x 4x 4x 4x 4x 4x 4x 4x 4x 54x 35x 188x | import { Controller, useFormContext } from "react-hook-form";
import { TMerchantDocument } from "@components/Merchants/MerchantPreview/data.types";
import Dropzone from "react-dropzone-uploader";
import { isTestEnvironment } from "@constants/constants";
import { UPLOAD_DENY_MESSAGE } from "@constants/permissions";
import { useAppTheme } from "@theme/v2/Provider";
import { UploaderState } from "@components/Merchants/MerchantPreview/components/PrimaryAccountHolder/PAHUploaderMachine";
import GiveTooltip from "@shared/Tooltip/GiveTooltip";
import { useIsValidFile } from "@hooks/upload-api/useIsValidFile";
import { MAX_UPLOAD_SIZE } from "@hooks/upload-api/uploadHooks";
import IDUploaderActions from "features/Merchants/MerchantSidePanel/components/PrimaryAccountHolderSection/IDUploaderActions";
import {
IDUploaderInput,
IDUploaderLayout,
} from "features/Merchants/MerchantSidePanel/components/PrimaryAccountHolderSection/IDUploaderComponents";
import { useCustomThemeV2 } from "@theme/hooks/useCustomThemeV2";
import useHEICConversion from "@components/UploadFile/hooks/useHEICConversion";
import { UploadDocumentTypes } from "@redux/slices/uploadProgressSlice/types";
import { useBusinessOwnerIDUploader } from "./useBusinessOwnerIDUploaderV2";
import { getFilesFromEvent } from "@shared/FileUpload/utils";
import { CSSProperties } from "react";
type Props = {
merchantId: number;
idFile?: TMerchantDocument;
isUploadAllowed: boolean;
isDeleteAllowed: boolean;
isDeleteHidden?: boolean;
idImageUrl?: string;
disabled?: boolean;
documentType?: UploadDocumentTypes;
dropZoneStyle?: CSSProperties;
};
const TYPE_UPLOAD = "businessOwnerID";
const GiveBusinessOwnerIDUploader = ({
merchantId,
idFile,
isUploadAllowed,
isDeleteAllowed,
isDeleteHidden,
disabled,
idImageUrl,
documentType,
dropZoneStyle = {},
}: Props) => {
const {
deleteID,
idUrl,
downloadFile: downloadHandler,
previewDocument,
updateIdUrl,
} = useBusinessOwnerIDUploader({
merchantId,
idFile,
idImageUrl,
});
const theme = useAppTheme();
const { isMobileView: isMobile } = useCustomThemeV2();
const { isDropzoneImageFileValid } = useIsValidFile();
const { convertAndUploadHEICFiles } = useHEICConversion();
const { control } = useFormContext();
const isFileUploaded = !!idUrl;
const state = isFileUploaded
? UploaderState.ON_UPLOADED
: UploaderState.ON_INITIAL;
return (
<Controller
name="files"
control={control}
render={({ field: { onChange }, fieldState: { error } }) => {
const isUploadable = !isFileUploaded || !!error;
const errorMessage = (error as any)?.allFiles?.message;
return (
<>
<Dropzone
disabled={!isUploadable || disabled}
styles={{
dropzone: {
flex: 1,
overflow: "hidden",
borderRadius: 12,
justifyContent: "center",
backgroundColor:
theme.palette.primitive?.transparent["darken-5"],
borderColor: errorMessage
? theme?.palette.primitive?.error[50]
: "none",
...dropZoneStyle,
},
dropzoneDisabled: {
opacity: 1,
},
}}
onChangeStatus={(fileWithMeta, status, allFiles) => {
const changeStatus = isTestEnvironment ? "done" : status; //Ensure onChange is called on first instance within jest
Iif (!isDropzoneImageFileValid(fileWithMeta, changeStatus)) {
return;
}
const currFile = allFiles[allFiles.length - 1];
const handleSave = (files: File[]) => {
const [newFile] = files;
const file = {
...currFile,
file: newFile,
meta: {
...currFile?.meta,
name: newFile.name,
size: newFile.size,
type: newFile.type,
previewUrl: URL.createObjectURL(newFile),
},
};
updateIdUrl(file.meta.previewUrl ?? "");
onChange(
{
fileWithMeta: file,
status: changeStatus,
allFiles: [file],
},
{ shouldDirty: true },
);
};
convertAndUploadHEICFiles({
files: [currFile.file],
documentType,
onComplete: handleSave,
});
}}
multiple={false}
canCancel={false}
getFilesFromEvent={getFilesFromEvent}
LayoutComponent={
state === UploaderState.ON_UPLOADED
? (props) => (
<IDUploaderLayout
{...props}
type={TYPE_UPLOAD}
fileUrl={idUrl}
actions={
<IDUploaderActions
type={TYPE_UPLOAD}
downloadHandler={downloadHandler}
deleteDocument={deleteID}
previewDocument={previewDocument}
disabled={{
delete: !isDeleteAllowed,
}}
hidden={{
delete: isDeleteHidden,
}}
isBusinessOwnerModal
/>
}
/>
)
: undefined
}
PreviewComponent={() => <></>}
maxSizeBytes={MAX_UPLOAD_SIZE.value}
InputComponent={(props) => (
<GiveTooltip
width="compact"
alignment="left"
title={UPLOAD_DENY_MESSAGE}
color="default"
disableHoverListener={isUploadAllowed}
>
<IDUploaderInput
{...props}
isMobile={isMobile}
fileName={idUrl}
type={TYPE_UPLOAD}
state={state}
fileUrl={idUrl}
previewDocument={previewDocument}
isUploadable={isUploadable}
disabled={!!disabled}
error={errorMessage}
/>
</GiveTooltip>
)}
/>
</>
);
}}
/>
);
};
export default GiveBusinessOwnerIDUploader;
|