Skip to content

Commit 669ba9e

Browse files
feat: add download btn in expired document
1 parent 476dcf0 commit 669ba9e

File tree

2 files changed

+50
-82
lines changed

2 files changed

+50
-82
lines changed

apps/OpenSign/src/pages/PdfRequestFiles.js

Lines changed: 33 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ import {
3434
openInNewTab,
3535
getDefaultSignature,
3636
onClickZoomIn,
37-
onClickZoomOut
37+
onClickZoomOut,
38+
fetchUrl
3839
} from "../constant/Utils";
3940
import LoaderWithMsg from "../primitives/LoaderWithMsg";
4041
import HandleError from "../primitives/HandleError";
@@ -340,23 +341,17 @@ function PdfRequestFiles(props) {
340341
}
341342
setUnSignedSigners(placeholdersOrSigners);
342343
setPdfDetails(documentData);
343-
setIsLoading({
344-
isLoad: false
345-
});
344+
setIsLoading({ isLoad: false });
346345
} else if (
347346
documentData === "Error: Something went wrong!" ||
348347
(documentData.result && documentData.result.error)
349348
) {
350349
console.log("err in get template details ");
351350
setHandleError(t("something-went-wrong-mssg"));
352-
setIsLoading({
353-
isLoad: false
354-
});
351+
setIsLoading({ isLoad: false });
355352
} else {
356353
setHandleError(t("no-data"));
357-
setIsLoading({
358-
isLoad: false
359-
});
354+
setIsLoading({ isLoad: false });
360355
}
361356
} catch (err) {
362357
console.log("err in get template details ", err);
@@ -424,16 +419,11 @@ function PdfRequestFiles(props) {
424419
}
425420
if (isCompleted) {
426421
setIsSigned(true);
427-
const data = {
428-
isCertificate: true,
429-
isModal: true
430-
};
422+
const data = { isCertificate: true, isModal: true };
431423
setAlreadySign(true);
432424
setIsCompleted(data);
433425
setIsCelebration(true);
434-
setTimeout(() => {
435-
setIsCelebration(false);
436-
}, 5000);
426+
setTimeout(() => setIsCelebration(false), 5000);
437427
} else if (declined) {
438428
const currentDecline = {
439429
currnt: "another",
@@ -449,9 +439,7 @@ function PdfRequestFiles(props) {
449439
} // Check if the current signer is not a last signer and handle the complete message.
450440
else if (isNextUser) {
451441
setIsCelebration(true);
452-
setTimeout(() => {
453-
setIsCelebration(false);
454-
}, 5000);
442+
setTimeout(() => setIsCelebration(false), 5000);
455443
setIsCompleted({
456444
isModal: true,
457445
message: t("document-signed-alert-1")
@@ -478,7 +466,8 @@ function PdfRequestFiles(props) {
478466
documentData[0].AuditTrail.length > 0 &&
479467
documentData[0].AuditTrail.filter(
480468
(data) =>
481-
data.UserPtr.objectId === currUserId && data.Activity === "Signed"
469+
data.UserPtr?.objectId === currUserId &&
470+
data.Activity === "Signed"
482471
);
483472
if (
484473
checkAlreadySign &&
@@ -558,15 +547,15 @@ function PdfRequestFiles(props) {
558547
for (const item of placeholdersOrSigners) {
559548
const checkEmail = item?.email;
560549
//if email exist then compare user signed by using email else signers objectId
561-
const emailOrId = checkEmail ? item.email : item.objectId;
550+
const emailOrId = checkEmail ? item.email : item?.objectId;
562551
//`isSignedSignature` variable to handle break loop whenever it get true
563552
let isSignedSignature = false;
564553
//checking the signer who signed the document by using audit trail details.
565554
//and save signedSigners and unsignedSigners details
566555
for (const doc of audittrailData) {
567556
const signedExist = checkEmail
568-
? doc?.UserPtr.Email
569-
: doc?.UserPtr.objectId;
557+
? doc?.UserPtr?.Email
558+
: doc?.UserPtr?.objectId;
570559

571560
if (emailOrId === signedExist) {
572561
signers.push({ ...item });
@@ -644,15 +633,11 @@ function PdfRequestFiles(props) {
644633
(documentData.result && documentData.result.error)
645634
) {
646635
setHandleError(t("something-went-wrong-mssg"));
647-
setIsLoading({
648-
isLoad: false
649-
});
636+
setIsLoading({ isLoad: false });
650637
console.log("err in getDocument cloud function ");
651638
} else {
652639
setHandleError(t("no-data"));
653-
setIsUiLoading({
654-
isLoad: false
655-
});
640+
setIsUiLoading({ isLoad: false });
656641
}
657642
//function to get default signatur eof current user from `contracts_Signature` class
658643
const defaultSignRes = await getDefaultSignature(jsonSender.objectId);
@@ -662,15 +647,11 @@ function PdfRequestFiles(props) {
662647
} else if (defaultSignRes?.status === "error") {
663648
setHandleError("Error: Something went wrong!");
664649
}
665-
setIsLoading({
666-
isLoad: false
667-
});
650+
setIsLoading({ isLoad: false });
668651
} catch (err) {
669652
console.log("Error: error in getDocumentDetails", err);
670653
setHandleError("Error: Something went wrong!");
671-
setIsLoading({
672-
isLoad: false
673-
});
654+
setIsLoading({ isLoad: false });
674655
}
675656
};
676657
//function for embed signature or image url in pdf
@@ -1028,9 +1009,7 @@ function PdfRequestFiles(props) {
10281009
openSignUrl +
10291010
" target=_blank>here</a>.</p> </div></div></body> </html>"
10301011
};
1031-
await axios.post(url, params, {
1032-
headers: headers
1033-
});
1012+
await axios.post(url, params, { headers: headers });
10341013
} catch (error) {
10351014
console.log("error", error);
10361015
}
@@ -1193,10 +1172,7 @@ function PdfRequestFiles(props) {
11931172
const img = new Image();
11941173
img.src = defaultSignImg;
11951174
if (img.complete) {
1196-
imgWH = {
1197-
width: img.width,
1198-
height: img.height
1199-
};
1175+
imgWH = { width: img.width, height: img.height };
12001176
}
12011177
}
12021178
//get current signer placeholder position data
@@ -1256,10 +1232,7 @@ function PdfRequestFiles(props) {
12561232
.then(async (result) => {
12571233
const res = result.data;
12581234
if (res) {
1259-
const currentDecline = {
1260-
currnt: "YouDeclined",
1261-
isDeclined: true
1262-
};
1235+
const currentDecline = { currnt: "YouDeclined", isDeclined: true };
12631236
setIsDecline(currentDecline);
12641237
setIsUiLoading(false);
12651238
const params = {
@@ -1318,10 +1291,7 @@ function PdfRequestFiles(props) {
13181291
x.signerObjId === signerObjectId ? { ...x, placeHolder: updatePlace } : x
13191292
);
13201293
setSignerPos(updatesignerPos);
1321-
setDefaultSignAlert({
1322-
isShow: false,
1323-
alertMessage: ""
1324-
});
1294+
setDefaultSignAlert({ isShow: false, alertMessage: "" });
13251295
};
13261296
const handleDontShow = (isChecked) => {
13271297
setIsDontShow(isChecked);
@@ -1502,7 +1472,6 @@ function PdfRequestFiles(props) {
15021472
const SendOtp = async () => {
15031473
try {
15041474
const params = { email: contact.email, docId: res.docId };
1505-
15061475
const Otp = await axios.post(
15071476
`${localStorage.getItem("baseUrl")}/functions/SendOTPMailV1`,
15081477
params,
@@ -1540,10 +1509,7 @@ function PdfRequestFiles(props) {
15401509
"Content-Type": "application/json",
15411510
"X-Parse-Application-Id": parseId
15421511
};
1543-
let body = {
1544-
email: contact.email,
1545-
otp: otp
1546-
};
1512+
let body = { email: contact.email, otp: otp };
15471513
let user = await axios.post(url, body, { headers: headers });
15481514
if (user.data.result === "Invalid Otp") {
15491515
alert(t("invalid-otp"));
@@ -1575,9 +1541,7 @@ function PdfRequestFiles(props) {
15751541
// document.getElementById("my_modal").close();
15761542
setIsPublicContact(false);
15771543
setIsPublicTemplate(false);
1578-
setIsLoading({
1579-
isLoad: false
1580-
});
1544+
setIsLoading({ isLoad: false });
15811545
setDocumentId(res?.docId);
15821546
getDocumentDetails(res?.docId);
15831547
}
@@ -1593,11 +1557,7 @@ function PdfRequestFiles(props) {
15931557
setLoading(false);
15941558
setIsOtp(false);
15951559
setOtp();
1596-
setContact({
1597-
name: "",
1598-
email: "",
1599-
phone: ""
1600-
});
1560+
setContact({ name: "", email: "", phone: "" });
16011561
};
16021562

16031563
const clickOnZoomIn = () => {
@@ -1606,6 +1566,11 @@ function PdfRequestFiles(props) {
16061566
const clickOnZoomOut = () => {
16071567
onClickZoomOut(zoomPercent, scale, setZoomPercent, setScale);
16081568
};
1569+
const handleDownloadBtn = async () => {
1570+
const url = pdfDetails?.[0]?.SignedUrl || pdfDetails?.[0]?.URL;
1571+
const name = pdfDetails?.[0]?.Name;
1572+
await fetchUrl(url, name);
1573+
};
16091574
return (
16101575
<DndProvider backend={HTML5Backend}>
16111576
<Title title={props.templateId ? "Public Sign" : "Request Sign"} />
@@ -1696,9 +1661,9 @@ function PdfRequestFiles(props) {
16961661
headMsg={t("document-decline")}
16971662
bodyMssg={
16981663
isDecline.currnt === "Sure"
1699-
? t("decline-alert-2")
1664+
? t("decline-alert-1")
17001665
: isDecline.currnt === "YouDeclined"
1701-
? t("decline-alert-1")
1666+
? t("decline-alert-2")
17021667
: isDecline.currnt === "another" && t("decline-alert-3")
17031668
}
17041669
footerMessage={isDecline.currnt === "Sure"}
@@ -1710,6 +1675,8 @@ function PdfRequestFiles(props) {
17101675
show={isExpired}
17111676
headMsg={t("expired-doc-title")}
17121677
bodyMssg={t("expired-on-mssg", { expiredDate })}
1678+
isDownloadBtn={true}
1679+
handleDownloadBtn={handleDownloadBtn}
17131680
/>
17141681
{!isEmailVerified && (
17151682
<VerifyEmail
@@ -1723,7 +1690,6 @@ function PdfRequestFiles(props) {
17231690
handleResend={handleResend}
17241691
/>
17251692
)}
1726-
17271693
<ModalUi
17281694
isOpen={isPublicContact}
17291695
title={isOtp ? t("verify-email-1") : t("contact-details")}

apps/OpenSign/src/primitives/PdfDeclineModal.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,30 @@ import React, { useState } from "react";
22
import "../styles/signature.css";
33
import { useTranslation } from "react-i18next";
44

5-
function CustomModal({
6-
show,
7-
headMsg,
8-
bodyMssg,
9-
footerMessage,
10-
declineDoc,
11-
setIsDecline
12-
}) {
5+
function CustomModal(props) {
136
const { t } = useTranslation();
147
const [reason, setReason] = useState("");
158
return (
16-
show && (
9+
props.show && (
1710
<dialog className="op-modal op-modal-open absolute z-[448]">
1811
<div className="w-[95%] md:w-[60%] lg:w-[40%] op-modal-box p-0 overflow-y-auto hide-scrollbar text-sm">
1912
<h3 className="text-base-content font-bold text-lg pt-[15px] px-[20px]">
20-
{headMsg && headMsg}
13+
{props?.headMsg && props?.headMsg}
2114
</h3>
2215
<div className="p-[10px] px-[20px]">
23-
<p className="text-[15px]">{bodyMssg && bodyMssg}</p>
16+
<p className="text-[15px]">{props.bodyMssg && props.bodyMssg}</p>
2417
</div>
25-
{footerMessage && (
18+
{props.isDownloadBtn && (
19+
<div className="flex justify-start w-full ml-[20px] mb-3 mt-1">
20+
<button
21+
className="op-btn op-btn-primary "
22+
onClick={() => props.handleDownloadBtn()}
23+
>
24+
Download
25+
</button>
26+
</div>
27+
)}
28+
{props.footerMessage && (
2629
<>
2730
<div className="mx-3">
2831
<textarea
@@ -33,14 +36,13 @@ function CustomModal({
3336
onChange={(e) => setReason(e.target.value)}
3437
></textarea>
3538
</div>
36-
{/* <div className="h-[1px] bg-[#9f9f9f] w-full"></div> */}
3739
<div className="m-[15px]">
3840
<button
3941
className="op-btn op-btn-primary mr-2 px-6"
4042
type="button"
4143
onClick={() => {
4244
setReason("");
43-
declineDoc(reason);
45+
props.declineDoc(reason);
4446
}}
4547
>
4648
{t("yes")}
@@ -50,7 +52,7 @@ function CustomModal({
5052
className="op-btn op-btn-secondary"
5153
onClick={() => {
5254
setReason("");
53-
setIsDecline({ isDeclined: false });
55+
props.setIsDecline({ isDeclined: false });
5456
}}
5557
>
5658
{t("close")}

0 commit comments

Comments
 (0)