( pdfDetails, setIsDownloading, pdfBase64 )
| 3010 | }; |
| 3011 | //handle download signed pdf |
| 3012 | export const handleDownloadPdf = async ( |
| 3013 | pdfDetails, |
| 3014 | setIsDownloading, |
| 3015 | pdfBase64 |
| 3016 | ) => { |
| 3017 | const pdfName = |
| 3018 | pdfDetails?.[0]?.Name?.length > 100 |
| 3019 | ? pdfDetails?.[0]?.Name?.slice(0, 100) |
| 3020 | : pdfDetails?.[0]?.Name || "Document"; |
| 3021 | const isCompleted = pdfDetails?.[0]?.IsCompleted || false; |
| 3022 | const formatId = pdfDetails?.[0]?.ExtUserPtr?.DownloadFilenameFormat; |
| 3023 | const docName = buildDownloadFilename(formatId, { |
| 3024 | docName: pdfName, |
| 3025 | email: pdfDetails?.[0]?.ExtUserPtr?.Email, |
| 3026 | isSigned: isCompleted |
| 3027 | }); |
| 3028 | if (pdfBase64) { |
| 3029 | await fetchBase64(pdfBase64, docName); |
| 3030 | setIsDownloading && setIsDownloading(""); |
| 3031 | } else { |
| 3032 | const pdfUrl = pdfDetails?.[0]?.SignedUrl || pdfDetails?.[0]?.URL; |
| 3033 | setIsDownloading && setIsDownloading("pdf"); |
| 3034 | const docId = pdfDetails?.[0]?.objectId || ""; |
| 3035 | try { |
| 3036 | const url = await getSignedUrl(pdfUrl, docId); |
| 3037 | await fetchUrl(url, docName); |
| 3038 | setIsDownloading && setIsDownloading(""); |
| 3039 | } catch (err) { |
| 3040 | console.log("err in getsignedurl", err); |
| 3041 | setIsDownloading(""); |
| 3042 | alert(i18n.t("something-went-wrong-mssg")); |
| 3043 | } |
| 3044 | } |
| 3045 | }; |
| 3046 | |
| 3047 | export function fileNameWithUnderscore(pdfName) { |
| 3048 | // Replace spaces with underscore |
no test coverage detected