()
| 23 | ]; |
| 24 | |
| 25 | const handleDownload = async () => { |
| 26 | if (selectType === 1) { |
| 27 | await handleDownloadPdf( |
| 28 | props.pdfDetails, |
| 29 | setIsDownloading, |
| 30 | props?.pdfBase64 |
| 31 | ); |
| 32 | setSelectType(1); |
| 33 | props.setIsDownloadModal(false); |
| 34 | } else if (selectType === 2) { |
| 35 | setIsDownloading("pdf"); |
| 36 | const zip = new JSZip(); |
| 37 | const pdfDetails = props.pdfDetails; |
| 38 | const pdfName = |
| 39 | pdfDetails?.[0]?.Name?.length > 100 |
| 40 | ? pdfDetails?.[0]?.Name?.slice(0, 100) |
| 41 | : pdfDetails?.[0]?.Name || "Document"; |
| 42 | const pdfUrl = pdfDetails?.[0]?.SignedUrl || ""; |
| 43 | |
| 44 | try { |
| 45 | // Fetch the first PDF (Signed Document) |
| 46 | const docId = pdfDetails?.[0]?.objectId || ""; |
| 47 | const signedUrl = await getSignedUrl( |
| 48 | pdfUrl, |
| 49 | docId, |
| 50 | ); |
| 51 | const pdf1Response = await fetch(signedUrl); |
| 52 | if (!pdf1Response.ok) { |
| 53 | throw new Error(`Failed to fetch PDF: ${signedUrl}`); |
| 54 | } |
| 55 | const pdf1Blob = await pdf1Response.blob(); |
| 56 | const isZip = true; |
| 57 | // Fetch the Certificate (or generate its URL dynamically) |
| 58 | const certificateUrl = await handleDownloadCertificate( |
| 59 | pdfDetails, |
| 60 | setIsDownloading, |
| 61 | isZip |
| 62 | ); |
| 63 | const pdf2Response = await fetch(certificateUrl); |
| 64 | if (!pdf2Response.ok) { |
| 65 | throw new Error(`Failed to fetch certificate PDF: ${certificateUrl}`); |
| 66 | } |
| 67 | const pdf2Blob = await pdf2Response.blob(); |
| 68 | // Add files to ZIP |
| 69 | zip.file( |
| 70 | `${fileNameWithUnderscore(pdfName)}_signed_by_${appName}.pdf`, |
| 71 | pdf1Blob |
| 72 | ); |
| 73 | zip.file(`Certificate_signed_by_${appName}.pdf`, pdf2Blob); |
| 74 | // Generate the ZIP and trigger download |
| 75 | const zipBlob = await zip.generateAsync({ type: "blob" }); |
| 76 | saveAs( |
| 77 | zipBlob, |
| 78 | `${fileNameWithUnderscore(pdfName)}_signed_by_${appName}.zip` |
| 79 | ); |
| 80 | setSelectType(1); |
| 81 | props.setIsDownloadModal(false); |
| 82 | setIsDownloading(""); |
no test coverage detected