mirror of
https://github.com/OpenSignLabs/OpenSign.git
synced 2026-08-17 21:25:54 +02:00
fix: error in auto-sign feature unexpected issue encountered - something went wrong
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
import React, { useState } from "react";
|
||||
import { saveAs } from "file-saver";
|
||||
import axios from "axios";
|
||||
import { getBase64FromUrl } from "../../constant/Utils";
|
||||
import { handleDownloadPdf, handleToPrint } from "../../constant/Utils";
|
||||
import { themeColor, emailRegex } from "../../constant/const";
|
||||
import printModule from "print-js";
|
||||
import Loader from "../../primitives/Loader";
|
||||
import ModalUi from "../../primitives/ModalUi";
|
||||
|
||||
@@ -12,7 +10,7 @@ function EmailComponent({
|
||||
pdfUrl,
|
||||
setIsEmail,
|
||||
setSuccessEmail,
|
||||
pdfName,
|
||||
pdfDetails,
|
||||
sender,
|
||||
setIsAlert,
|
||||
extUserId,
|
||||
@@ -22,8 +20,11 @@ function EmailComponent({
|
||||
const [emailValue, setEmailValue] = useState("");
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [emailErr, setEmailErr] = useState(false);
|
||||
const [isDownloading, setIsDownloading] = useState("");
|
||||
const isAndroid = /Android/i.test(navigator.userAgent);
|
||||
//function for send email
|
||||
const sendEmail = async () => {
|
||||
const pdfName = pdfDetails[0]?.Name;
|
||||
setIsLoading(true);
|
||||
|
||||
let sendMail;
|
||||
@@ -138,43 +139,6 @@ function EmailComponent({
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// function for print signed pdf
|
||||
const handleToPrint = async (event) => {
|
||||
event.preventDefault();
|
||||
|
||||
const pdf = await getBase64FromUrl(pdfUrl);
|
||||
const isAndroidDevice = navigator.userAgent.match(/Android/i);
|
||||
const isAppleDevice =
|
||||
(/iPad|iPhone|iPod/.test(navigator.platform) ||
|
||||
(navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1)) &&
|
||||
!window.MSStream;
|
||||
if (isAndroidDevice || isAppleDevice) {
|
||||
const byteArray = Uint8Array.from(
|
||||
atob(pdf)
|
||||
.split("")
|
||||
.map((char) => char.charCodeAt(0))
|
||||
);
|
||||
const blob = new Blob([byteArray], { type: "application/pdf" });
|
||||
const blobUrl = URL.createObjectURL(blob);
|
||||
window.open(blobUrl, "_blank");
|
||||
} else {
|
||||
printModule({ printable: pdf, type: "pdf", base64: true });
|
||||
}
|
||||
};
|
||||
|
||||
//handle download signed pdf
|
||||
const handleDownloadPdf = () => {
|
||||
saveAs(pdfUrl, `${sanitizeFileName(pdfName)}_signed_by_OpenSign™.pdf`);
|
||||
};
|
||||
|
||||
const sanitizeFileName = (pdfName) => {
|
||||
// Replace spaces with underscore
|
||||
return pdfName.replace(/ /g, "_");
|
||||
};
|
||||
|
||||
const isAndroid = /Android/i.test(navigator.userAgent);
|
||||
|
||||
return (
|
||||
<div>
|
||||
{/* isEmail */}
|
||||
@@ -188,6 +152,11 @@ function EmailComponent({
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
{isDownloading === "pdf" && (
|
||||
<div className="fixed z-[200] inset-0 flex justify-center items-center bg-black bg-opacity-30">
|
||||
<Loader />
|
||||
</div>
|
||||
)}
|
||||
<div className="flex justify-between items-center py-[10px] px-[20px] border-b-[1px] border-base-content">
|
||||
<span className="text-base-content font-semibold">
|
||||
Successfully signed!
|
||||
@@ -195,7 +164,7 @@ function EmailComponent({
|
||||
<div className="flex flex-row">
|
||||
{!isAndroid && (
|
||||
<button
|
||||
onClick={handleToPrint}
|
||||
onClick={(e) => handleToPrint(e, pdfUrl, setIsDownloading)}
|
||||
className="op-btn op-btn-neutral op-btn-sm text-[15px]"
|
||||
>
|
||||
<i className="fa-light fa-print" aria-hidden="true"></i>
|
||||
@@ -204,7 +173,9 @@ function EmailComponent({
|
||||
)}
|
||||
<button
|
||||
className="op-btn op-btn-primary op-btn-sm text-[15px] ml-2"
|
||||
onClick={() => handleDownloadPdf()}
|
||||
onClick={() =>
|
||||
handleDownloadPdf(pdfDetails, pdfUrl, setIsDownloading)
|
||||
}
|
||||
>
|
||||
<i className="fa-light fa-download" aria-hidden="true"></i>
|
||||
Download
|
||||
|
||||
@@ -440,7 +440,7 @@ export const resizeBorderExtraWidth = () => {
|
||||
return 20;
|
||||
};
|
||||
|
||||
export async function getBase64FromUrl(url) {
|
||||
export async function getBase64FromUrl(url, autosign) {
|
||||
const data = await fetch(url);
|
||||
const blob = await data.blob();
|
||||
return new Promise((resolve) => {
|
||||
@@ -448,8 +448,12 @@ export async function getBase64FromUrl(url) {
|
||||
reader.readAsDataURL(blob);
|
||||
reader.onloadend = function () {
|
||||
const pdfBase = this.result;
|
||||
const suffixbase64 = pdfBase.split(",").pop();
|
||||
resolve(suffixbase64);
|
||||
if (autosign) {
|
||||
resolve(pdfBase);
|
||||
} else {
|
||||
const suffixbase64 = pdfBase.split(",").pop();
|
||||
resolve(suffixbase64);
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
@@ -2225,3 +2229,42 @@ export const getContainerScale = (pdfOriginalWH, pageNumber, containerWH) => {
|
||||
const containerScale = containerWH?.width / getPdfPageWidth?.width || 1;
|
||||
return containerScale;
|
||||
};
|
||||
//function to get default signatur eof current user from `contracts_Signature` class
|
||||
export const getDefaultSignature = async (objectId) => {
|
||||
try {
|
||||
const result = await axios.get(
|
||||
`${localStorage.getItem(
|
||||
"baseUrl"
|
||||
)}classes/contracts_Signature?where={"UserId": {"__type": "Pointer","className": "_User", "objectId":"${objectId}"}}`,
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"X-Parse-Application-Id": localStorage.getItem("parseAppId"),
|
||||
"X-Parse-Session-Token": localStorage.getItem("accesstoken")
|
||||
}
|
||||
}
|
||||
);
|
||||
const res = result.data?.results;
|
||||
if (res[0] && res.length > 0) {
|
||||
const defaultSignature = res[0]?.ImageURL
|
||||
? await getBase64FromUrl(res[0]?.ImageURL, true)
|
||||
: "";
|
||||
const defaultInitial = res[0]?.Initials
|
||||
? await getBase64FromUrl(res[0]?.Initials, true)
|
||||
: "";
|
||||
|
||||
return {
|
||||
status: "success",
|
||||
res: {
|
||||
defaultSignature: defaultSignature,
|
||||
defaultInitial: defaultInitial
|
||||
}
|
||||
};
|
||||
}
|
||||
} catch (err) {
|
||||
console.log("Error: error in fetch data in contracts_Signature", err);
|
||||
return {
|
||||
status: "error"
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -30,7 +30,8 @@ import {
|
||||
contactBook,
|
||||
handleDownloadPdf,
|
||||
handleToPrint,
|
||||
handleDownloadCertificate
|
||||
handleDownloadCertificate,
|
||||
getDefaultSignature
|
||||
} from "../constant/Utils";
|
||||
import LoaderWithMsg from "../primitives/LoaderWithMsg";
|
||||
import HandleError from "../primitives/HandleError";
|
||||
@@ -337,244 +338,233 @@ function PdfRequestFiles(props) {
|
||||
};
|
||||
//function for get document details for perticular signer with signer'object id
|
||||
const getDocumentDetails = async (docId, isNextUser) => {
|
||||
const senderUser = localStorage.getItem(
|
||||
`Parse/${localStorage.getItem("parseAppId")}/currentUser`
|
||||
);
|
||||
const jsonSender = JSON.parse(senderUser);
|
||||
let currUserId;
|
||||
//getting document details
|
||||
const documentData = await contractDocument(documentId || docId);
|
||||
if (documentData && documentData.length > 0) {
|
||||
setExtUserId(documentData[0]?.ExtUserPtr?.objectId);
|
||||
const isCompleted =
|
||||
documentData[0].IsCompleted && documentData[0].IsCompleted;
|
||||
const expireDate = documentData[0].ExpiryDate.iso;
|
||||
const declined = documentData[0].IsDeclined && documentData[0].IsDeclined;
|
||||
const expireUpdateDate = new Date(expireDate).getTime();
|
||||
const currDate = new Date().getTime();
|
||||
const getSigners = documentData[0].Signers;
|
||||
const getCurrentSigner =
|
||||
getSigners &&
|
||||
getSigners.filter(
|
||||
(data) => data.UserId.objectId === jsonSender?.objectId
|
||||
);
|
||||
try {
|
||||
const senderUser = localStorage.getItem(
|
||||
`Parse/${localStorage.getItem("parseAppId")}/currentUser`
|
||||
);
|
||||
const jsonSender = JSON.parse(senderUser);
|
||||
let currUserId;
|
||||
//getting document details
|
||||
const documentData = await contractDocument(documentId || docId);
|
||||
if (documentData && documentData.length > 0) {
|
||||
setExtUserId(documentData[0]?.ExtUserPtr?.objectId);
|
||||
const isCompleted =
|
||||
documentData[0].IsCompleted && documentData[0].IsCompleted;
|
||||
const expireDate = documentData[0].ExpiryDate.iso;
|
||||
const declined =
|
||||
documentData[0].IsDeclined && documentData[0].IsDeclined;
|
||||
const expireUpdateDate = new Date(expireDate).getTime();
|
||||
const currDate = new Date().getTime();
|
||||
const getSigners = documentData[0].Signers;
|
||||
const getCurrentSigner =
|
||||
getSigners &&
|
||||
getSigners.filter(
|
||||
(data) => data.UserId.objectId === jsonSender?.objectId
|
||||
);
|
||||
|
||||
currUserId = getCurrentSigner[0] ? getCurrentSigner[0].objectId : "";
|
||||
if (isEnableSubscription) {
|
||||
await checkIsSubscribed(
|
||||
documentData[0]?.ExtUserPtr?.objectId,
|
||||
currUserId
|
||||
);
|
||||
}
|
||||
if (currUserId) {
|
||||
setSignerObjectId(currUserId);
|
||||
}
|
||||
if (documentData[0].SignedUrl) {
|
||||
setPdfUrl(documentData[0].SignedUrl);
|
||||
} else {
|
||||
setPdfUrl(documentData[0].URL);
|
||||
}
|
||||
if (isCompleted) {
|
||||
setIsSigned(true);
|
||||
const data = {
|
||||
isCertificate: true,
|
||||
isModal: true
|
||||
};
|
||||
setAlreadySign(true);
|
||||
setIsCompleted(data);
|
||||
setIsCelebration(true);
|
||||
setTimeout(() => {
|
||||
setIsCelebration(false);
|
||||
}, 5000);
|
||||
} else if (declined) {
|
||||
const currentDecline = {
|
||||
currnt: "another",
|
||||
isDeclined: true
|
||||
};
|
||||
setIsDecline(currentDecline);
|
||||
} else if (currDate > expireUpdateDate) {
|
||||
const expireDateFormat = moment(new Date(expireDate)).format(
|
||||
"MMM DD, YYYY"
|
||||
);
|
||||
setIsExpired(true);
|
||||
setExpiredDate(expireDateFormat);
|
||||
} // Check if the current signer is not a last signer and handle the complete message.
|
||||
else if (isNextUser) {
|
||||
setIsCelebration(true);
|
||||
setTimeout(() => {
|
||||
setIsCelebration(false);
|
||||
}, 5000);
|
||||
setIsCompleted({
|
||||
isModal: true,
|
||||
message:
|
||||
"You have successfully signed the document. You can download or print a copy of the partially signed document. A copy of the digitally signed document will be sent to the owner over email once it is signed by all signers."
|
||||
});
|
||||
} else {
|
||||
currUserId = getCurrentSigner[0] ? getCurrentSigner[0].objectId : "";
|
||||
if (isEnableSubscription) {
|
||||
await checkIsSubscribed(
|
||||
documentData[0]?.ExtUserPtr?.objectId,
|
||||
currUserId
|
||||
);
|
||||
}
|
||||
if (currUserId) {
|
||||
const checkCurrentUser = documentData[0].Placeholders.find(
|
||||
(data) => data?.signerObjId === currUserId
|
||||
);
|
||||
if (checkCurrentUser) {
|
||||
setCurrentSigner(true);
|
||||
}
|
||||
setSignerObjectId(currUserId);
|
||||
}
|
||||
}
|
||||
const audittrailData =
|
||||
documentData[0].AuditTrail &&
|
||||
documentData[0].AuditTrail.length > 0 &&
|
||||
documentData[0].AuditTrail.filter((data) => data.Activity === "Signed");
|
||||
|
||||
const checkAlreadySign =
|
||||
documentData[0].AuditTrail &&
|
||||
documentData[0].AuditTrail.length > 0 &&
|
||||
documentData[0].AuditTrail.filter(
|
||||
(data) =>
|
||||
data.UserPtr.objectId === currUserId && data.Activity === "Signed"
|
||||
);
|
||||
if (
|
||||
checkAlreadySign &&
|
||||
checkAlreadySign[0] &&
|
||||
checkAlreadySign.length > 0
|
||||
) {
|
||||
setAlreadySign(true);
|
||||
} else {
|
||||
const obj = documentData?.[0];
|
||||
setSendInOrder(obj?.SendinOrder || false);
|
||||
if (
|
||||
obj &&
|
||||
obj.Signers &&
|
||||
obj.Signers.length > 0 &&
|
||||
obj.Placeholders &&
|
||||
obj.Placeholders.length > 0
|
||||
) {
|
||||
const params = {
|
||||
event: "viewed",
|
||||
contactId: currUserId,
|
||||
body: {
|
||||
objectId: documentData?.[0].objectId,
|
||||
file: documentData?.[0]?.SignedUrl || documentData?.[0]?.URL,
|
||||
name: documentData?.[0].Name,
|
||||
note: documentData?.[0].Note || "",
|
||||
description: documentData?.[0].Description || "",
|
||||
signers: documentData?.[0].Signers?.map((x) => ({
|
||||
name: x?.Name,
|
||||
email: x?.Email,
|
||||
phone: x?.Phone
|
||||
})),
|
||||
viewedBy: jsonSender.email,
|
||||
viewedAt: new Date(),
|
||||
createdAt: documentData?.[0].createdAt
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
await axios.post(
|
||||
`${localStorage.getItem("baseUrl")}functions/callwebhook`,
|
||||
params,
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"X-Parse-Application-Id": localStorage.getItem("parseAppId"),
|
||||
sessiontoken: localStorage.getItem("accesstoken")
|
||||
}
|
||||
}
|
||||
);
|
||||
} catch (err) {
|
||||
console.log("Err ", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let signers = [];
|
||||
let unSignedSigner = [];
|
||||
|
||||
const placeholdersOrSigners = [];
|
||||
for (const placeholder of documentData[0].Placeholders) {
|
||||
//`emailExist` variable to handle condition for quick send flow and show unsigned signers list
|
||||
const signerIdExist = placeholder?.signerObjId;
|
||||
if (signerIdExist) {
|
||||
const getSignerData = documentData[0].Signers.find(
|
||||
(data) => data.objectId === placeholder?.signerObjId
|
||||
);
|
||||
placeholdersOrSigners.push(getSignerData);
|
||||
if (documentData[0].SignedUrl) {
|
||||
setPdfUrl(documentData[0].SignedUrl);
|
||||
} else {
|
||||
placeholdersOrSigners.push(placeholder);
|
||||
setPdfUrl(documentData[0].URL);
|
||||
}
|
||||
}
|
||||
//condition to check already signed document by someone
|
||||
if (audittrailData && audittrailData.length > 0) {
|
||||
setIsDocId(true);
|
||||
|
||||
for (const item of placeholdersOrSigners) {
|
||||
const checkEmail = item?.email;
|
||||
//if email exist then compare user signed by using email else signers objectId
|
||||
const emailOrId = checkEmail ? item.email : item.objectId;
|
||||
//`isSignedSignature` variable to handle break loop whenever it get true
|
||||
let isSignedSignature = false;
|
||||
//checking the signer who signed the document by using audit trail details.
|
||||
//and save signedSigners and unsignedSigners details
|
||||
for (const doc of audittrailData) {
|
||||
const signedExist = checkEmail
|
||||
? doc?.UserPtr.Email
|
||||
: doc?.UserPtr.objectId;
|
||||
|
||||
if (emailOrId === signedExist) {
|
||||
signers.push({ ...item });
|
||||
isSignedSignature = true;
|
||||
break;
|
||||
if (isCompleted) {
|
||||
setIsSigned(true);
|
||||
const data = {
|
||||
isCertificate: true,
|
||||
isModal: true
|
||||
};
|
||||
setAlreadySign(true);
|
||||
setIsCompleted(data);
|
||||
setIsCelebration(true);
|
||||
setTimeout(() => {
|
||||
setIsCelebration(false);
|
||||
}, 5000);
|
||||
} else if (declined) {
|
||||
const currentDecline = {
|
||||
currnt: "another",
|
||||
isDeclined: true
|
||||
};
|
||||
setIsDecline(currentDecline);
|
||||
} else if (currDate > expireUpdateDate) {
|
||||
const expireDateFormat = moment(new Date(expireDate)).format(
|
||||
"MMM DD, YYYY"
|
||||
);
|
||||
setIsExpired(true);
|
||||
setExpiredDate(expireDateFormat);
|
||||
} // Check if the current signer is not a last signer and handle the complete message.
|
||||
else if (isNextUser) {
|
||||
setIsCelebration(true);
|
||||
setTimeout(() => {
|
||||
setIsCelebration(false);
|
||||
}, 5000);
|
||||
setIsCompleted({
|
||||
isModal: true,
|
||||
message:
|
||||
"You have successfully signed the document. You can download or print a copy of the partially signed document. A copy of the digitally signed document will be sent to the owner over email once it is signed by all signers."
|
||||
});
|
||||
} else {
|
||||
if (currUserId) {
|
||||
const checkCurrentUser = documentData[0].Placeholders.find(
|
||||
(data) => data?.signerObjId === currUserId
|
||||
);
|
||||
if (checkCurrentUser) {
|
||||
setCurrentSigner(true);
|
||||
}
|
||||
}
|
||||
if (!isSignedSignature) {
|
||||
unSignedSigner.push({ ...item });
|
||||
}
|
||||
const audittrailData =
|
||||
documentData[0].AuditTrail &&
|
||||
documentData[0].AuditTrail.length > 0 &&
|
||||
documentData[0].AuditTrail.filter(
|
||||
(data) => data.Activity === "Signed"
|
||||
);
|
||||
|
||||
const checkAlreadySign =
|
||||
documentData[0].AuditTrail &&
|
||||
documentData[0].AuditTrail.length > 0 &&
|
||||
documentData[0].AuditTrail.filter(
|
||||
(data) =>
|
||||
data.UserPtr.objectId === currUserId && data.Activity === "Signed"
|
||||
);
|
||||
if (
|
||||
checkAlreadySign &&
|
||||
checkAlreadySign[0] &&
|
||||
checkAlreadySign.length > 0
|
||||
) {
|
||||
setAlreadySign(true);
|
||||
} else {
|
||||
const obj = documentData?.[0];
|
||||
setSendInOrder(obj?.SendinOrder || false);
|
||||
if (
|
||||
obj &&
|
||||
obj.Signers &&
|
||||
obj.Signers.length > 0 &&
|
||||
obj.Placeholders &&
|
||||
obj.Placeholders.length > 0
|
||||
) {
|
||||
const params = {
|
||||
event: "viewed",
|
||||
contactId: currUserId,
|
||||
body: {
|
||||
objectId: documentData?.[0].objectId,
|
||||
file: documentData?.[0]?.SignedUrl || documentData?.[0]?.URL,
|
||||
name: documentData?.[0].Name,
|
||||
note: documentData?.[0].Note || "",
|
||||
description: documentData?.[0].Description || "",
|
||||
signers: documentData?.[0].Signers?.map((x) => ({
|
||||
name: x?.Name,
|
||||
email: x?.Email,
|
||||
phone: x?.Phone
|
||||
})),
|
||||
viewedBy: jsonSender.email,
|
||||
viewedAt: new Date(),
|
||||
createdAt: documentData?.[0].createdAt
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
await axios.post(
|
||||
`${localStorage.getItem("baseUrl")}functions/callwebhook`,
|
||||
params,
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"X-Parse-Application-Id":
|
||||
localStorage.getItem("parseAppId"),
|
||||
sessiontoken: localStorage.getItem("accesstoken")
|
||||
}
|
||||
}
|
||||
);
|
||||
} catch (err) {
|
||||
console.log("Err ", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
setSignedSigners(signers);
|
||||
setUnSignedSigners(unSignedSigner);
|
||||
setSignerPos(documentData[0].Placeholders);
|
||||
} else {
|
||||
//else condition is show there are no details in audit trail then direct push all signers details
|
||||
//in unsignedsigners array
|
||||
setUnSignedSigners(placeholdersOrSigners);
|
||||
setSignerPos(documentData[0].Placeholders);
|
||||
}
|
||||
setPdfDetails(documentData);
|
||||
//checking if condition current user already sign or owner does not exist as a signer or document has been declined by someone or document has been expired
|
||||
//then stop to display tour message
|
||||
if (
|
||||
(checkAlreadySign &&
|
||||
checkAlreadySign[0] &&
|
||||
checkAlreadySign.length > 0) ||
|
||||
!currUserId ||
|
||||
declined ||
|
||||
currDate > expireUpdateDate
|
||||
) {
|
||||
setRequestSignTour(true);
|
||||
} else {
|
||||
//else condition to check current user exist in contracts_Users class and check tour message status
|
||||
//if not then check user exist in contracts_Contactbook class and check tour message statu
|
||||
const res = await contractUsers();
|
||||
if (res === "Error: Something went wrong!") {
|
||||
setHandleError("Error: Something went wrong!");
|
||||
} else if (res[0] && res?.length) {
|
||||
setContractName("_Users");
|
||||
currUserId = res[0].objectId;
|
||||
setSignerUserId(currUserId);
|
||||
const tourData = res[0].TourStatus && res[0].TourStatus;
|
||||
if (tourData && tourData.length > 0) {
|
||||
const checkTourRequest = tourData.filter(
|
||||
(data) => data?.requestSign
|
||||
|
||||
let signers = [];
|
||||
let unSignedSigner = [];
|
||||
|
||||
const placeholdersOrSigners = [];
|
||||
for (const placeholder of documentData[0].Placeholders) {
|
||||
//`emailExist` variable to handle condition for quick send flow and show unsigned signers list
|
||||
const signerIdExist = placeholder?.signerObjId;
|
||||
if (signerIdExist) {
|
||||
const getSignerData = documentData[0].Signers.find(
|
||||
(data) => data.objectId === placeholder?.signerObjId
|
||||
);
|
||||
setTourStatus(tourData);
|
||||
setRequestSignTour(checkTourRequest[0]?.requestSign || false);
|
||||
placeholdersOrSigners.push(getSignerData);
|
||||
} else {
|
||||
placeholdersOrSigners.push(placeholder);
|
||||
}
|
||||
} else if (res?.length === 0) {
|
||||
const res = await contactBook(currUserId);
|
||||
}
|
||||
//condition to check already signed document by someone
|
||||
if (audittrailData && audittrailData.length > 0) {
|
||||
setIsDocId(true);
|
||||
|
||||
for (const item of placeholdersOrSigners) {
|
||||
const checkEmail = item?.email;
|
||||
//if email exist then compare user signed by using email else signers objectId
|
||||
const emailOrId = checkEmail ? item.email : item.objectId;
|
||||
//`isSignedSignature` variable to handle break loop whenever it get true
|
||||
let isSignedSignature = false;
|
||||
//checking the signer who signed the document by using audit trail details.
|
||||
//and save signedSigners and unsignedSigners details
|
||||
for (const doc of audittrailData) {
|
||||
const signedExist = checkEmail
|
||||
? doc?.UserPtr.Email
|
||||
: doc?.UserPtr.objectId;
|
||||
|
||||
if (emailOrId === signedExist) {
|
||||
signers.push({ ...item });
|
||||
isSignedSignature = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!isSignedSignature) {
|
||||
unSignedSigner.push({ ...item });
|
||||
}
|
||||
}
|
||||
setSignedSigners(signers);
|
||||
setUnSignedSigners(unSignedSigner);
|
||||
setSignerPos(documentData[0].Placeholders);
|
||||
} else {
|
||||
//else condition is show there are no details in audit trail then direct push all signers details
|
||||
//in unsignedsigners array
|
||||
setUnSignedSigners(placeholdersOrSigners);
|
||||
setSignerPos(documentData[0].Placeholders);
|
||||
}
|
||||
setPdfDetails(documentData);
|
||||
//checking if condition current user already sign or owner does not exist as a signer or document has been declined by someone or document has been expired
|
||||
//then stop to display tour message
|
||||
if (
|
||||
(checkAlreadySign &&
|
||||
checkAlreadySign[0] &&
|
||||
checkAlreadySign.length > 0) ||
|
||||
!currUserId ||
|
||||
declined ||
|
||||
currDate > expireUpdateDate
|
||||
) {
|
||||
setRequestSignTour(true);
|
||||
} else {
|
||||
//else condition to check current user exist in contracts_Users class and check tour message status
|
||||
//if not then check user exist in contracts_Contactbook class and check tour message statu
|
||||
const res = await contractUsers();
|
||||
if (res === "Error: Something went wrong!") {
|
||||
setHandleError("Error: Something went wrong!");
|
||||
} else if (res[0] && res.length) {
|
||||
setContractName("_Contactbook");
|
||||
const objectId = res[0].objectId;
|
||||
setSignerUserId(objectId);
|
||||
} else if (res[0] && res?.length) {
|
||||
setContractName("_Users");
|
||||
currUserId = res[0].objectId;
|
||||
setSignerUserId(currUserId);
|
||||
const tourData = res[0].TourStatus && res[0].TourStatus;
|
||||
if (tourData && tourData.length > 0) {
|
||||
const checkTourRequest = tourData.filter(
|
||||
@@ -583,63 +573,61 @@ function PdfRequestFiles(props) {
|
||||
setTourStatus(tourData);
|
||||
setRequestSignTour(checkTourRequest[0]?.requestSign || false);
|
||||
}
|
||||
} else if (res.length === 0) {
|
||||
setHandleError("Error: User does not exist!");
|
||||
} else if (res?.length === 0) {
|
||||
const res = await contactBook(currUserId);
|
||||
if (res === "Error: Something went wrong!") {
|
||||
setHandleError("Error: Something went wrong!");
|
||||
} else if (res[0] && res.length) {
|
||||
setContractName("_Contactbook");
|
||||
const objectId = res[0].objectId;
|
||||
setSignerUserId(objectId);
|
||||
const tourData = res[0].TourStatus && res[0].TourStatus;
|
||||
if (tourData && tourData.length > 0) {
|
||||
const checkTourRequest = tourData.filter(
|
||||
(data) => data?.requestSign
|
||||
);
|
||||
setTourStatus(tourData);
|
||||
setRequestSignTour(checkTourRequest[0]?.requestSign || false);
|
||||
}
|
||||
} else if (res.length === 0) {
|
||||
setHandleError("Error: User does not exist!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
setIsUiLoading(false);
|
||||
} else if (
|
||||
documentData === "Error: Something went wrong!" ||
|
||||
(documentData.result && documentData.result.error)
|
||||
) {
|
||||
setHandleError("Error: Something went wrong!");
|
||||
setIsLoading({
|
||||
isLoad: false
|
||||
});
|
||||
console.log("err in getDocument cloud function ");
|
||||
} else {
|
||||
setHandleError("No Data Found!");
|
||||
setIsUiLoading({
|
||||
isLoad: false
|
||||
});
|
||||
}
|
||||
await axios
|
||||
.get(
|
||||
`${localStorage.getItem(
|
||||
"baseUrl"
|
||||
)}classes/contracts_Signature?where={"UserId": {"__type": "Pointer","className": "_User", "objectId":"${
|
||||
jsonSender?.objectId
|
||||
}"}}`,
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"X-Parse-Application-Id": localStorage.getItem("parseAppId"),
|
||||
"X-Parse-Session-Token": localStorage.getItem("accesstoken")
|
||||
}
|
||||
}
|
||||
)
|
||||
.then((Listdata) => {
|
||||
const json = Listdata.data;
|
||||
const res = json.results;
|
||||
|
||||
if (res[0] && res.length > 0) {
|
||||
setDefaultSignImg(res[0].ImageURL);
|
||||
setMyInitial(res[0]?.Initials);
|
||||
}
|
||||
|
||||
const loadObj = {
|
||||
isLoad: false
|
||||
};
|
||||
setIsLoading(loadObj);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log("Err in contracts_Signature class", err);
|
||||
setIsUiLoading(false);
|
||||
} else if (
|
||||
documentData === "Error: Something went wrong!" ||
|
||||
(documentData.result && documentData.result.error)
|
||||
) {
|
||||
setHandleError("Error: Something went wrong!");
|
||||
setIsLoading({
|
||||
isLoad: false
|
||||
});
|
||||
console.log("err in getDocument cloud function ");
|
||||
} else {
|
||||
setHandleError("No Data Found!");
|
||||
setIsUiLoading({
|
||||
isLoad: false
|
||||
});
|
||||
}
|
||||
//function to get default signatur eof current user from `contracts_Signature` class
|
||||
const defaultSignRes = await getDefaultSignature(jsonSender.objectId);
|
||||
if (defaultSignRes?.status === "success") {
|
||||
setDefaultSignImg(defaultSignRes?.res?.defaultSignature);
|
||||
setMyInitial(defaultSignRes?.res?.defaultInitial);
|
||||
} else if (defaultSignRes?.status === "error") {
|
||||
setHandleError("Error: Something went wrong!");
|
||||
setIsLoading({
|
||||
isLoad: false
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
console.log("Error: error in getDocumentDetails", err);
|
||||
setHandleError("Error: Something went wrong!");
|
||||
setIsLoading({
|
||||
isLoad: false
|
||||
});
|
||||
}
|
||||
};
|
||||
//function for embed signature or image url in pdf
|
||||
async function embedWidgetsData() {
|
||||
@@ -2156,7 +2144,6 @@ function PdfRequestFiles(props) {
|
||||
{defaultSignImg && !alreadySign && currentSigner && (
|
||||
<DefaultSignature
|
||||
defaultSignImg={defaultSignImg}
|
||||
setDefaultSignImg={setDefaultSignImg}
|
||||
userObjectId={signerObjectId}
|
||||
setIsLoading={setIsLoading}
|
||||
xyPostion={signerPos}
|
||||
|
||||
@@ -33,7 +33,8 @@ import {
|
||||
fetchImageBase64,
|
||||
changeImageWH,
|
||||
handleSendOTP,
|
||||
getContainerScale
|
||||
getContainerScale,
|
||||
getDefaultSignature
|
||||
} from "../constant/Utils";
|
||||
import { useParams } from "react-router-dom";
|
||||
import Tour from "reactour";
|
||||
@@ -205,131 +206,91 @@ function SignYourSelf() {
|
||||
}, [divRef.current, isHeader]);
|
||||
//function for get document details for perticular signer with signer'object id
|
||||
const getDocumentDetails = async (showComplete) => {
|
||||
let isCompleted;
|
||||
//getting document details
|
||||
const documentData = await contractDocument(documentId);
|
||||
try {
|
||||
let isCompleted;
|
||||
//getting document details
|
||||
const documentData = await contractDocument(documentId);
|
||||
|
||||
if (documentData && documentData.length > 0) {
|
||||
setPdfDetails(documentData);
|
||||
setExtUserId(documentData[0]?.ExtUserPtr?.objectId);
|
||||
const url = documentData[0] && documentData[0]?.URL;
|
||||
if (url) {
|
||||
//convert document url in array buffer format to use embed widgets in pdf using pdf-lib
|
||||
const arrayBuffer = await convertPdfArrayBuffer(url);
|
||||
if (arrayBuffer === "Error") {
|
||||
if (documentData && documentData.length > 0) {
|
||||
setPdfDetails(documentData);
|
||||
setExtUserId(documentData[0]?.ExtUserPtr?.objectId);
|
||||
const url = documentData[0] && documentData[0]?.URL;
|
||||
if (url) {
|
||||
//convert document url in array buffer format to use embed widgets in pdf using pdf-lib
|
||||
const arrayBuffer = await convertPdfArrayBuffer(url);
|
||||
if (arrayBuffer === "Error") {
|
||||
setHandleError("Error: Something went wrong!");
|
||||
} else {
|
||||
setPdfArrayBuffer(arrayBuffer);
|
||||
}
|
||||
} else {
|
||||
setHandleError("Error: Something went wrong!");
|
||||
} else {
|
||||
setPdfArrayBuffer(arrayBuffer);
|
||||
}
|
||||
} else {
|
||||
setHandleError("Error: Something went wrong!");
|
||||
}
|
||||
isCompleted = documentData[0].IsCompleted && documentData[0].IsCompleted;
|
||||
if (isCompleted) {
|
||||
setIsCelebration(true);
|
||||
setTimeout(() => {
|
||||
setIsCelebration(false);
|
||||
}, 5000);
|
||||
setIsCompleted(true);
|
||||
setPdfUrl(documentData[0].SignedUrl);
|
||||
const alreadySign = {
|
||||
status: true,
|
||||
mssg: "Congratulations! 🎉 This document has been successfully signed by you!"
|
||||
};
|
||||
if (showComplete) {
|
||||
setShowAlreadySignDoc(alreadySign);
|
||||
} else {
|
||||
setIsUiLoading(false);
|
||||
setIsSignPad(false);
|
||||
setIsEmail(true);
|
||||
setXyPostion([]);
|
||||
setSignBtnPosition([]);
|
||||
}
|
||||
}
|
||||
} else if (
|
||||
documentData === "Error: Something went wrong!" ||
|
||||
(documentData.result && documentData.result.error)
|
||||
) {
|
||||
const loadObj = {
|
||||
isLoad: false
|
||||
};
|
||||
setHandleError("Error: Something went wrong!");
|
||||
setIsLoading(loadObj);
|
||||
} else {
|
||||
setHandleError("No Data Found!");
|
||||
const loadObj = {
|
||||
isLoad: false
|
||||
};
|
||||
setIsLoading(loadObj);
|
||||
}
|
||||
await axios
|
||||
.get(
|
||||
`${localStorage.getItem(
|
||||
"baseUrl"
|
||||
)}classes/contracts_Signature?where={"UserId": {"__type": "Pointer","className": "_User", "objectId":"${
|
||||
jsonSender.objectId
|
||||
}"}}`,
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"X-Parse-Application-Id": localStorage.getItem("parseAppId"),
|
||||
"X-Parse-Session-Token": localStorage.getItem("accesstoken")
|
||||
isCompleted =
|
||||
documentData[0].IsCompleted && documentData[0].IsCompleted;
|
||||
if (isCompleted) {
|
||||
setIsCelebration(true);
|
||||
setTimeout(() => {
|
||||
setIsCelebration(false);
|
||||
}, 5000);
|
||||
setIsCompleted(true);
|
||||
setPdfUrl(documentData[0].SignedUrl);
|
||||
const alreadySign = {
|
||||
status: true,
|
||||
mssg: "Congratulations! 🎉 This document has been successfully signed by you!"
|
||||
};
|
||||
if (showComplete) {
|
||||
setShowAlreadySignDoc(alreadySign);
|
||||
} else {
|
||||
setIsUiLoading(false);
|
||||
setIsSignPad(false);
|
||||
setIsEmail(true);
|
||||
setXyPostion([]);
|
||||
setSignBtnPosition([]);
|
||||
}
|
||||
}
|
||||
)
|
||||
.then((Listdata) => {
|
||||
const json = Listdata.data;
|
||||
const res = json.results;
|
||||
if (res[0] && res.length > 0) {
|
||||
setDefaultSignImg(res[0].ImageURL);
|
||||
setMyInitial(res[0]?.Initials);
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log("Err ", err);
|
||||
} else if (
|
||||
documentData === "Error: Something went wrong!" ||
|
||||
(documentData.result && documentData.result.error)
|
||||
) {
|
||||
const loadObj = {
|
||||
isLoad: false
|
||||
};
|
||||
setHandleError("Error: Something went wrong!");
|
||||
setIsLoading(loadObj);
|
||||
});
|
||||
const contractUsersRes = await contractUsers();
|
||||
if (contractUsersRes === "Error: Something went wrong!") {
|
||||
const loadObj = {
|
||||
isLoad: false
|
||||
};
|
||||
setHandleError("Error: Something went wrong!");
|
||||
setIsLoading(loadObj);
|
||||
} else if (contractUsersRes[0] && contractUsersRes.length > 0) {
|
||||
setActiveMailAdapter(contractUsersRes[0]?.active_mail_adapter);
|
||||
setContractName("_Users");
|
||||
setSignerUserId(contractUsersRes[0].objectId);
|
||||
const tourstatuss =
|
||||
contractUsersRes[0].TourStatus && contractUsersRes[0].TourStatus;
|
||||
if (tourstatuss && tourstatuss.length > 0 && !isCompleted) {
|
||||
setTourStatus(tourstatuss);
|
||||
const checkTourRecipients = tourstatuss.filter(
|
||||
(data) => data.signyourself
|
||||
);
|
||||
if (checkTourRecipients && checkTourRecipients.length > 0) {
|
||||
setCheckTourStatus(checkTourRecipients[0].signyourself);
|
||||
}
|
||||
} else {
|
||||
setCheckTourStatus(true);
|
||||
setHandleError("No Data Found!");
|
||||
const loadObj = {
|
||||
isLoad: false
|
||||
};
|
||||
setIsLoading(loadObj);
|
||||
}
|
||||
const loadObj = {
|
||||
isLoad: false
|
||||
};
|
||||
setIsLoading(loadObj);
|
||||
} else if (contractUsersRes.length === 0) {
|
||||
const contractContactBook = await contactBook(jsonSender.objectId);
|
||||
if (contractContactBook && contractContactBook.length > 0) {
|
||||
setContractName("_Contactbook");
|
||||
setSignerUserId(contractContactBook[0].objectId);
|
||||
const tourstatuss =
|
||||
contractContactBook[0].TourStatus &&
|
||||
contractContactBook[0].TourStatus;
|
||||
|
||||
//function to get default signatur eof current user from `contracts_Signature` class
|
||||
const defaultSignRes = await getDefaultSignature(jsonSender.objectId);
|
||||
console.log("defaultSignRes", defaultSignRes);
|
||||
if (defaultSignRes?.status === "success") {
|
||||
setDefaultSignImg(defaultSignRes?.res?.defaultSignature);
|
||||
setMyInitial(defaultSignRes?.res?.defaultInitial);
|
||||
} else if (defaultSignRes?.status === "error") {
|
||||
setHandleError("Error: Something went wrong!");
|
||||
setIsLoading({
|
||||
isLoad: false
|
||||
});
|
||||
}
|
||||
const contractUsersRes = await contractUsers();
|
||||
if (contractUsersRes === "Error: Something went wrong!") {
|
||||
const loadObj = {
|
||||
isLoad: false
|
||||
};
|
||||
setHandleError("Error: Something went wrong!");
|
||||
setIsLoading(loadObj);
|
||||
} else if (contractUsersRes[0] && contractUsersRes.length > 0) {
|
||||
setActiveMailAdapter(contractUsersRes[0]?.active_mail_adapter);
|
||||
setContractName("_Users");
|
||||
setSignerUserId(contractUsersRes[0].objectId);
|
||||
const tourstatuss =
|
||||
contractUsersRes[0].TourStatus && contractUsersRes[0].TourStatus;
|
||||
if (tourstatuss && tourstatuss.length > 0 && !isCompleted) {
|
||||
setTourStatus(tourstatuss);
|
||||
const checkTourRecipients = tourstatuss.filter(
|
||||
@@ -341,15 +302,47 @@ function SignYourSelf() {
|
||||
} else {
|
||||
setCheckTourStatus(true);
|
||||
}
|
||||
} else {
|
||||
setHandleError("No Data Found!");
|
||||
const loadObj = {
|
||||
isLoad: false
|
||||
};
|
||||
setIsLoading(loadObj);
|
||||
} else if (contractUsersRes.length === 0) {
|
||||
const contractContactBook = await contactBook(jsonSender.objectId);
|
||||
if (contractContactBook && contractContactBook.length > 0) {
|
||||
setContractName("_Contactbook");
|
||||
setSignerUserId(contractContactBook[0].objectId);
|
||||
const tourstatuss =
|
||||
contractContactBook[0].TourStatus &&
|
||||
contractContactBook[0].TourStatus;
|
||||
|
||||
if (tourstatuss && tourstatuss.length > 0 && !isCompleted) {
|
||||
setTourStatus(tourstatuss);
|
||||
const checkTourRecipients = tourstatuss.filter(
|
||||
(data) => data.signyourself
|
||||
);
|
||||
if (checkTourRecipients && checkTourRecipients.length > 0) {
|
||||
setCheckTourStatus(checkTourRecipients[0].signyourself);
|
||||
}
|
||||
} else {
|
||||
setCheckTourStatus(true);
|
||||
}
|
||||
} else {
|
||||
setHandleError("No Data Found!");
|
||||
}
|
||||
const loadObj = {
|
||||
isLoad: false
|
||||
};
|
||||
setIsLoading(loadObj);
|
||||
}
|
||||
const loadObj = {
|
||||
} catch (err) {
|
||||
console.log("Error: error in getDocumentDetails", err);
|
||||
setHandleError("Error: Something went wrong!");
|
||||
setIsLoading({
|
||||
isLoad: false
|
||||
};
|
||||
setIsLoading(loadObj);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const getWidgetValue = (type) => {
|
||||
switch (type) {
|
||||
case "name":
|
||||
@@ -1310,12 +1303,12 @@ function SignYourSelf() {
|
||||
isEmail={isEmail}
|
||||
pdfUrl={pdfUrl}
|
||||
setIsEmail={setIsEmail}
|
||||
pdfName={pdfDetails[0] && pdfDetails[0].Name}
|
||||
setSuccessEmail={setSuccessEmail}
|
||||
sender={jsonSender}
|
||||
setIsAlert={setIsAlert}
|
||||
extUserId={extUserId}
|
||||
activeMailAdapter={activeMailAdapter}
|
||||
pdfDetails={pdfDetails}
|
||||
/>
|
||||
{/* pdf header which contain funish back button */}
|
||||
<Header
|
||||
|
||||
Reference in New Issue
Block a user