🔥 The free & Open Source DocuSign alternative
JavaScript digital-signaturedocument-signingdocusign-alternativedocusign-freee-signatureelectronic-signatureelectronic-signaturesesignesignaturehacktoberfestjavascriptlegaltechmongodbnodejsopen-sourcepdf-signpdf-signaturereactjsself-hostedsign-pdf-files
fix: error in auto-sign feature unexpected issue encountered - something went wrong
RaktimaNXG9fa97f27f071
diff --git a/apps/OpenSign/src/components/pdf/EmailComponent.js b/apps/OpenSign/src/components/pdf/EmailComponent.jsindex a41f82cbb..77ee86b9c 100644--- a/apps/OpenSign/src/components/pdf/EmailComponent.js+++ b/apps/OpenSign/src/components/pdf/EmailComponent.js@@ -1,7 +1,11 @@import React, { useState } from "react";import { saveAs } from "file-saver";import axios from "axios";-import { getBase64FromUrl } from "../../constant/Utils";+import {+ getBase64FromUrl,+ handleDownloadPdf,+ handleToPrint+} from "../../constant/Utils";import { themeColor, emailRegex } from "../../constant/const";import printModule from "print-js";import Loader from "../../primitives/Loader";@@ -13,7 +17,7 @@ function EmailComponent({pdfUrl,setIsEmail,setSuccessEmail,- pdfName,+ pdfDetails,sender,setIsAlert,extUserId,@@ -24,10 +28,12 @@ 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 emailconst sendEmail = async () => {+ const pdfName = pdfDetails[0]?.Name;setIsLoading(true);-let sendMail;for (let i = 0; i < emailList.length; i++) {try {@@ -140,43 +146,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 */}@@ -190,6 +159,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">{t("successfully-signed")}@@ -197,7 +171,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>@@ -206,7 +180,9 @@ function EmailComponent({)}<buttonclassName="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>{t("download")}diff --git a/apps/OpenSign/src/constant/Utils.js b/apps/OpenSign/src/constant/Utils.jsindex 40be47d12..3321d35e1 100644--- a/apps/OpenSign/src/constant/Utils.js+++ b/apps/OpenSign/src/constant/Utils.js@@ -439,7 +439,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) => {@@ -447,8 +447,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);+ }};});}@@ -2230,3 +2234,42 @@ export const saveLanguageInLocal = (i18n) => {const detectedLanguage = i18n.language || "en";localStorage.setItem("i18nextLng", detectedLanguage);};+//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"+ };+ }+};diff --git a/apps/OpenSign/src/pages/PdfRequestFiles.js b/apps/OpenSign/src/pages/PdfRequestFiles.jsindex 1e77ff05a..43ddddb3c 100644--- a/apps/OpenSign/src/pages/PdfRequestFiles.js+++ b/apps/OpenSign/src/pages/PdfRequestFiles.js@@ -30,7 +30,8 @@ import {contactBook,handleDownloadPdf,handleToPrint,- handleDownloadCertificate+ handleDownloadCertificate,+ getDefaultSignature} from "../constant/Utils";import LoaderWithMsg from "../primitives/LoaderWithMsg";import HandleError from "../primitives/HandleError";@@ -340,243 +341,232 @@ function PdfRequestFiles(props) {};//function for get document details for perticular signer with signer'object idconst 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: t("document-signed-alert-1")- });- } 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+ 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");- if (checkCurrentUser) {- setCurrentSigner(true);+ 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: t("document-signed-alert-1")+ });+ } else {+ if (currUserId) {+ const checkCurrentUser = documentData[0].Placeholders.find(+ (data) => data?.signerObjId === currUserId+ );+ if (checkCurrentUser) {+ setCurrentSigner(true);+ }}}- }- const audittrailData =- documentData[0].AuditTrail &&- documentData[0].AuditTrail.length > 0 &&- documentData[0].AuditTrail.filter((data) => data.Activity === "Signed");+ 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);+ const checkAlreadySign =+ documentData[0].AuditTrail &&+ documentData[0].AuditTrail.length > 0 &&+ documentData[0].AuditTrail.filter(+ (data) =>+ data.UserPtr.objectId === currUserId && data.Activity === "Signed"+ );if (- obj &&- obj.Signers &&- obj.Signers.length > 0 &&- obj.Placeholders &&- obj.Placeholders.length > 0+ checkAlreadySign &&+ checkAlreadySign[0] &&+ checkAlreadySign.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- }- };+ 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")+ 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);+ );+ } catch (err) {+ console.log("Err ", err);+ }}}- }- let signers = [];- let unSignedSigner = [];+ 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);- } else {- placeholdersOrSigners.push(placeholder);+ 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);+ } else {+ placeholdersOrSigners.push(placeholder);+ }}- }- //condition to check already signed document by someone- if (audittrailData && audittrailData.length > 0) {- setIsDocId(true);+ //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;+ 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 (emailOrId === signedExist) {+ signers.push({ ...item });+ isSignedSignature = true;+ break;+ }+ }+ if (!isSignedSignature) {+ unSignedSigner.push({ ...item });}}- 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);}- 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(t("something-went-wrong-mssg"));- } 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- );- setTourStatus(tourData);- setRequestSignTour(checkTourRequest[0]?.requestSign || false);- }- } else if (res?.length === 0) {- const res = await contactBook(currUserId);+ 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(t("something-went-wrong-mssg"));- } 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(@@ -585,63 +575,61 @@ function PdfRequestFiles(props) {setTourStatus(tourData);setRequestSignTour(checkTourRequest[0]?.requestSign || false);}- } else if (res.length === 0) {- setHandleError(t("user-not-exist"));- }- }- }- setIsUiLoading(false);- } else if (- documentData === "Error: Something went wrong!" ||- (documentData.result && documentData.result.error)- ) {- setHandleError(t("something-went-wrong-mssg"));- setIsLoading({- isLoad: false- });- console.log("err in getDocument cloud function ");- } else {- setHandleError(t("no-data"));- 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")+ } else if (res?.length === 0) {+ const res = await contactBook(currUserId);+ if (res === "Error: Something went wrong!") {+ setHandleError(t("something-went-wrong-mssg"));+ } 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(t("user-not-exist"));+ }}}- )- .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(t("something-went-wrong-mssg"));setIsLoading({isLoad: false});+ console.log("err in getDocument cloud function ");+ } else {+ setHandleError(t("no-data"));+ 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 pdfasync function embedWidgetsData() {@@ -2164,7 +2152,6 @@ function PdfRequestFiles(props) {{defaultSignImg && !alreadySign && currentSigner && (<DefaultSignaturedefaultSignImg={defaultSignImg}- setDefaultSignImg={setDefaultSignImg}userObjectId={signerObjectId}setIsLoading={setIsLoading}xyPostion={signerPos}diff --git a/apps/OpenSign/src/pages/SignyourselfPdf.js b/apps/OpenSign/src/pages/SignyourselfPdf.jsindex c3155a123..b44c4afcd 100644--- a/apps/OpenSign/src/pages/SignyourselfPdf.js+++ b/apps/OpenSign/src/pages/SignyourselfPdf.js@@ -33,7 +33,8 @@ import {fetchImageBase64,changeImageWH,handleSendOTP,- getContainerScale+ getContainerScale,+ getDefaultSignature} from "../constant/Utils";import { useParams } from "react-router-dom";import Tour from "reactour";@@ -207,131 +208,90 @@ function SignYourSelf() {}, [divRef.current, isHeader]);//function for get document details for perticular signer with signer'object idconst 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") {- setHandleError(t("something-went-wrong-mssg"));- } else {- setPdfArrayBuffer(arrayBuffer);- }- } else {- setHandleError(t("something-went-wrong-mssg"));- }- 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: t("document-signed-alert")- };- if (showComplete) {- setShowAlreadySignDoc(alreadySign);+ 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(t("something-went-wrong-mssg"));+ } else {+ setPdfArrayBuffer(arrayBuffer);+ }} else {- setIsUiLoading(false);- setIsSignPad(false);- setIsEmail(true);- setXyPostion([]);- setSignBtnPosition([]);+ setHandleError(t("something-went-wrong-mssg"));}- }- } else if (- documentData === "Error: Something went wrong!" ||- (documentData.result && documentData.result.error)- ) {- const loadObj = {- isLoad: false- };- setHandleError(t("something-went-wrong-mssg"));- setIsLoading(loadObj);- } else {- setHandleError(t("no-data-avaliable"));- 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: t("document-signed-alert")+ };+ 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(t("something-went-wrong-mssg"));setIsLoading(loadObj);- });- const contractUsersRes = await contractUsers();- if (contractUsersRes === "Error: Something went wrong!") {- const loadObj = {- isLoad: false- };- setHandleError(t("something-went-wrong-mssg"));- 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(t("no-data-avaliable"));+ 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);+ //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(t("something-went-wrong-mssg"));+ setIsLoading(loadObj);+ } else if (contractUsersRes[0] && contractUsersRes.length > 0) {+ setActiveMailAdapter(contractUsersRes[0]?.active_mail_adapter);+ setContractName("_Users");+ setSignerUserId(contractUsersRes[0].objectId);const tourstatuss =- contractContactBook[0].TourStatus &&- contractContactBook[0].TourStatus;-+ contractUsersRes[0].TourStatus && contractUsersRes[0].TourStatus;if (tourstatuss && tourstatuss.length > 0 && !isCompleted) {setTourStatus(tourstatuss);const checkTourRecipients = tourstatuss.filter(@@ -343,13 +303,44 @@ function SignYourSelf() {} else {setCheckTourStatus(true);}- } else {- setHandleError(t("no-data-avaliable"));+ 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(t("no-data-avaliable"));+ }+ 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) => {@@ -1313,7 +1304,7 @@ function SignYourSelf() {isEmail={isEmail}pdfUrl={pdfUrl}setIsEmail={setIsEmail}- pdfName={pdfDetails[0] && pdfDetails[0].Name}+ pdfDetails={pdfDetails}setSuccessEmail={setSuccessEmail}sender={jsonSender}setIsAlert={setIsAlert}