mirror of
https://github.com/OpenSignLabs/OpenSign.git
synced 2026-08-29 03:09:49 +02:00
feat: add zip file to dowload pdf and certificate in all download option of completed pdf
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import React, { useState } from "react";
|
||||
import axios from "axios";
|
||||
import { handleDownloadPdf, handleToPrint } from "../../constant/Utils";
|
||||
import { handleToPrint } from "../../constant/Utils";
|
||||
import { themeColor, emailRegex } from "../../constant/const";
|
||||
import Loader from "../../primitives/Loader";
|
||||
import ModalUi from "../../primitives/ModalUi";
|
||||
@@ -15,7 +15,8 @@ function EmailComponent({
|
||||
sender,
|
||||
setIsAlert,
|
||||
extUserId,
|
||||
activeMailAdapter
|
||||
activeMailAdapter,
|
||||
setIsDownloadModal
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const [emailList, setEmailList] = useState([]);
|
||||
@@ -129,6 +130,11 @@ function EmailComponent({
|
||||
}
|
||||
}
|
||||
};
|
||||
const handleClose = () => {
|
||||
setIsEmail(false);
|
||||
setEmailValue("");
|
||||
setEmailList([]);
|
||||
};
|
||||
return (
|
||||
<div>
|
||||
{/* isEmail */}
|
||||
@@ -165,7 +171,10 @@ function EmailComponent({
|
||||
)}
|
||||
<button
|
||||
className="op-btn op-btn-primary op-btn-sm text-[15px] ml-2"
|
||||
onClick={() => handleDownloadPdf(pdfDetails, setIsDownloading)}
|
||||
onClick={() => {
|
||||
handleClose();
|
||||
setIsDownloadModal(true);
|
||||
}}
|
||||
>
|
||||
<i className="fa-light fa-download" aria-hidden="true"></i>
|
||||
{t("download")}
|
||||
@@ -261,11 +270,7 @@ function EmailComponent({
|
||||
<button
|
||||
type="button"
|
||||
className="op-btn op-btn-ghost ml-2"
|
||||
onClick={() => {
|
||||
setIsEmail(false);
|
||||
setEmailValue("");
|
||||
setEmailList([]);
|
||||
}}
|
||||
onClick={() => handleClose()}
|
||||
>
|
||||
{t("close")}
|
||||
</button>
|
||||
|
||||
@@ -2038,6 +2038,13 @@ export const fetchUrl = async (url, pdfName) => {
|
||||
console.error("Error downloading the file:", error);
|
||||
}
|
||||
};
|
||||
export const getSignedUrl = async (pdfUrl, docId) => {
|
||||
const signedUrl = await Parse.Cloud.run("getsignedurl", {
|
||||
url: pdfUrl,
|
||||
docId: docId || ""
|
||||
});
|
||||
return signedUrl;
|
||||
};
|
||||
//handle download signed pdf
|
||||
export const handleDownloadPdf = async (pdfDetails, setIsDownloading) => {
|
||||
const pdfName = pdfDetails[0] && pdfDetails[0]?.Name;
|
||||
@@ -2045,19 +2052,7 @@ export const handleDownloadPdf = async (pdfDetails, setIsDownloading) => {
|
||||
setIsDownloading("pdf");
|
||||
const docId = !pdfDetails?.[0]?.IsEnableOTP ? pdfDetails?.[0]?.objectId : "";
|
||||
try {
|
||||
// const url = await Parse.Cloud.run("getsignedurl", { url: pdfUrl });
|
||||
const axiosRes = await axios.post(
|
||||
`${localStorage.getItem("baseUrl")}/functions/getsignedurl`,
|
||||
{ url: pdfUrl, docId: docId },
|
||||
{
|
||||
headers: {
|
||||
"content-type": "Application/json",
|
||||
"X-Parse-Application-Id": localStorage.getItem("parseAppId"),
|
||||
"X-Parse-Session-Token": localStorage.getItem("accesstoken")
|
||||
}
|
||||
}
|
||||
);
|
||||
const url = axiosRes.data.result;
|
||||
const url = await getSignedUrl(pdfUrl, docId);
|
||||
await fetchUrl(url, pdfName);
|
||||
setIsDownloading("");
|
||||
} catch (err) {
|
||||
@@ -2165,6 +2160,7 @@ export const handleDownloadCertificate = async (
|
||||
await fetch(doc?.CertificateUrl);
|
||||
const certificateUrl = doc?.CertificateUrl;
|
||||
if (isZip) {
|
||||
setIsDownloading("");
|
||||
return certificateUrl;
|
||||
} else {
|
||||
saveAs(certificateUrl, `Certificate_signed_by_OpenSign™.pdf`);
|
||||
|
||||
@@ -28,7 +28,6 @@ import {
|
||||
contractUsers,
|
||||
handleSendOTP,
|
||||
contactBook,
|
||||
handleDownloadPdf,
|
||||
handleToPrint,
|
||||
handleDownloadCertificate,
|
||||
getDefaultSignature,
|
||||
@@ -2000,9 +1999,13 @@ function PdfRequestFiles(props) {
|
||||
<button
|
||||
type="button"
|
||||
className="font-[500] text-[13px] mr-[5px] op-btn op-btn-primary"
|
||||
onClick={() =>
|
||||
handleDownloadPdf(pdfDetails, setIsDownloading)
|
||||
}
|
||||
onClick={() => {
|
||||
setIsCompleted((prev) => ({
|
||||
...prev,
|
||||
isModal: false
|
||||
}));
|
||||
setIsDownloadModal(true);
|
||||
}}
|
||||
>
|
||||
<i
|
||||
className="fa-light fa-download"
|
||||
@@ -2213,6 +2216,7 @@ function PdfRequestFiles(props) {
|
||||
setIsDownloadModal={setIsDownloadModal}
|
||||
isDownloadModal={isDownloadModal}
|
||||
pdfDetails={pdfDetails}
|
||||
isDocId={true}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
|
||||
@@ -1336,6 +1336,7 @@ function SignYourSelf() {
|
||||
setIsAlert={setIsAlert}
|
||||
extUserId={extUserId}
|
||||
activeMailAdapter={activeMailAdapter}
|
||||
setIsDownloadModal={setIsDownloadModal}
|
||||
/>
|
||||
{/* pdf header which contain funish back button */}
|
||||
<Header
|
||||
@@ -1464,6 +1465,7 @@ function SignYourSelf() {
|
||||
setIsDownloadModal={setIsDownloadModal}
|
||||
isDownloadModal={isDownloadModal}
|
||||
pdfDetails={pdfDetails}
|
||||
isDocId={true}
|
||||
/>
|
||||
<TextFontSetting
|
||||
isTextSetting={isTextSetting}
|
||||
|
||||
@@ -2,6 +2,7 @@ import React, { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import ModalUi from "./ModalUi";
|
||||
import {
|
||||
getSignedUrl,
|
||||
handleDownloadCertificate,
|
||||
handleDownloadPdf,
|
||||
sanitizeFileName
|
||||
@@ -21,8 +22,11 @@ function DownloadPdfZip(props) {
|
||||
|
||||
const handleDownload = async () => {
|
||||
if (selectType === 1) {
|
||||
handleDownloadPdf(props.pdfDetails, setIsDownloading);
|
||||
await handleDownloadPdf(props.pdfDetails, setIsDownloading);
|
||||
setSelectType(1);
|
||||
props.setIsDownloadModal(false);
|
||||
} else if (selectType === 2) {
|
||||
setIsDownloading("pdf");
|
||||
const zip = new JSZip();
|
||||
const pdfDetails = props.pdfDetails;
|
||||
const pdfName = pdfDetails?.[0]?.Name || "Document";
|
||||
@@ -30,9 +34,14 @@ function DownloadPdfZip(props) {
|
||||
|
||||
try {
|
||||
// Fetch the first PDF (Signed Document)
|
||||
const pdf1Response = await fetch(pdfUrl);
|
||||
const docId =
|
||||
props.isDocId && !pdfDetails?.[0]?.IsEnableOTP
|
||||
? pdfDetails?.[0]?.objectId
|
||||
: "";
|
||||
const signedUrl = await getSignedUrl(pdfUrl, docId);
|
||||
const pdf1Response = await fetch(signedUrl);
|
||||
if (!pdf1Response.ok) {
|
||||
throw new Error(`Failed to fetch PDF: ${pdfUrl}`);
|
||||
throw new Error(`Failed to fetch PDF: ${signedUrl}`);
|
||||
}
|
||||
const pdf1Blob = await pdf1Response.blob();
|
||||
|
||||
@@ -56,14 +65,16 @@ function DownloadPdfZip(props) {
|
||||
|
||||
// Generate the ZIP and trigger download
|
||||
const zipBlob = await zip.generateAsync({ type: "blob" });
|
||||
saveAs(zipBlob, "pdf-files.zip");
|
||||
saveAs(zipBlob, `${sanitizeFileName(pdfName)}.zip`);
|
||||
setSelectType(1);
|
||||
props.setIsDownloadModal(false);
|
||||
setIsDownloading("");
|
||||
} catch (error) {
|
||||
console.error("Error creating ZIP file:", error);
|
||||
}
|
||||
}
|
||||
};
|
||||
console.log("isDownloading", isDownloading);
|
||||
return (
|
||||
<ModalUi
|
||||
isOpen={props.isDownloadModal}
|
||||
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
checkIsSubscribed,
|
||||
copytoData,
|
||||
fetchUrl,
|
||||
getSignedUrl,
|
||||
replaceMailVaribles
|
||||
} from "../constant/Utils";
|
||||
import Confetti from "react-confetti";
|
||||
@@ -30,6 +31,7 @@ import SubscribeCard from "./SubscribeCard";
|
||||
import { validplan } from "../json/plansArr";
|
||||
import { serverUrl_fn } from "../constant/appinfo";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import DownloadPdfZip from "./DownloadPdfZip";
|
||||
|
||||
const ReportTable = (props) => {
|
||||
const { t } = useTranslation();
|
||||
@@ -71,6 +73,7 @@ const ReportTable = (props) => {
|
||||
const [isSubscribe, setIsSubscribe] = useState(true);
|
||||
const [isModal, setIsModal] = useState({});
|
||||
const [reason, setReason] = useState("");
|
||||
const [isDownloadModal, setIsDownloadModal] = useState(false);
|
||||
const Extand_Class = localStorage.getItem("Extand_Class");
|
||||
const extClass = Extand_Class && JSON.parse(Extand_Class);
|
||||
const startIndex = (currentPage - 1) * props.docPerPage;
|
||||
@@ -649,10 +652,15 @@ const ReportTable = (props) => {
|
||||
setActLoader({ [`${item.objectId}`]: true });
|
||||
const url = item?.SignedUrl || item?.URL || "";
|
||||
const pdfName = item?.Name || "exported_file";
|
||||
const isCompleted = item?.IsCompleted || false;
|
||||
if (url) {
|
||||
try {
|
||||
const signedUrl = await Parse.Cloud.run("getsignedurl", { url: url });
|
||||
await fetchUrl(signedUrl, pdfName);
|
||||
if (isCompleted) {
|
||||
setIsDownloadModal({ [item.objectId]: true });
|
||||
} else {
|
||||
const signedUrl = await getSignedUrl(url);
|
||||
await fetchUrl(signedUrl, pdfName);
|
||||
}
|
||||
setActLoader({});
|
||||
} catch (err) {
|
||||
console.log("err in getsignedurl", err);
|
||||
@@ -2107,6 +2115,14 @@ const ReportTable = (props) => {
|
||||
</div>
|
||||
</ModalUi>
|
||||
)}
|
||||
{isDownloadModal[item.objectId] && (
|
||||
<DownloadPdfZip
|
||||
setIsDownloadModal={setIsDownloadModal}
|
||||
isDownloadModal={isDownloadModal[item.objectId]}
|
||||
pdfDetails={[item]}
|
||||
isDocId={false}
|
||||
/>
|
||||
)}
|
||||
</td>
|
||||
</tr>
|
||||
)
|
||||
|
||||
@@ -139,6 +139,7 @@ export default function reportJson(id, userId) {
|
||||
'TimeToCompleteDays',
|
||||
'Placeholders',
|
||||
'IsSignyourself',
|
||||
'IsCompleted',
|
||||
],
|
||||
};
|
||||
// declined documents report
|
||||
|
||||
Reference in New Issue
Block a user