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 | 52x 70x 70x 70x 70x 70x 70x 70x 70x 70x 70x 70x 1x 70x 3x 3x 3x 3x 3x 3x 3x 70x 70x 52x 391x 391x 96x 330x 330x 1x 96x 391x 52x 70x | import { TMerchantDocument } from "@components/Merchants/MerchantPreview/data.types";
import { NEW_ACTION_DENY_MESSAGE } from "@constants/permissions";
import { useGetUploadFilePermission } from "@hooks/merchant-api/manage-money/useUploadBankAccountDocument";
import {
AcceptAllowedGeneralDocumentsTypes,
MAX_UPLOAD_SIZE,
useUploadFiles,
} from "@hooks/upload-api/uploadHooks";
import { Stack, SxProps, Box } from "@mui/material";
import GiveUploadArea from "@shared/FileUpload/GiveUploadArea";
import GiveText from "@shared/Text/GiveText";
import GiveTooltip from "@shared/Tooltip/GiveTooltip";
import { useCustomThemeV2 } from "@theme/hooks/useCustomThemeV2";
import { checkPortals } from "@utils/routing";
import { useQueryClient } from "react-query";
import useDeleteDocument from "../hooks/useDeleteDocument";
import { MERCHANT_SIDE_PANEL_PREVIEW_API_KEYS } from "../../constants";
import { GiveUploadItemProps } from "@shared/FileUpload/types";
import { FILES_UPLOAD_GENERAL_LABEL } from "@constants/constants";
import { QKEY_CHALLENGE_FILES } from "@constants/queryKeys";
import DocumentsVirtualizedList from "./DocumentsVirtualizedList";
import { useFormatDateInTimezone } from "@utils/date.helpers";
import { styled } from "@theme/v2/Provider";
type Props = {
id: number;
challengeID?: number;
data: TMerchantDocument[];
isEnterprise?: boolean;
title?: string;
customUploadStackStyles?: SxProps;
isHideDelete?: boolean;
fullName?: string;
};
const DocumentsSection = ({
id,
data,
isEnterprise = false,
title,
customUploadStackStyles,
isHideDelete = false,
challengeID,
fullName,
}: Props) => {
const queryClient = useQueryClient();
const { isAcquirerPortal, isEnterprisePortal } = checkPortals();
const { isMobileView } = useCustomThemeV2();
const isUploadAllowed = useGetUploadFilePermission(isEnterprise);
const tag = `${
isAcquirerPortal ? "Acquirer" : isEnterprisePortal ? "Provider" : "Merchant"
} upload`;
const { handleUpload } = useUploadFiles();
const { deleteDocument } = useDeleteDocument();
const { parseDocumentsList } = useParseDocumentsList();
const documentsQuery = queryClient.getQueryData([
MERCHANT_SIDE_PANEL_PREVIEW_API_KEYS.GET_FILES,
id,
]) as any;
const totalDocuments = documentsQuery?.pages?.[0]?.total;
const handleDeleteDocument = (fileName: string, fileId: number) => {
deleteDocument(id, { id: fileId, fileName }, () =>
queryClient.invalidateQueries(
MERCHANT_SIDE_PANEL_PREVIEW_API_KEYS.GET_FILES,
),
);
};
const attemptUpload = async (files: File | File[]) => {
Iif (!files) return;
// Normalize to array
const fileArray = Array.isArray(files) ? files : [files];
Iif (!fileArray.length) return;
await handleUpload(
{
list: fileArray.map((file) => ({ file })),
merchantId: id,
resourceID: id,
attachmentType: "underwriting_profile",
label: "",
tag,
refetcherKey: [MERCHANT_SIDE_PANEL_PREVIEW_API_KEYS.GET_FILES],
},
undefined,
challengeID,
);
Iif (challengeID)
queryClient.invalidateQueries([QKEY_CHALLENGE_FILES, id, challengeID]);
queryClient.invalidateQueries([
MERCHANT_SIDE_PANEL_PREVIEW_API_KEYS.GET_FILES,
id,
]);
};
const parsedData = parseDocumentsList({
documents: data,
id: id,
handleDeleteDocument: handleDeleteDocument,
fullName,
});
return (
<Stack gap="20px">
{title && <GiveText>{title}</GiveText>}
<GiveTooltip
width="compact"
alignment="left"
title={NEW_ACTION_DENY_MESSAGE}
color="default"
disableHoverListener={isUploadAllowed}
>
<GiveUploadArea
message={FILES_UPLOAD_GENERAL_LABEL}
disabled={!isUploadAllowed}
uploadFunction={attemptUpload}
accept={AcceptAllowedGeneralDocumentsTypes}
maxFiles={5}
multiple
isMobile={isMobileView}
maxSizeInBytes={MAX_UPLOAD_SIZE.value}
/>
</GiveTooltip>
<DocumentListContainer>
<DocumentsVirtualizedList
items={parsedData}
customStyles={customUploadStackStyles}
isHideDelete={isHideDelete}
totalDocuments={totalDocuments}
hideScrollbar={true}
/>
</DocumentListContainer>
</Stack>
);
};
export const useParseDocumentsList = () => {
const { formatInTimezone } = useFormatDateInTimezone();
const parseDocumentsList = ({
documents,
id,
handleDeleteDocument,
fullName,
useSizeMessage,
useNotes,
}: {
documents: TMerchantDocument[];
id?: number;
handleDeleteDocument?: (fileName: string, fileId: number) => void;
fullName?: string;
useSizeMessage?: boolean;
useNotes?: boolean;
}) => {
const parsedData: GiveUploadItemProps[] = documents?.map((document) => {
const {
tag,
id: fileId,
attTypeName,
userFullName,
fileName,
updatedAt,
userEmail,
fileSize,
} = document;
return {
merchantId: id,
state: "uploaded",
value: (tag || attTypeName) ?? "",
setValue: () => null,
byMessage: `by ${userFullName || fullName || userEmail}`,
dateMessage: formatInTimezone(
updatedAt,
"MMM dd, yyyy, HH:mm",
)?.toString(),
fileData: document,
setTagWithApi: true,
onDelete: () =>
handleDeleteDocument ? handleDeleteDocument(fileName, fileId) : null,
sizeMessage: useSizeMessage ? fileSize?.toString() : "",
useNotes,
};
});
return parsedData;
};
return { parseDocumentsList };
};
export default DocumentsSection;
export const DocumentListContainer = styled(Box)(({ theme }) => {
return {
borderRadius: `${theme?.customs?.radius?.medium}px`,
width: "100%",
backgroundColor: theme.palette.background.paper,
};
});
|