mirror of
https://github.com/OpenSignLabs/OpenSign.git
synced 2026-08-17 21:25:54 +02:00
feat: attach digital sign to completion certificate
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
import React from "react";
|
||||
import PrevNext from "./PrevNext";
|
||||
import { PDFDownloadLink } from "@react-pdf/renderer";
|
||||
import Certificate from "./Certificate";
|
||||
import printModule from "print-js";
|
||||
import { getBase64FromUrl } from "../../constant/Utils";
|
||||
import { saveAs } from "file-saver";
|
||||
@@ -13,14 +11,11 @@ import { themeColor } from "../../constant/const";
|
||||
function Header({
|
||||
isPdfRequestFiles,
|
||||
isPlaceholder,
|
||||
recipient,
|
||||
setIsDecline,
|
||||
pageNumber,
|
||||
isAlreadySign,
|
||||
allPages,
|
||||
changePage,
|
||||
pdfUrl,
|
||||
documentStatus,
|
||||
embedWidgetsData,
|
||||
pdfDetails,
|
||||
signerPos,
|
||||
@@ -94,109 +89,15 @@ function Header({
|
||||
// Replace spaces with underscore
|
||||
return pdfName.replace(/ /g, "_");
|
||||
};
|
||||
//certificate generate and download component in mobile view
|
||||
const CertificateDropDown = () => {
|
||||
//after generate download certifcate pdf
|
||||
const handleDownload = (pdfBlob, fileName) => {
|
||||
if (pdfBlob) {
|
||||
const url = window.URL.createObjectURL(pdfBlob);
|
||||
// Create a temporary anchor element
|
||||
const link = document.createElement("a");
|
||||
link.href = url;
|
||||
link.download = fileName;
|
||||
// Append the anchor to the body
|
||||
document.body.appendChild(link);
|
||||
// Programmatically click the anchor to trigger the download
|
||||
link.click();
|
||||
// Remove the anchor from the body
|
||||
document.body.removeChild(link);
|
||||
// Release the object URL to free up resources
|
||||
window.URL.revokeObjectURL(url);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<PDFDownloadLink
|
||||
onClick={(e) => e.preventDefault()}
|
||||
style={{ textDecoration: "none", zIndex: "35" }}
|
||||
document={<Certificate pdfData={pdfDetails} />}
|
||||
>
|
||||
{({ blob, loading }) => (
|
||||
<>
|
||||
{loading ? (
|
||||
<div
|
||||
style={{
|
||||
border: "none",
|
||||
backgroundColor: "#fff"
|
||||
}}
|
||||
>
|
||||
<i
|
||||
className="fa-solid fa-award"
|
||||
style={{ marginRight: "2px" }}
|
||||
aria-hidden="true"
|
||||
></i>
|
||||
Certificate
|
||||
</div>
|
||||
) : (
|
||||
<div
|
||||
style={{ border: "none", backgroundColor: "#fff" }}
|
||||
onClick={() =>
|
||||
handleDownload(
|
||||
blob,
|
||||
`completion certificate-${
|
||||
pdfDetails[0] && pdfDetails[0].Name
|
||||
}.pdf`
|
||||
)
|
||||
}
|
||||
>
|
||||
<i
|
||||
className="fa-solid fa-award"
|
||||
style={{ marginRight: "2px" }}
|
||||
aria-hidden="true"
|
||||
></i>
|
||||
Certificate
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</PDFDownloadLink>
|
||||
);
|
||||
};
|
||||
const CertificateComponent = () => {
|
||||
return (
|
||||
<PDFDownloadLink
|
||||
style={{ textDecoration: "none" }}
|
||||
document={<Certificate pdfData={pdfDetails} />}
|
||||
fileName={`completion certificate-${
|
||||
pdfDetails[0] && pdfDetails[0].Name
|
||||
}.pdf`}
|
||||
>
|
||||
{({ loading }) => (
|
||||
<button
|
||||
type="button"
|
||||
className="defaultBtn certificateBtn"
|
||||
disabled={loading}
|
||||
style={{
|
||||
display: "flex",
|
||||
flexDirection: "row",
|
||||
alignItems: "center"
|
||||
}}
|
||||
>
|
||||
<i
|
||||
className="fa-solid fa-award"
|
||||
style={{
|
||||
color: "white",
|
||||
fontSize: "15px",
|
||||
marginRight: "3px"
|
||||
}}
|
||||
aria-hidden="true"
|
||||
></i>
|
||||
Certificate
|
||||
</button>
|
||||
)}
|
||||
</PDFDownloadLink>
|
||||
);
|
||||
//handle download signed pdf
|
||||
const handleDownloadCertificate = () => {
|
||||
if (pdfDetails?.length > 0 && pdfDetails[0]?.CertificateUrl) {
|
||||
const certificateUrl = pdfDetails[0] && pdfDetails[0]?.CertificateUrl;
|
||||
saveAs(certificateUrl, `Certificate_signed_by_OpenSign™.pdf`);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div style={{ padding: "5px 0px 5px 0px" }} className="mobileHead">
|
||||
{isMobile && isShowHeader ? (
|
||||
@@ -210,11 +111,7 @@ function Header({
|
||||
}}
|
||||
>
|
||||
<div className="preBtn2">
|
||||
<div
|
||||
onClick={() => {
|
||||
navigate(-1);
|
||||
}}
|
||||
>
|
||||
<div onClick={() => navigate(-1)}>
|
||||
<i
|
||||
className="fa fa-arrow-left"
|
||||
aria-hidden="true"
|
||||
@@ -266,7 +163,6 @@ function Header({
|
||||
<i className="fa fa-ellipsis-v" aria-hidden="true"></i>
|
||||
</div>
|
||||
</DropdownMenu.Trigger>
|
||||
|
||||
<DropdownMenu.Portal>
|
||||
<DropdownMenu.Content
|
||||
className="DropdownMenuContent"
|
||||
@@ -290,42 +186,42 @@ function Header({
|
||||
Download
|
||||
</div>
|
||||
</DropdownMenu.Item>
|
||||
{recipient && pdfDetails[0] && pdfDetails.length > 0 ? (
|
||||
<DropdownMenu.Item className="DropdownMenuItem">
|
||||
<CertificateDropDown />
|
||||
{isCompleted && (
|
||||
<DropdownMenu.Item
|
||||
className="DropdownMenuItem"
|
||||
onClick={() => handleDownloadCertificate()}
|
||||
>
|
||||
<div
|
||||
style={{ border: "none", backgroundColor: "#fff" }}
|
||||
>
|
||||
<i
|
||||
className="fa-solid fa-award"
|
||||
style={{ marginRight: "2px" }}
|
||||
aria-hidden="true"
|
||||
></i>
|
||||
Certificate
|
||||
</div>
|
||||
</DropdownMenu.Item>
|
||||
) : isPdfRequestFiles &&
|
||||
alreadySign &&
|
||||
isCompleted.isCertificate ? (
|
||||
<DropdownMenu.Item className="DropdownMenuItem">
|
||||
<CertificateDropDown />
|
||||
)}
|
||||
{isSignYourself && (
|
||||
<DropdownMenu.Item
|
||||
className="DropdownMenuItem"
|
||||
onClick={() => setIsEmail(true)}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
flexDirection: "row"
|
||||
}}
|
||||
>
|
||||
<i
|
||||
className="fa fa-envelope"
|
||||
style={{ marginRight: "2px" }}
|
||||
aria-hidden="true"
|
||||
></i>
|
||||
Mail
|
||||
</div>
|
||||
</DropdownMenu.Item>
|
||||
) : (
|
||||
isSignYourself && (
|
||||
<>
|
||||
<DropdownMenu.Item className="DropdownMenuItem">
|
||||
<CertificateDropDown />
|
||||
</DropdownMenu.Item>
|
||||
<DropdownMenu.Item
|
||||
className="DropdownMenuItem"
|
||||
onClick={() => setIsEmail(true)}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
flexDirection: "row"
|
||||
}}
|
||||
>
|
||||
<i
|
||||
className="fa fa-envelope"
|
||||
style={{ marginRight: "2px" }}
|
||||
aria-hidden="true"
|
||||
></i>
|
||||
Mail
|
||||
</div>
|
||||
</DropdownMenu.Item>
|
||||
</>
|
||||
)
|
||||
)}
|
||||
<DropdownMenu.Item
|
||||
className="DropdownMenuItem"
|
||||
@@ -337,7 +233,6 @@ function Header({
|
||||
flexDirection: "row"
|
||||
}}
|
||||
>
|
||||
{" "}
|
||||
<i
|
||||
className="fa fa-print"
|
||||
aria-hidden="true"
|
||||
@@ -416,113 +311,34 @@ function Header({
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className="signatureHeader headerBtn">
|
||||
<div className="flex flex-wrap justify-between items-center mt-[5px]">
|
||||
<PrevNext
|
||||
pageNumber={pageNumber}
|
||||
allPages={allPages}
|
||||
changePage={changePage}
|
||||
/>
|
||||
|
||||
{recipient ? (
|
||||
pdfUrl || isAlreadySign.mssg ? (
|
||||
<div style={{ display: "flex", flexDirection: "row" }}>
|
||||
{pdfDetails && pdfDetails.length > 0 && (
|
||||
<CertificateComponent />
|
||||
)}
|
||||
<button
|
||||
onClick={handleToPrint}
|
||||
style={{
|
||||
display: "flex",
|
||||
flexDirection: "row",
|
||||
alignItems: "center"
|
||||
}}
|
||||
className="defaultBtn printBtn"
|
||||
>
|
||||
<i
|
||||
className="fa fa-print"
|
||||
style={{
|
||||
fontSize: "15px",
|
||||
marginRight: "3px",
|
||||
color: "white"
|
||||
}}
|
||||
aria-hidden="true"
|
||||
></i>
|
||||
Print
|
||||
</button>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
style={{
|
||||
display: "flex",
|
||||
flexDirection: "row",
|
||||
alignItems: "center"
|
||||
}}
|
||||
className="defaultBtn downloadBtn"
|
||||
onClick={() => handleDownloadPdf()}
|
||||
>
|
||||
<i
|
||||
className="fa fa-download"
|
||||
style={{
|
||||
color: "white",
|
||||
fontSize: "15px",
|
||||
marginRight: "3px"
|
||||
}}
|
||||
aria-hidden="true"
|
||||
></i>
|
||||
Download
|
||||
</button>
|
||||
</div>
|
||||
) : (
|
||||
<div style={{ display: "flex", flexDirection: "row" }}>
|
||||
<button
|
||||
style={{
|
||||
background: "#de4337"
|
||||
}}
|
||||
className="finishBtn hoverCss"
|
||||
onClick={() => {
|
||||
handleDeclinePdfAlert();
|
||||
}}
|
||||
>
|
||||
Decline
|
||||
</button>
|
||||
|
||||
<button
|
||||
data-tut="reactourThird"
|
||||
style={{
|
||||
background: !pdfUrl ? "#188ae2" : "#d3edeb"
|
||||
}}
|
||||
className="finishBtn sendHover"
|
||||
onClick={() => {
|
||||
if (!pdfUrl) {
|
||||
embedWidgetsData();
|
||||
}
|
||||
}}
|
||||
>
|
||||
Finish
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
) : isPlaceholder ? (
|
||||
{isPlaceholder ? (
|
||||
<>
|
||||
{!isMailSend &&
|
||||
signersdata.length > 0 &&
|
||||
signersdata.length !== filterPrefill.length && (
|
||||
<div>
|
||||
{filterPrefill.length === 0 ? (
|
||||
<span style={{ fontSize: "13px", color: "#f5405e" }}>
|
||||
Add {signersdata.length - filterPrefill.length}{" "}
|
||||
recipients signature
|
||||
</span>
|
||||
) : (
|
||||
<span style={{ fontSize: "13px", color: "#f5405e" }}>
|
||||
Add {signersdata.length - filterPrefill.length} more
|
||||
recipients signature
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div>
|
||||
<div className="flex mx-[100px] lg:mx-0 order-last lg:order-none">
|
||||
{!isMailSend &&
|
||||
signersdata.length > 0 &&
|
||||
signersdata.length !== filterPrefill.length && (
|
||||
<div>
|
||||
{filterPrefill.length === 0 ? (
|
||||
<span style={{ fontSize: "13px", color: "#f5405e" }}>
|
||||
Add {signersdata.length - filterPrefill.length}{" "}
|
||||
recipients signature
|
||||
</span>
|
||||
) : (
|
||||
<span style={{ fontSize: "13px", color: "#f5405e" }}>
|
||||
Add {signersdata.length - filterPrefill.length} more
|
||||
recipients signature
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex">
|
||||
{setIsEditTemplate && (
|
||||
<button
|
||||
onClick={() => setIsEditTemplate(true)}
|
||||
@@ -540,93 +356,79 @@ function Header({
|
||||
navigate(-1);
|
||||
}}
|
||||
type="button"
|
||||
className="defaultBtn backBtn"
|
||||
className="flex flex-row items-center shadow rounded-[3px] py-[3px] px-[18px] text-black font-[500] text-sm mr-[5px] bg-white"
|
||||
>
|
||||
Back
|
||||
</button>
|
||||
|
||||
<button
|
||||
disabled={isMailSend && true}
|
||||
data-tut="reactourFour"
|
||||
className="flex flex-row items-center shadow rounded-[3px] py-[3px] px-[18px] font-[500] text-sm mr-[5px]"
|
||||
style={{
|
||||
background: isMailSend ? "rgb(203, 203, 203)" : "#188ae2",
|
||||
color: isMailSend && "rgb(77, 75, 75)"
|
||||
color: isMailSend ? "rgb(77, 75, 75)" : "white"
|
||||
}}
|
||||
onClick={() => {
|
||||
alertSendEmail();
|
||||
}}
|
||||
className={isMailSend ? "sendMail" : "sendMail sendHover"}
|
||||
>
|
||||
{completeBtnTitle ? completeBtnTitle : "Send"}
|
||||
{completeBtnTitle
|
||||
? completeBtnTitle
|
||||
: isMailSend
|
||||
? "Sent"
|
||||
: "Send"}
|
||||
</button>
|
||||
</div>
|
||||
</>
|
||||
) : isPdfRequestFiles ? (
|
||||
alreadySign ? (
|
||||
<div style={{ display: "flex", flexDirection: "row" }}>
|
||||
{isCompleted.isCertificate && <CertificateComponent />}
|
||||
{isCompleted && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => handleDownloadCertificate()}
|
||||
className="flex flex-row items-center shadow rounded-[3px] py-[3px] px-[11px] text-white font-[500] text-[13px] mr-[5px] bg-[#08bc66]"
|
||||
>
|
||||
<i
|
||||
className="fa-solid fa-award py-[3px]"
|
||||
aria-hidden="true"
|
||||
></i>
|
||||
<span className="hidden lg:block ml-1">Certificate</span>
|
||||
</button>
|
||||
)}
|
||||
|
||||
<button
|
||||
onClick={handleToPrint}
|
||||
type="button"
|
||||
className="defaultBtn printBtn"
|
||||
style={{
|
||||
display: "flex",
|
||||
flexDirection: "row",
|
||||
alignItems: "center"
|
||||
}}
|
||||
className="flex flex-row items-center shadow rounded-[3px] py-[3px] px-[11px] text-white font-[500] text-[13px] mr-[5px] bg-[#188ae2]"
|
||||
>
|
||||
<i
|
||||
className="fa fa-print"
|
||||
style={{
|
||||
fontSize: "15px",
|
||||
marginRight: "3px",
|
||||
color: "white"
|
||||
}}
|
||||
aria-hidden="true"
|
||||
></i>
|
||||
Print
|
||||
<i className="fa fa-print py-[3px]" aria-hidden="true"></i>
|
||||
<span className="hidden lg:block ml-1">Print</span>
|
||||
</button>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
className="defaultBtn downloadBtn"
|
||||
style={{
|
||||
display: "flex",
|
||||
flexDirection: "row",
|
||||
alignItems: "center"
|
||||
}}
|
||||
className="flex flex-row items-center shadow rounded-[3px] py-[3px] px-[11px] text-white font-[500] text-[13px] mr-[5px] bg-[#f14343]"
|
||||
onClick={() => handleDownloadPdf()}
|
||||
>
|
||||
<i
|
||||
className="fa fa-download"
|
||||
style={{
|
||||
color: "white",
|
||||
fontSize: "15px",
|
||||
marginRight: "3px"
|
||||
}}
|
||||
aria-hidden="true"
|
||||
></i>
|
||||
Download
|
||||
<i className="fa fa-download py-[3px]" aria-hidden="true"></i>
|
||||
<span className="hidden lg:block ml-1">Download</span>
|
||||
</button>
|
||||
</div>
|
||||
) : (
|
||||
<div>
|
||||
<div className="flex">
|
||||
<button
|
||||
onClick={() => {
|
||||
navigate(-1);
|
||||
}}
|
||||
onClick={() => navigate(-1)}
|
||||
type="button"
|
||||
className="defaultBtn backBtn"
|
||||
className="flex flex-row items-center shadow rounded-[3px] py-[3px] px-[18px] text-black font-[500] text-sm mr-[5px] bg-white"
|
||||
>
|
||||
Back
|
||||
</button>
|
||||
{currentSigner && (
|
||||
<>
|
||||
<button
|
||||
style={{
|
||||
background: "#de4337"
|
||||
}}
|
||||
className="finishBtn hoverCss"
|
||||
style={{ background: "#de4337" }}
|
||||
className="flex flex-row items-center shadow rounded-[3px] py-[3px] px-[18px] text-white font-[500] text-[13px] mr-[5px] bg-[#f14343]"
|
||||
onClick={() => {
|
||||
handleDeclinePdfAlert();
|
||||
}}
|
||||
@@ -638,7 +440,7 @@ function Header({
|
||||
background: "#188ae2"
|
||||
}}
|
||||
type="button"
|
||||
className="finishBtn sendHover"
|
||||
className="flex flex-row items-center shadow rounded-[3px] py-[3px] px-[18px] text-white font-[500] text-[13px] mr-[5px] bg-[#188ae2]"
|
||||
onClick={() => {
|
||||
embedWidgetsData();
|
||||
}}
|
||||
@@ -649,93 +451,61 @@ function Header({
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
) : pdfUrl || (documentStatus && documentStatus.isCompleted) ? (
|
||||
) : isCompleted ? (
|
||||
<div style={{ display: "flex", flexDirection: "row" }}>
|
||||
<CertificateComponent />
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => handleDownloadCertificate()}
|
||||
className="flex flex-row items-center shadow rounded-[3px] py-[3px] px-[11px] text-white font-[500] text-[13px] mr-[5px] bg-[#08bc66]"
|
||||
>
|
||||
<i
|
||||
className="fa-solid fa-award py-[3px]"
|
||||
aria-hidden="true"
|
||||
></i>
|
||||
<span className="hidden lg:block ml-1">Certificate</span>
|
||||
</button>
|
||||
<button
|
||||
onClick={handleToPrint}
|
||||
type="button"
|
||||
style={{
|
||||
display: "flex",
|
||||
flexDirection: "row",
|
||||
alignItems: "center"
|
||||
}}
|
||||
className="defaultBtn printBtn"
|
||||
className="flex flex-row items-center shadow rounded-[3px] py-[3px] px-[11px] text-white font-[500] text-[13px] mr-[5px] bg-[#188ae2]"
|
||||
>
|
||||
<i
|
||||
className="fa fa-print"
|
||||
style={{
|
||||
fontSize: "15px",
|
||||
marginRight: "3px",
|
||||
color: "white"
|
||||
}}
|
||||
aria-hidden="true"
|
||||
></i>
|
||||
Print
|
||||
<i className="fa fa-print py-[3px]" aria-hidden="true"></i>
|
||||
<span className="hidden lg:block ml-1">Print</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="defaultBtn downloadBtn"
|
||||
style={{
|
||||
display: "flex",
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
marginLeft: "10px"
|
||||
}}
|
||||
className="flex flex-row items-center shadow rounded-[3px] py-[3px] px-[11px] text-white font-[500] text-[13px] mr-[5px] bg-[#f14343]"
|
||||
onClick={() => handleDownloadPdf()}
|
||||
>
|
||||
<i
|
||||
className="fa fa-download"
|
||||
style={{
|
||||
color: "white",
|
||||
fontSize: "15px",
|
||||
marginRight: "3px"
|
||||
}}
|
||||
aria-hidden="true"
|
||||
></i>
|
||||
Download
|
||||
<i className="fa fa-download py-[3px]" aria-hidden="true"></i>
|
||||
<span className="hidden lg:block ml-1">Download</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="defaultBtn mailBtn"
|
||||
style={{
|
||||
display: "flex",
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
marginLeft: "10px"
|
||||
}}
|
||||
className="flex flex-row items-center shadow rounded-[3px] py-[3px] px-[11px] text-white font-[500] text-[13px] mr-[5px] bg-[#3ba7e5]"
|
||||
onClick={() => setIsEmail(true)}
|
||||
>
|
||||
<i
|
||||
className="fa fa-envelope"
|
||||
style={{
|
||||
color: "white",
|
||||
fontSize: "15px",
|
||||
marginRight: "3px"
|
||||
}}
|
||||
aria-hidden="true"
|
||||
></i>
|
||||
Mail
|
||||
<i className="fa fa-envelope py-[3px]" aria-hidden="true"></i>
|
||||
<span className="hidden lg:block ml-1">Mail</span>
|
||||
</button>
|
||||
</div>
|
||||
) : (
|
||||
<div>
|
||||
<div className="flex">
|
||||
<button
|
||||
onClick={() => {
|
||||
navigate(-1);
|
||||
}}
|
||||
type="button"
|
||||
className="defaultBtn backBtn"
|
||||
className="flex flex-row items-center shadow rounded-[3px] py-[3px] px-[18px] text-black font-[500] text-sm mr-[5px] bg-white"
|
||||
>
|
||||
Back
|
||||
</button>
|
||||
|
||||
<button
|
||||
style={{
|
||||
background: "#188ae2"
|
||||
}}
|
||||
type="button"
|
||||
className="finishBtn sendHover"
|
||||
className="flex flex-row items-center shadow rounded-[3px] py-[3px] px-[18px] text-white font-[500] text-[13px] mr-[5px] bg-[#188ae2]"
|
||||
onClick={() => {
|
||||
if (!pdfUrl) {
|
||||
embedWidgetsData();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import React from "react";
|
||||
import { themeColor } from "../../constant/const";
|
||||
|
||||
function PrevNext({ pageNumber, allPages, changePage }) {
|
||||
//for go to previous page
|
||||
@@ -14,41 +15,35 @@ function PrevNext({ pageNumber, allPages, changePage }) {
|
||||
<div>
|
||||
<div className="preBtn1">
|
||||
<button
|
||||
style={{
|
||||
padding: "3px 20px ",
|
||||
fontSize: "10px",
|
||||
background: "#d3edeb",
|
||||
fontWeight: "600",
|
||||
|
||||
border: "0px",
|
||||
marginRight: "5px"
|
||||
}}
|
||||
className="py-[3px] px-[10px] text-xs bg-[#d3edeb] font-[600] mr-[5px]"
|
||||
disabled={pageNumber <= 1}
|
||||
onClick={previousPage}
|
||||
>
|
||||
Prev
|
||||
<span className="block lg:hidden">
|
||||
<i
|
||||
className="fa fa-backward"
|
||||
aria-hidden="true"
|
||||
style={{ color: themeColor, cursor: "pointer" }}
|
||||
></i>
|
||||
</span>
|
||||
<span className="lg:block hidden">Prev</span>
|
||||
</button>
|
||||
<span
|
||||
style={{
|
||||
fontSize: "13px",
|
||||
fontWeight: "600"
|
||||
}}
|
||||
>
|
||||
<span className="text-xs font-[500]">
|
||||
{pageNumber || (allPages ? 1 : "--")} of {allPages || "--"}
|
||||
</span>
|
||||
<button
|
||||
style={{
|
||||
padding: "3px 20px ",
|
||||
fontSize: "10px",
|
||||
background: "#d3edeb",
|
||||
fontWeight: "600",
|
||||
marginLeft: "5px",
|
||||
border: "0px"
|
||||
}}
|
||||
className="py-[3px] px-[10px] text-xs bg-[#d3edeb] font-[600] ml-[5px]"
|
||||
disabled={pageNumber >= allPages}
|
||||
onClick={nextPage}
|
||||
>
|
||||
Next
|
||||
<span className="block lg:hidden">
|
||||
<i
|
||||
className="fa fa-forward"
|
||||
aria-hidden="true"
|
||||
style={{ color: themeColor, cursor: "pointer" }}
|
||||
></i>
|
||||
</span>
|
||||
<span className="lg:block hidden">Next</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1152,7 +1152,7 @@ function PdfRequestFiles() {
|
||||
isOpen={isCompleted.isModal}
|
||||
title={"Sign Documents"}
|
||||
handleClose={() => {
|
||||
setIsCompleted({ isModal: false, isCertificate: true });
|
||||
setIsCompleted((prev) => ({ ...prev, isModal: false }));
|
||||
}}
|
||||
>
|
||||
<div style={{ height: "100%", padding: 20 }}>
|
||||
@@ -1170,12 +1170,12 @@ function PdfRequestFiles() {
|
||||
<button
|
||||
type="button"
|
||||
className="finishBtn cancelBtn"
|
||||
onClick={() =>
|
||||
setIsCompleted({
|
||||
isModal: false,
|
||||
isCertificate: true
|
||||
})
|
||||
}
|
||||
onClick={() => {
|
||||
setIsCompleted((prev) => ({
|
||||
...prev,
|
||||
isModal: false
|
||||
}));
|
||||
}}
|
||||
>
|
||||
Close
|
||||
</button>
|
||||
@@ -1213,7 +1213,7 @@ function PdfRequestFiles() {
|
||||
pdfDetails={pdfDetails}
|
||||
signerPos={signerPos}
|
||||
isSigned={isSigned}
|
||||
isCompleted={isCompleted}
|
||||
isCompleted={isCompleted.isCertificate}
|
||||
embedWidgetsData={embedWidgetsData}
|
||||
isShowHeader={true}
|
||||
setIsDecline={setIsDecline}
|
||||
|
||||
@@ -67,7 +67,6 @@ function SignYourSelf() {
|
||||
const [pdfOriginalWidth, setPdfOriginalWidth] = useState();
|
||||
const [successEmail, setSuccessEmail] = useState(false);
|
||||
const imageRef = useRef(null);
|
||||
const [documentStatus, setDocumentStatus] = useState({ isCompleted: false });
|
||||
const [myInitial, setMyInitial] = useState("");
|
||||
const [isInitial, setIsInitial] = useState(false);
|
||||
const [isUiLoading, setIsUiLoading] = useState(false);
|
||||
@@ -100,6 +99,7 @@ function SignYourSelf() {
|
||||
const [isAlert, setIsAlert] = useState({ isShow: false, alertMessage: "" });
|
||||
const [isDontShow, setIsDontShow] = useState(false);
|
||||
const [extUserId, setExtUserId] = useState("");
|
||||
const [isCompleted, setIsCompleted] = useState(false);
|
||||
const divRef = useRef(null);
|
||||
const nodeRef = useRef(null);
|
||||
const [, drop] = useDrop({
|
||||
@@ -190,10 +190,7 @@ function SignYourSelf() {
|
||||
setExtUserId(documentData[0]?.ExtUserPtr?.objectId);
|
||||
isCompleted = documentData[0].IsCompleted && documentData[0].IsCompleted;
|
||||
if (isCompleted) {
|
||||
const docStatus = {
|
||||
isCompleted: isCompleted
|
||||
};
|
||||
setDocumentStatus(docStatus);
|
||||
setIsCompleted(true);
|
||||
setPdfUrl(documentData[0].SignedUrl);
|
||||
const alreadySign = {
|
||||
status: true,
|
||||
@@ -1129,7 +1126,6 @@ function SignYourSelf() {
|
||||
allPages={allPages}
|
||||
changePage={changePage}
|
||||
pdfUrl={pdfUrl}
|
||||
documentStatus={documentStatus}
|
||||
embedWidgetsData={embedWidgetsData}
|
||||
pdfDetails={pdfDetails}
|
||||
isShowHeader={true}
|
||||
@@ -1137,6 +1133,7 @@ function SignYourSelf() {
|
||||
alreadySign={pdfUrl ? true : false}
|
||||
isSignYourself={true}
|
||||
setIsEmail={setIsEmail}
|
||||
isCompleted={isCompleted}
|
||||
/>
|
||||
|
||||
<div data-tut="reactourSecond">
|
||||
@@ -1189,7 +1186,7 @@ function SignYourSelf() {
|
||||
}}
|
||||
className="autoSignScroll"
|
||||
>
|
||||
{!documentStatus.isCompleted ? (
|
||||
{!isCompleted ? (
|
||||
<div>
|
||||
<WidgetComponent
|
||||
dataTut="reactourFirst"
|
||||
|
||||
@@ -395,14 +395,6 @@
|
||||
margin-left: 10px;
|
||||
}
|
||||
|
||||
.backBtn {
|
||||
background-color: white;
|
||||
}
|
||||
|
||||
.backBtn:hover {
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1), 0 2px 4px rgba(0, 0, 0, 0.18);
|
||||
}
|
||||
|
||||
.defaultBtn {
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.18);
|
||||
padding: 3px 26px;
|
||||
@@ -420,42 +412,6 @@
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.downloadBtn {
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.18);
|
||||
padding: 3px 15px !important;
|
||||
background-color: rgb(241 79 79);
|
||||
border: none !important;
|
||||
color: white !important;
|
||||
}
|
||||
|
||||
.downloadBtn:hover {
|
||||
box-shadow: 0 2px 4px rgba(154, 36, 36, 0.1), 0 2px 4px rgba(0, 0, 0, 0.18);
|
||||
}
|
||||
|
||||
.printBtn {
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.18);
|
||||
padding: 3px 15px !important;
|
||||
background: #188ae2;
|
||||
border: none !important;
|
||||
color: white !important;
|
||||
}
|
||||
|
||||
.printBtn:hover {
|
||||
box-shadow: 0 2px 4px rgba(23, 48, 137, 0.1), 0 2px 4px rgba(0, 0, 0, 0.18);
|
||||
}
|
||||
|
||||
.certificateBtn {
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.18);
|
||||
padding: 3px 15px !important;
|
||||
background: #08bc66;
|
||||
border: none !important;
|
||||
color: white !important;
|
||||
text-decoration: none !important;
|
||||
}
|
||||
|
||||
.certificateBtn:hover {
|
||||
box-shadow: 0 2px 4px rgba(15, 150, 87, 0.1), 0 2px 4px rgba(0, 0, 0, 0.18);
|
||||
}
|
||||
|
||||
.signerList {
|
||||
overflow-y: scroll;
|
||||
@@ -557,13 +513,6 @@
|
||||
position: "relative";
|
||||
}
|
||||
|
||||
.signatureHeader {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
.signerComponent {
|
||||
/* box-shadow: rgba(17, 12, 46, 0.15) 0px 48px 100px 0px; */
|
||||
|
||||
@@ -5,9 +5,7 @@ async function DocumentBeforesave(request) {
|
||||
const oldDocument = request.original;
|
||||
|
||||
// Check if SignedUrl field has been added (transition from undefined to defined)
|
||||
if (!oldDocument.get('SignedUrl') && document.get('SignedUrl')) {
|
||||
const SignedUrl = document.get('SignedUrl');
|
||||
|
||||
if (!oldDocument?.get('SignedUrl') && document?.get('SignedUrl')) {
|
||||
// Update count in contracts_Users class
|
||||
const query = new Parse.Query('contracts_Users');
|
||||
query.equalTo('objectId', oldDocument.get('ExtUserPtr').id);
|
||||
|
||||
@@ -0,0 +1,244 @@
|
||||
import { PDFDocument, StandardFonts, rgb } from 'pdf-lib';
|
||||
import fs from 'node:fs';
|
||||
export default async function GenerateCertificate(docDetails) {
|
||||
const pdfDoc = await PDFDocument.create();
|
||||
const timesRomanFont = await pdfDoc.embedFont(StandardFonts.TimesRoman);
|
||||
const pngUrl = fs.readFileSync('./logo.png').buffer;
|
||||
const pngImage = await pdfDoc.embedPng(pngUrl);
|
||||
const page = pdfDoc.addPage();
|
||||
const { width, height } = page.getSize();
|
||||
const startX = 15;
|
||||
const startY = 15;
|
||||
const borderColor = rgb(0.12, 0.12, 0.12);
|
||||
const titleColor = rgb(0, 0.2, 0.4); //rgb(0, 0.53, 0.71);
|
||||
const titleUnderline = rgb(0, 0.2, 0.4); // rgb(0.12, 0.12, 0.12);
|
||||
const title = 25;
|
||||
const subtitle = 20;
|
||||
const text = 14;
|
||||
const textKeyColor = rgb(0.12, 0.12, 0.12);
|
||||
const textValueColor = rgb(0.3, 0.3, 0.3);
|
||||
const completedAt = new Date(docDetails.updatedAt);
|
||||
const completedUTCtime = completedAt.toUTCString();
|
||||
const signersCount = docDetails?.Signers?.length || 1;
|
||||
const createdAt = new Date();
|
||||
const createdUTCTime = createdAt.toUTCString();
|
||||
const createDate = 'Generated On ' + createdUTCTime;
|
||||
const company = docDetails?.ExtUserPtr?.Company || '';
|
||||
const auditTrail =
|
||||
docDetails.AuditTrail?.length > 1
|
||||
? docDetails.AuditTrail.map(x => {
|
||||
const data = docDetails.Signers.find(y => y.objectId === x.UserPtr.objectId);
|
||||
return { ...data, ipAddress: x.ipAddress };
|
||||
})
|
||||
: [{ ...docDetails.ExtUserPtr, ipAddress: docDetails?.AuditTrail[0].ipAddress }];
|
||||
|
||||
// Draw a border
|
||||
page.drawRectangle({
|
||||
x: startX,
|
||||
y: startY,
|
||||
width: width - 2 * startX,
|
||||
height: height - 2 * startY,
|
||||
borderColor: borderColor,
|
||||
borderWidth: 1,
|
||||
});
|
||||
page.drawImage(pngImage, {
|
||||
x: 30,
|
||||
y: 790,
|
||||
width: 100,
|
||||
height: 25,
|
||||
});
|
||||
|
||||
page.drawText(createDate, {
|
||||
x: 320,
|
||||
y: 810,
|
||||
size: 12,
|
||||
font: timesRomanFont,
|
||||
color: rgb(0.12, 0.12, 0.12),
|
||||
});
|
||||
|
||||
page.drawText('Certificate of Completion', {
|
||||
x: 160,
|
||||
y: 750,
|
||||
size: title,
|
||||
font: timesRomanFont,
|
||||
color: titleColor,
|
||||
});
|
||||
|
||||
const underlineY = 740;
|
||||
page.drawLine({
|
||||
start: { x: 30, y: underlineY },
|
||||
end: { x: width - 30, y: underlineY },
|
||||
color: titleUnderline,
|
||||
thickness: 1,
|
||||
});
|
||||
|
||||
page.drawText('Summary', {
|
||||
x: 30,
|
||||
y: 710,
|
||||
size: subtitle,
|
||||
font: timesRomanFont,
|
||||
color: titleColor,
|
||||
});
|
||||
|
||||
page.drawText('Document Id :', {
|
||||
x: 30,
|
||||
y: 685,
|
||||
size: text,
|
||||
font: timesRomanFont,
|
||||
color: textKeyColor,
|
||||
});
|
||||
|
||||
page.drawText(docDetails.objectId, {
|
||||
x: 115,
|
||||
y: 685,
|
||||
size: text,
|
||||
font: timesRomanFont,
|
||||
color: textValueColor,
|
||||
});
|
||||
|
||||
page.drawText('Document Name :', {
|
||||
x: 30,
|
||||
y: 665,
|
||||
size: text,
|
||||
font: timesRomanFont,
|
||||
color: textKeyColor,
|
||||
});
|
||||
|
||||
page.drawText(docDetails.Name, {
|
||||
x: 140,
|
||||
y: 665,
|
||||
size: text,
|
||||
font: timesRomanFont,
|
||||
color: textValueColor,
|
||||
});
|
||||
|
||||
page.drawText('Organization :', {
|
||||
x: 30,
|
||||
y: 645,
|
||||
size: text,
|
||||
font: timesRomanFont,
|
||||
color: textKeyColor,
|
||||
});
|
||||
|
||||
page.drawText(company, {
|
||||
x: 115,
|
||||
y: 645,
|
||||
size: text,
|
||||
font: timesRomanFont,
|
||||
color: textValueColor,
|
||||
});
|
||||
|
||||
page.drawText('Completed on :', {
|
||||
x: 30,
|
||||
y: 625,
|
||||
size: text,
|
||||
font: timesRomanFont,
|
||||
color: textKeyColor,
|
||||
});
|
||||
|
||||
page.drawText(`${completedUTCtime}`, {
|
||||
x: 120,
|
||||
y: 625,
|
||||
size: text,
|
||||
font: timesRomanFont,
|
||||
color: textValueColor,
|
||||
});
|
||||
|
||||
page.drawText('Signers :', {
|
||||
x: 30,
|
||||
y: 605,
|
||||
size: text,
|
||||
font: timesRomanFont,
|
||||
color: textKeyColor,
|
||||
});
|
||||
|
||||
page.drawText(`${signersCount}`, {
|
||||
x: 80,
|
||||
y: 605,
|
||||
size: text,
|
||||
font: timesRomanFont,
|
||||
color: textValueColor,
|
||||
});
|
||||
|
||||
page.drawLine({
|
||||
start: { x: 30, y: 565 },
|
||||
end: { x: width - 30, y: 565 },
|
||||
color: rgb(0.12, 0.12, 0.12),
|
||||
thickness: 0.5,
|
||||
});
|
||||
page.drawText('Recipients', {
|
||||
x: 30,
|
||||
y: 575,
|
||||
size: subtitle,
|
||||
font: timesRomanFont,
|
||||
color: titleColor,
|
||||
});
|
||||
let yPosition1 = 550;
|
||||
let yPosition2 = 530;
|
||||
let yPosition3 = 510;
|
||||
let yPosition4 = 500;
|
||||
auditTrail.forEach(x => {
|
||||
page.drawText('Name :', {
|
||||
x: 30,
|
||||
y: yPosition1,
|
||||
size: text,
|
||||
font: timesRomanFont,
|
||||
color: textKeyColor,
|
||||
});
|
||||
|
||||
page.drawText(x?.Name, {
|
||||
x: 75,
|
||||
y: yPosition1,
|
||||
size: text,
|
||||
font: timesRomanFont,
|
||||
color: textValueColor,
|
||||
});
|
||||
|
||||
page.drawText('Email :', {
|
||||
x: 30,
|
||||
y: yPosition2,
|
||||
size: text,
|
||||
font: timesRomanFont,
|
||||
color: textKeyColor,
|
||||
});
|
||||
|
||||
page.drawText(x?.Email, {
|
||||
x: 75,
|
||||
y: yPosition2,
|
||||
size: text,
|
||||
font: timesRomanFont,
|
||||
color: textValueColor,
|
||||
});
|
||||
|
||||
page.drawText('Accessed from :', {
|
||||
x: 30,
|
||||
y: yPosition3,
|
||||
size: text,
|
||||
font: timesRomanFont,
|
||||
color: textKeyColor,
|
||||
});
|
||||
|
||||
page.drawText(x?.ipAddress, {
|
||||
x: 125,
|
||||
y: yPosition3,
|
||||
size: text,
|
||||
font: timesRomanFont,
|
||||
color: textValueColor,
|
||||
});
|
||||
|
||||
page.drawLine({
|
||||
start: { x: 30, y: yPosition4 },
|
||||
end: { x: width - 30, y: yPosition4 },
|
||||
color: rgb(0.12, 0.12, 0.12),
|
||||
thickness: 0.5,
|
||||
});
|
||||
|
||||
yPosition1 = yPosition4 - 20;
|
||||
yPosition2 = yPosition1 - 20;
|
||||
yPosition3 = yPosition2 - 20;
|
||||
yPosition4 = yPosition4 - 70;
|
||||
});
|
||||
|
||||
const pdfBytes = await pdfDoc.save();
|
||||
return pdfBytes;
|
||||
}
|
||||
+110
-74
@@ -4,6 +4,7 @@ import axios from 'axios';
|
||||
import { pdflibAddPlaceholder } from './customSignPdf/pdflibplaceholder.min.js';
|
||||
import { PDFDocument } from 'pdf-lib';
|
||||
import { saveFileUsage } from '../../../Utils.js';
|
||||
import GenerateCertificate from './GenerateCertificate.js';
|
||||
const serverUrl = process.env.SERVER_URL,
|
||||
APPID = process.env.APP_ID,
|
||||
masterKEY = process.env.MASTER_KEY;
|
||||
@@ -17,20 +18,20 @@ async function uploadFile(e, a) {
|
||||
console.log('Err ', e), fs.unlinkSync(a);
|
||||
}
|
||||
}
|
||||
async function updateDoc(t, s, r, o, i, n) {
|
||||
async function updateDoc(t, s, r, i, o, n) {
|
||||
try {
|
||||
var d = {
|
||||
UserPtr: { __type: 'Pointer', className: n, objectId: r },
|
||||
SignedUrl: s,
|
||||
Activity: 'Signed',
|
||||
ipAddress: o,
|
||||
ipAddress: i,
|
||||
};
|
||||
let e;
|
||||
var l = (e = i.AuditTrail && 0 < i.AuditTrail.length ? [...i.AuditTrail, d] : [d]).filter(
|
||||
var l = (e = o.AuditTrail && 0 < o.AuditTrail.length ? [...o.AuditTrail, d] : [d]).filter(
|
||||
e => 'Signed' === e.Activity
|
||||
);
|
||||
let a = !1;
|
||||
!((i.Signers && 0 < i.Signers.length && l.length !== i.Signers.length) || !(a = !0));
|
||||
!((o.Signers && 0 < o.Signers.length && l.length !== o.Signers.length) || !(a = !0));
|
||||
var c = { SignedUrl: s, AuditTrail: e, IsCompleted: a };
|
||||
await axios.put(serverUrl + '/classes/contracts_Document/' + t, c, {
|
||||
headers: {
|
||||
@@ -39,7 +40,7 @@ async function updateDoc(t, s, r, o, i, n) {
|
||||
'X-Parse-Master-Key': masterKEY,
|
||||
},
|
||||
});
|
||||
return { isCompleted: a, message: 'success' };
|
||||
return { isCompleted: a, message: 'success', AuditTrail: e };
|
||||
} catch (e) {
|
||||
return console.log('update doc err ', e), 'err';
|
||||
}
|
||||
@@ -129,12 +130,12 @@ async function sendDoctoWebhook(t, e, a, s) {
|
||||
}
|
||||
}));
|
||||
}
|
||||
async function PDF(i) {
|
||||
async function PDF(o) {
|
||||
try {
|
||||
var e = i.params.docId,
|
||||
a = i.params.userId,
|
||||
n = await axios.get(
|
||||
serverUrl + '/classes/contracts_Document/' + e + '?include=ExtUserPtr,Signers',
|
||||
var n = o.params.docId,
|
||||
e = o.params.userId,
|
||||
d = await axios.get(
|
||||
serverUrl + '/classes/contracts_Document/' + n + '?include=ExtUserPtr,Signers',
|
||||
{
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@@ -143,66 +144,66 @@ async function PDF(i) {
|
||||
},
|
||||
}
|
||||
),
|
||||
d = await axios.get(serverUrl + '/users/me', {
|
||||
l = await axios.get(serverUrl + '/users/me', {
|
||||
headers: {
|
||||
'X-Parse-Application-Id': APPID,
|
||||
'X-Parse-Session-Token': i.headers.sessiontoken,
|
||||
'X-Parse-Session-Token': o.headers.sessiontoken,
|
||||
},
|
||||
});
|
||||
if (!d.data || !d.data.objectId) return { status: 'error', message: 'This user not allowed!' };
|
||||
if (!l.data || !l.data.objectId) return { status: 'error', message: 'This user not allowed!' };
|
||||
{
|
||||
var t,
|
||||
var a,
|
||||
t,
|
||||
s,
|
||||
l,
|
||||
c = JSON.stringify({ objectId: a });
|
||||
let r, o;
|
||||
o = a
|
||||
? (t = await axios.get(serverUrl + '/classes/contracts_Contactbook?where=' + c, {
|
||||
c = JSON.stringify({ objectId: e });
|
||||
let r, i;
|
||||
i = e
|
||||
? (a = await axios.get(serverUrl + '/classes/contracts_Contactbook?where=' + c, {
|
||||
headers: {
|
||||
'X-Parse-Application-Id': APPID,
|
||||
'X-Parse-Session-Token': i.headers.sessiontoken,
|
||||
'X-Parse-Session-Token': o.headers.sessiontoken,
|
||||
},
|
||||
})).data && 0 < t.data.results.length
|
||||
? ((r = t), 'contracts_Contactbook')
|
||||
})).data && 0 < a.data.results.length
|
||||
? ((r = a), 'contracts_Contactbook')
|
||||
: ((r = await axios.get(serverUrl + '/classes/contracts_Users?where=' + c, {
|
||||
headers: { 'X-Parse-Application-Id': APPID, 'X-Parse-Master-Key': masterKEY },
|
||||
})),
|
||||
'contracts_Users')
|
||||
: ((s = JSON.stringify({
|
||||
UserId: { __type: 'Pointer', className: '_User', objectId: d.data.objectId },
|
||||
: ((t = JSON.stringify({
|
||||
UserId: { __type: 'Pointer', className: '_User', objectId: l.data.objectId },
|
||||
})),
|
||||
(l = await axios.get(serverUrl + '/classes/contracts_Users?where=' + s, {
|
||||
(s = await axios.get(serverUrl + '/classes/contracts_Users?where=' + t, {
|
||||
headers: { 'X-Parse-Application-Id': APPID, 'X-Parse-Master-Key': masterKEY },
|
||||
})).data && 0 < l.data.results.length
|
||||
? ((r = l), 'contracts_Users')
|
||||
: ((r = await axios.get(serverUrl + '/classes/contracts_Contactbook?where=' + s, {
|
||||
})).data && 0 < s.data.results.length
|
||||
? ((r = s), 'contracts_Users')
|
||||
: ((r = await axios.get(serverUrl + '/classes/contracts_Contactbook?where=' + t, {
|
||||
headers: {
|
||||
'X-Parse-Application-Id': APPID,
|
||||
'X-Parse-Session-Token': i.headers.sessiontoken,
|
||||
'X-Parse-Session-Token': o.headers.sessiontoken,
|
||||
},
|
||||
})),
|
||||
'contracts_Contactbook'));
|
||||
var p = r.data.results[0].Name,
|
||||
m = r.data.results[0].Email;
|
||||
if (!i.params.pdfFile) return { status: 'error', message: 'pdf file not present!' };
|
||||
if (!o.params.pdfFile) return { status: 'error', message: 'Pdf file not present!' };
|
||||
{
|
||||
let e = Buffer.from(i.params.pdfFile, 'base64');
|
||||
let e = Buffer.from(o.params.pdfFile, 'base64');
|
||||
var g = process.env.PFX_BASE64,
|
||||
u = Buffer.from(g, 'base64'),
|
||||
h = {
|
||||
UserPtr: { __type: 'Pointer', className: o, objectId: r.data.results[0].objectId },
|
||||
f = {
|
||||
UserPtr: { __type: 'Pointer', className: i, objectId: r.data.results[0].objectId },
|
||||
SignedUrl: '',
|
||||
Activity: 'Signed',
|
||||
ipAddress: i.headers['x-real-ip'],
|
||||
ipAddress: o.headers['x-real-ip'],
|
||||
};
|
||||
let a;
|
||||
var f = (a =
|
||||
n.data.AuditTrail && 0 < n.data.AuditTrail.length
|
||||
? [...n.data.AuditTrail, h]
|
||||
: [h]).filter(e => 'Signed' === e.Activity);
|
||||
var h = (a =
|
||||
d.data.AuditTrail && 0 < d.data.AuditTrail.length
|
||||
? [...d.data.AuditTrail, f]
|
||||
: [f]).filter(e => 'Signed' === e.Activity);
|
||||
let t = !1;
|
||||
!(
|
||||
(n.data.Signers && 0 < n.data.Signers.length && f.length !== n.data.Signers.length) ||
|
||||
(d.data.Signers && 0 < d.data.Signers.length && h.length !== d.data.Signers.length) ||
|
||||
!(t = !0)
|
||||
);
|
||||
var P,
|
||||
@@ -211,19 +212,19 @@ async function PDF(i) {
|
||||
U,
|
||||
b,
|
||||
I,
|
||||
S = `exported_file_${Math.floor(5e3 * Math.random())}.pdf`,
|
||||
x = './exports/' + S;
|
||||
w = `exported_file_${Math.floor(5e3 * Math.random())}.pdf`,
|
||||
A = './exports/' + w;
|
||||
let s = e.length;
|
||||
s = (
|
||||
t
|
||||
? ((P = n.data.Signers?.map(e => e.Name + ' <' + e.Email + '>')),
|
||||
? ((P = d.data.Signers?.map(e => e.Name + ' <' + e.Email + '>')),
|
||||
(e =
|
||||
P && 0 < P.length
|
||||
? ((y = await PDFDocument.load(e)),
|
||||
pdflibAddPlaceholder({
|
||||
pdfDoc: y,
|
||||
reason: 'Digitally signed by OpenSign for ' + P?.join(', '),
|
||||
location: 'location',
|
||||
location: 'n/a',
|
||||
signatureLength: 15e3,
|
||||
}),
|
||||
(v = await y.save()),
|
||||
@@ -232,49 +233,84 @@ async function PDF(i) {
|
||||
pdflibAddPlaceholder({
|
||||
pdfDoc: U,
|
||||
reason: 'Digitally signed by OpenSign for ' + p + ' <' + m + '>',
|
||||
location: 'location',
|
||||
location: 'n/a',
|
||||
signatureLength: 15e3,
|
||||
}),
|
||||
(b = await U.save()),
|
||||
Buffer.from(b))),
|
||||
(I = await new SignPDF(e, u).signPDF()),
|
||||
fs.writeFileSync(x, I),
|
||||
fs.writeFileSync(A, I),
|
||||
I)
|
||||
: (fs.writeFileSync(x, e), e)
|
||||
: (fs.writeFileSync(A, e), e)
|
||||
).length;
|
||||
var A,
|
||||
w,
|
||||
D = await uploadFile(S, x);
|
||||
if (D && D.imageUrl)
|
||||
var D,
|
||||
S,
|
||||
x,
|
||||
E,
|
||||
_,
|
||||
j,
|
||||
k,
|
||||
F,
|
||||
T,
|
||||
N,
|
||||
C = await uploadFile(w, A);
|
||||
if (C && C.imageUrl)
|
||||
return (
|
||||
(A = await updateDoc(
|
||||
i.params.docId,
|
||||
D.imageUrl,
|
||||
(D = await updateDoc(
|
||||
o.params.docId,
|
||||
C.imageUrl,
|
||||
r.data.results[0].objectId,
|
||||
i.headers['x-real-ip'],
|
||||
n.data,
|
||||
o
|
||||
o.headers['x-real-ip'],
|
||||
d.data,
|
||||
i
|
||||
)),
|
||||
sendDoctoWebhook(n, D.imageUrl, 'signed', r?.data.results?.[0]),
|
||||
saveFileUsage(s, D.imageUrl, d.data.objectId),
|
||||
A &&
|
||||
A.isCompleted &&
|
||||
((w = {
|
||||
url: D.imageUrl,
|
||||
sender: { Mail: n.data.ExtUserPtr.Email, Name: 'OpenSign™' },
|
||||
pdfName: n.data.Name,
|
||||
receiver: n.data.ExtUserPtr.Email,
|
||||
extUserId: n.data.ExtUserPtr.objectId,
|
||||
sendDoctoWebhook(d, C.imageUrl, 'signed', r?.data.results?.[0]),
|
||||
saveFileUsage(s, C.imageUrl, l.data.objectId),
|
||||
D &&
|
||||
D.isCompleted &&
|
||||
((S = {
|
||||
url: C.imageUrl,
|
||||
sender: { Mail: d.data.ExtUserPtr.Email, Name: 'OpenSign™' },
|
||||
pdfName: d.data.Name,
|
||||
receiver: d.data.ExtUserPtr.Email,
|
||||
extUserId: d.data.ExtUserPtr.objectId,
|
||||
}),
|
||||
n.data.IsSendMail && !1 === n.data.IsSendMail
|
||||
(x = { ...d.data, AuditTrail: D.AuditTrail }),
|
||||
(E = await GenerateCertificate(x)),
|
||||
(_ = await PDFDocument.load(E)),
|
||||
pdflibAddPlaceholder({
|
||||
pdfDoc: _,
|
||||
reason: 'Digitally signed by OpenSign.',
|
||||
location: 'n/a',
|
||||
signatureLength: 15e3,
|
||||
}),
|
||||
(j = await _.save()),
|
||||
(k = Buffer.from(j)),
|
||||
(F = await new SignPDF(k, u).signPDF()),
|
||||
fs.writeFileSync('./exports/certificate.pdf', F),
|
||||
(N = {
|
||||
CertificateUrl: (T = await uploadFile(
|
||||
'certificate.pdf',
|
||||
'./exports/certificate.pdf'
|
||||
)).imageUrl,
|
||||
}),
|
||||
await axios.put(serverUrl + '/classes/contracts_Document/' + n, N, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-Parse-Application-Id': APPID,
|
||||
'X-Parse-Master-Key': masterKEY,
|
||||
},
|
||||
}),
|
||||
d.data.IsSendMail && !1 === d.data.IsSendMail
|
||||
? console.log("don't send mail")
|
||||
: sendCompletedMail(w),
|
||||
sendDoctoWebhook(n, D.imageUrl, 'completed')),
|
||||
fs.unlinkSync(x),
|
||||
console.log('New Signed PDF created called: ' + x),
|
||||
'success' === A.message
|
||||
? { status: 'success', data: D.imageUrl }
|
||||
: { status: 'error', message: 'please provide required parameters!' }
|
||||
: sendCompletedMail(S),
|
||||
saveFileUsage(k.length, T.imageUrl, l.data.objectId),
|
||||
sendDoctoWebhook(d, C.imageUrl, 'completed')),
|
||||
fs.unlinkSync(A),
|
||||
console.log('New Signed PDF created called: ' + A),
|
||||
'success' === D.message
|
||||
? { status: 'success', data: C.imageUrl }
|
||||
: { status: 'error', message: 'Please provide required parameters!' }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,8 +58,20 @@ async function sendmailv3(req) {
|
||||
data: process.env.SMTP_ENABLE ? undefined : PdfBuffer,
|
||||
};
|
||||
|
||||
// const html = "<html><head><meta http-equiv='Content-Type' content='text/html; charset=UTF-8' /></head><body style='text-align: center;'> <p style='font-weight: bolder; font-size: large;'>Hello!</p> <p>This is a html checking mail</p><p><button style='background-color: lightskyblue; cursor: pointer; border-radius: 5px; padding: 10px; border-style: solid; border-width: 2px; text-decoration: none; font-weight: bolder; color:blue'>Verify email</button></p></body></html>"
|
||||
|
||||
let attachment;
|
||||
// `certificateBuffer` used to create buffer from pdf file
|
||||
try {
|
||||
const certificateBuffer = fs.readFileSync('./exports/certificate.pdf');
|
||||
const certificate = {
|
||||
filename: 'certificate.pdf',
|
||||
content: process.env.SMTP_ENABLE ? certificateBuffer : undefined, //fs.readFileSync('./exports/exported_file_1223.pdf'),
|
||||
data: process.env.SMTP_ENABLE ? undefined : certificateBuffer,
|
||||
};
|
||||
attachment = [file, certificate];
|
||||
} catch (err) {
|
||||
attachment = [file];
|
||||
console.log('Err in read certificate sendmailv3', err);
|
||||
}
|
||||
const from = req.params.from || '';
|
||||
const mailsender = process.env.SMTP_ENABLE
|
||||
? process.env.SMTP_USER_EMAIL
|
||||
@@ -71,8 +83,8 @@ async function sendmailv3(req) {
|
||||
subject: req.params.subject,
|
||||
text: req.params.text || 'mail',
|
||||
html: req.params.html || '',
|
||||
attachments: process.env.SMTP_ENABLE ? [file] : undefined,
|
||||
attachment: process.env.SMTP_ENABLE ? undefined : file,
|
||||
attachments: process.env.SMTP_ENABLE ? attachment : undefined,
|
||||
attachment: process.env.SMTP_ENABLE ? undefined : attachment,
|
||||
};
|
||||
if (transporterSMTP) {
|
||||
const res = await transporterSMTP.sendMail(messageParams);
|
||||
@@ -81,6 +93,11 @@ async function sendmailv3(req) {
|
||||
if (req.params?.extUserId) {
|
||||
await updateMailCount(req.params.extUserId);
|
||||
}
|
||||
try {
|
||||
fs.unlinkSync('./exports/certificate.pdf');
|
||||
} catch (err) {
|
||||
console.log('Err in unlink certificate sendmailv3');
|
||||
}
|
||||
return {
|
||||
status: 'success',
|
||||
};
|
||||
@@ -92,6 +109,11 @@ async function sendmailv3(req) {
|
||||
if (req.params?.extUserId) {
|
||||
await updateMailCount(req.params.extUserId);
|
||||
}
|
||||
try {
|
||||
fs.unlinkSync('./exports/certificate.pdf');
|
||||
} catch (err) {
|
||||
console.log('Err in unlink certificate sendmailv3');
|
||||
}
|
||||
return {
|
||||
status: 'success',
|
||||
};
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 86 KiB |
Reference in New Issue
Block a user