Skip to content

Commit e559d03

Browse files
feat: add zip file to dowload pdf and certificate in all download option of completed pdf
1 parent c9909a0 commit e559d03

File tree

7 files changed

+66
-31
lines changed

7 files changed

+66
-31
lines changed

apps/OpenSign/src/components/pdf/EmailComponent.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useState } from "react";
22
import axios from "axios";
3-
import { handleDownloadPdf, handleToPrint } from "../../constant/Utils";
3+
import { handleToPrint } from "../../constant/Utils";
44
import { themeColor, emailRegex } from "../../constant/const";
55
import Loader from "../../primitives/Loader";
66
import ModalUi from "../../primitives/ModalUi";
@@ -15,7 +15,8 @@ function EmailComponent({
1515
sender,
1616
setIsAlert,
1717
extUserId,
18-
activeMailAdapter
18+
activeMailAdapter,
19+
setIsDownloadModal
1920
}) {
2021
const { t } = useTranslation();
2122
const [emailList, setEmailList] = useState([]);
@@ -129,6 +130,11 @@ function EmailComponent({
129130
}
130131
}
131132
};
133+
const handleClose = () => {
134+
setIsEmail(false);
135+
setEmailValue("");
136+
setEmailList([]);
137+
};
132138
return (
133139
<div>
134140
{/* isEmail */}
@@ -165,7 +171,10 @@ function EmailComponent({
165171
)}
166172
<button
167173
className="op-btn op-btn-primary op-btn-sm text-[15px] ml-2"
168-
onClick={() => handleDownloadPdf(pdfDetails, setIsDownloading)}
174+
onClick={() => {
175+
handleClose();
176+
setIsDownloadModal(true);
177+
}}
169178
>
170179
<i className="fa-light fa-download" aria-hidden="true"></i>
171180
{t("download")}
@@ -261,11 +270,7 @@ function EmailComponent({
261270
<button
262271
type="button"
263272
className="op-btn op-btn-ghost ml-2"
264-
onClick={() => {
265-
setIsEmail(false);
266-
setEmailValue("");
267-
setEmailList([]);
268-
}}
273+
onClick={() => handleClose()}
269274
>
270275
{t("close")}
271276
</button>

apps/OpenSign/src/constant/Utils.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2038,26 +2038,21 @@ export const fetchUrl = async (url, pdfName) => {
20382038
console.error("Error downloading the file:", error);
20392039
}
20402040
};
2041+
export const getSignedUrl = async (pdfUrl, docId) => {
2042+
const signedUrl = await Parse.Cloud.run("getsignedurl", {
2043+
url: pdfUrl,
2044+
docId: docId || ""
2045+
});
2046+
return signedUrl;
2047+
};
20412048
//handle download signed pdf
20422049
export const handleDownloadPdf = async (pdfDetails, setIsDownloading) => {
20432050
const pdfName = pdfDetails[0] && pdfDetails[0]?.Name;
20442051
const pdfUrl = pdfDetails?.[0]?.SignedUrl || pdfDetails?.[0]?.URL;
20452052
setIsDownloading("pdf");
20462053
const docId = !pdfDetails?.[0]?.IsEnableOTP ? pdfDetails?.[0]?.objectId : "";
20472054
try {
2048-
// const url = await Parse.Cloud.run("getsignedurl", { url: pdfUrl });
2049-
const axiosRes = await axios.post(
2050-
`${localStorage.getItem("baseUrl")}/functions/getsignedurl`,
2051-
{ url: pdfUrl, docId: docId },
2052-
{
2053-
headers: {
2054-
"content-type": "Application/json",
2055-
"X-Parse-Application-Id": localStorage.getItem("parseAppId"),
2056-
"X-Parse-Session-Token": localStorage.getItem("accesstoken")
2057-
}
2058-
}
2059-
);
2060-
const url = axiosRes.data.result;
2055+
const url = await getSignedUrl(pdfUrl, docId);
20612056
await fetchUrl(url, pdfName);
20622057
setIsDownloading("");
20632058
} catch (err) {
@@ -2165,6 +2160,7 @@ export const handleDownloadCertificate = async (
21652160
await fetch(doc?.CertificateUrl);
21662161
const certificateUrl = doc?.CertificateUrl;
21672162
if (isZip) {
2163+
setIsDownloading("");
21682164
return certificateUrl;
21692165
} else {
21702166
saveAs(certificateUrl, `Certificate_signed_by_OpenSign™.pdf`);

apps/OpenSign/src/pages/PdfRequestFiles.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import {
2828
contractUsers,
2929
handleSendOTP,
3030
contactBook,
31-
handleDownloadPdf,
3231
handleToPrint,
3332
handleDownloadCertificate,
3433
getDefaultSignature,
@@ -2000,9 +1999,13 @@ function PdfRequestFiles(props) {
20001999
<button
20012000
type="button"
20022001
className="font-[500] text-[13px] mr-[5px] op-btn op-btn-primary"
2003-
onClick={() =>
2004-
handleDownloadPdf(pdfDetails, setIsDownloading)
2005-
}
2002+
onClick={() => {
2003+
setIsCompleted((prev) => ({
2004+
...prev,
2005+
isModal: false
2006+
}));
2007+
setIsDownloadModal(true);
2008+
}}
20062009
>
20072010
<i
20082011
className="fa-light fa-download"
@@ -2213,6 +2216,7 @@ function PdfRequestFiles(props) {
22132216
setIsDownloadModal={setIsDownloadModal}
22142217
isDownloadModal={isDownloadModal}
22152218
pdfDetails={pdfDetails}
2219+
isDocId={true}
22162220
/>
22172221
</>
22182222
)}

apps/OpenSign/src/pages/SignyourselfPdf.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,6 +1336,7 @@ function SignYourSelf() {
13361336
setIsAlert={setIsAlert}
13371337
extUserId={extUserId}
13381338
activeMailAdapter={activeMailAdapter}
1339+
setIsDownloadModal={setIsDownloadModal}
13391340
/>
13401341
{/* pdf header which contain funish back button */}
13411342
<Header
@@ -1464,6 +1465,7 @@ function SignYourSelf() {
14641465
setIsDownloadModal={setIsDownloadModal}
14651466
isDownloadModal={isDownloadModal}
14661467
pdfDetails={pdfDetails}
1468+
isDocId={true}
14671469
/>
14681470
<TextFontSetting
14691471
isTextSetting={isTextSetting}

apps/OpenSign/src/primitives/DownloadPdfZip.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { useState } from "react";
22
import { useTranslation } from "react-i18next";
33
import ModalUi from "./ModalUi";
44
import {
5+
getSignedUrl,
56
handleDownloadCertificate,
67
handleDownloadPdf,
78
sanitizeFileName
@@ -21,18 +22,26 @@ function DownloadPdfZip(props) {
2122

2223
const handleDownload = async () => {
2324
if (selectType === 1) {
24-
handleDownloadPdf(props.pdfDetails, setIsDownloading);
25+
await handleDownloadPdf(props.pdfDetails, setIsDownloading);
26+
setSelectType(1);
27+
props.setIsDownloadModal(false);
2528
} else if (selectType === 2) {
29+
setIsDownloading("pdf");
2630
const zip = new JSZip();
2731
const pdfDetails = props.pdfDetails;
2832
const pdfName = pdfDetails?.[0]?.Name || "Document";
2933
const pdfUrl = pdfDetails?.[0]?.SignedUrl || "";
3034

3135
try {
3236
// Fetch the first PDF (Signed Document)
33-
const pdf1Response = await fetch(pdfUrl);
37+
const docId =
38+
props.isDocId && !pdfDetails?.[0]?.IsEnableOTP
39+
? pdfDetails?.[0]?.objectId
40+
: "";
41+
const signedUrl = await getSignedUrl(pdfUrl, docId);
42+
const pdf1Response = await fetch(signedUrl);
3443
if (!pdf1Response.ok) {
35-
throw new Error(`Failed to fetch PDF: ${pdfUrl}`);
44+
throw new Error(`Failed to fetch PDF: ${signedUrl}`);
3645
}
3746
const pdf1Blob = await pdf1Response.blob();
3847

@@ -56,14 +65,16 @@ function DownloadPdfZip(props) {
5665

5766
// Generate the ZIP and trigger download
5867
const zipBlob = await zip.generateAsync({ type: "blob" });
59-
saveAs(zipBlob, "pdf-files.zip");
68+
saveAs(zipBlob, `${sanitizeFileName(pdfName)}.zip`);
6069
setSelectType(1);
6170
props.setIsDownloadModal(false);
71+
setIsDownloading("");
6272
} catch (error) {
6373
console.error("Error creating ZIP file:", error);
6474
}
6575
}
6676
};
77+
console.log("isDownloading", isDownloading);
6778
return (
6879
<ModalUi
6980
isOpen={props.isDownloadModal}

apps/OpenSign/src/primitives/GetReportDisplay.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
checkIsSubscribed,
1515
copytoData,
1616
fetchUrl,
17+
getSignedUrl,
1718
replaceMailVaribles
1819
} from "../constant/Utils";
1920
import Confetti from "react-confetti";
@@ -30,6 +31,7 @@ import SubscribeCard from "./SubscribeCard";
3031
import { validplan } from "../json/plansArr";
3132
import { serverUrl_fn } from "../constant/appinfo";
3233
import { useTranslation } from "react-i18next";
34+
import DownloadPdfZip from "./DownloadPdfZip";
3335

3436
const ReportTable = (props) => {
3537
const { t } = useTranslation();
@@ -71,6 +73,7 @@ const ReportTable = (props) => {
7173
const [isSubscribe, setIsSubscribe] = useState(true);
7274
const [isModal, setIsModal] = useState({});
7375
const [reason, setReason] = useState("");
76+
const [isDownloadModal, setIsDownloadModal] = useState(false);
7477
const Extand_Class = localStorage.getItem("Extand_Class");
7578
const extClass = Extand_Class && JSON.parse(Extand_Class);
7679
const startIndex = (currentPage - 1) * props.docPerPage;
@@ -649,10 +652,15 @@ const ReportTable = (props) => {
649652
setActLoader({ [`${item.objectId}`]: true });
650653
const url = item?.SignedUrl || item?.URL || "";
651654
const pdfName = item?.Name || "exported_file";
655+
const isCompleted = item?.IsCompleted || false;
652656
if (url) {
653657
try {
654-
const signedUrl = await Parse.Cloud.run("getsignedurl", { url: url });
655-
await fetchUrl(signedUrl, pdfName);
658+
if (isCompleted) {
659+
setIsDownloadModal({ [item.objectId]: true });
660+
} else {
661+
const signedUrl = await getSignedUrl(url);
662+
await fetchUrl(signedUrl, pdfName);
663+
}
656664
setActLoader({});
657665
} catch (err) {
658666
console.log("err in getsignedurl", err);
@@ -2107,6 +2115,14 @@ const ReportTable = (props) => {
21072115
</div>
21082116
</ModalUi>
21092117
)}
2118+
{isDownloadModal[item.objectId] && (
2119+
<DownloadPdfZip
2120+
setIsDownloadModal={setIsDownloadModal}
2121+
isDownloadModal={isDownloadModal[item.objectId]}
2122+
pdfDetails={[item]}
2123+
isDocId={false}
2124+
/>
2125+
)}
21102126
</td>
21112127
</tr>
21122128
)

apps/OpenSignServer/cloud/parsefunction/reportsJson.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ export default function reportJson(id, userId) {
139139
'TimeToCompleteDays',
140140
'Placeholders',
141141
'IsSignyourself',
142+
'IsCompleted',
142143
],
143144
};
144145
// declined documents report

0 commit comments

Comments
 (0)