diff --git a/apps/OpenSign/package-lock.json b/apps/OpenSign/package-lock.json index 311171281..4cc4ec3d6 100644 --- a/apps/OpenSign/package-lock.json +++ b/apps/OpenSign/package-lock.json @@ -43,6 +43,7 @@ "react-select": "^5.8.0", "react-signature-canvas": "^1.0.6", "react-tooltip": "^5.26.3", + "react-web-share": "^2.0.2", "reactour": "^1.19.2", "redux": "^5.0.1", "redux-thunk": "^3.1.0", @@ -20225,6 +20226,15 @@ "react-dom": ">=16.6.0" } }, + "node_modules/react-web-share": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/react-web-share/-/react-web-share-2.0.2.tgz", + "integrity": "sha512-bGm1TJc6xtC0MhAnYFsrzT4En7l2oAdLTgCK7nk7b4xGTg3L5gOldiPrmYQ8a/dEXNydgekvOj/tfjduIlIRVA==", + "peerDependencies": { + "react": "^16 || ^17 || ^18", + "react-dom": "^16 || ^17 || ^18" + } + }, "node_modules/reactour": { "version": "1.19.2", "resolved": "https://registry.npmjs.org/reactour/-/reactour-1.19.2.tgz", diff --git a/apps/OpenSign/package.json b/apps/OpenSign/package.json index 801361767..d7a59becc 100644 --- a/apps/OpenSign/package.json +++ b/apps/OpenSign/package.json @@ -38,6 +38,7 @@ "react-select": "^5.8.0", "react-signature-canvas": "^1.0.6", "react-tooltip": "^5.26.3", + "react-web-share": "^2.0.2", "reactour": "^1.19.2", "redux": "^5.0.1", "redux-thunk": "^3.1.0", diff --git a/apps/OpenSign/src/constant/Utils.js b/apps/OpenSign/src/constant/Utils.js index e8bea0151..4d32a960e 100644 --- a/apps/OpenSign/src/constant/Utils.js +++ b/apps/OpenSign/src/constant/Utils.js @@ -1862,3 +1862,18 @@ export function replaceMailVaribles(subject, body, variables) { }; return result; } + +export const copytoData = (text) => { + // navigator.clipboard.writeText(text); + if (navigator.clipboard) { + navigator.clipboard.writeText(text); + } else { + // Fallback for browsers that don't support navigator.clipboard + const textArea = document.createElement("textarea"); + textArea.value = text; + document.body.appendChild(textArea); + textArea.select(); + document.execCommand("copy"); + document.body.removeChild(textArea); + } +}; diff --git a/apps/OpenSign/src/pages/GenerateToken.js b/apps/OpenSign/src/pages/GenerateToken.js index b5cb2b481..4ffcc2245 100644 --- a/apps/OpenSign/src/pages/GenerateToken.js +++ b/apps/OpenSign/src/pages/GenerateToken.js @@ -5,7 +5,7 @@ import { useNavigate } from "react-router-dom"; import Alert from "../primitives/Alert"; import ModalUi from "../primitives/ModalUi"; import { isEnableSubscription, rejectBtn, submitBtn } from "../constant/const"; -import { checkIsSubscribed, openInNewTab } from "../constant/Utils"; +import { checkIsSubscribed, copytoData, openInNewTab } from "../constant/Utils"; import PremiumAlertHeader from "../primitives/PremiumAlertHeader"; import Tooltip from "../primitives/Tooltip"; @@ -92,7 +92,7 @@ function GenerateToken() { }; const copytoclipboard = (text) => { - navigator.clipboard.writeText(text); + copytoData(text); setCopied(true); setTimeout(() => { setCopied(false); diff --git a/apps/OpenSign/src/pages/Login.js b/apps/OpenSign/src/pages/Login.js index f192e34c5..9a7501545 100644 --- a/apps/OpenSign/src/pages/Login.js +++ b/apps/OpenSign/src/pages/Login.js @@ -44,7 +44,7 @@ function Login() { Destination: "" }); const [isModal, setIsModal] = useState(false); - const [image, setImage] = useState(appInfo?.applogo); + const [image, setImage] = useState(); useEffect(() => { if (localStorage.getItem("accesstoken")) { @@ -65,6 +65,8 @@ function Login() { } else { setImage(appInfo?.applogo || undefined); } + } else { + setImage(appInfo?.applogo || undefined); } }; const handleChange = (event) => { diff --git a/apps/OpenSign/src/pages/PdfRequestFiles.js b/apps/OpenSign/src/pages/PdfRequestFiles.js index bc64c7766..30598b1c3 100644 --- a/apps/OpenSign/src/pages/PdfRequestFiles.js +++ b/apps/OpenSign/src/pages/PdfRequestFiles.js @@ -385,354 +385,351 @@ function PdfRequestFiles() { }); }; - const checkSendInOrder = () => { - if (sendInOrder) { - const index = pdfDetails?.[0].Signers.findIndex( - (x) => x.Email === jsonSender.email - ); - const newIndex = index - 1; - if (newIndex !== -1) { - const user = pdfDetails?.[0].Signers[newIndex]; - const isPrevUserSigned = - pdfDetails?.[0].AuditTrail && - pdfDetails?.[0].AuditTrail.some( - (x) => - x.UserPtr.objectId === user.objectId && x.Activity === "Signed" - ); - if (isPrevUserSigned) { - return true; - } else { - return false; - } - } else { - return true; - } - } else { - return true; - } - }; + // const checkSendInOrder = () => { + // if (sendInOrder) { + // const index = pdfDetails?.[0].Signers.findIndex( + // (x) => x.Email === jsonSender.email + // ); + // const newIndex = index - 1; + // if (newIndex !== -1) { + // const user = pdfDetails?.[0].Signers[newIndex]; + // const isPrevUserSigned = + // pdfDetails?.[0].AuditTrail && + // pdfDetails?.[0].AuditTrail.some( + // (x) => + // x.UserPtr.objectId === user.objectId && x.Activity === "Signed" + // ); + // if (isPrevUserSigned) { + // return true; + // } else { + // return false; + // } + // } else { + // return true; + // } + // } else { + // return true; + // } + // }; //function for embed signature or image url in pdf async function embedWidgetsData() { - const validateSigning = checkSendInOrder(); - if (validateSigning) { - const checkUser = signerPos.filter( - (data) => data.signerObjId === signerObjectId - ); - if (checkUser && checkUser.length > 0) { - let checkboxExist, - requiredRadio, - showAlert = false, - widgetKey, - radioExist, - requiredCheckbox; + // const validateSigning = checkSendInOrder(); + // if (validateSigning) { + const checkUser = signerPos.filter( + (data) => data.signerObjId === signerObjectId + ); + if (checkUser && checkUser.length > 0) { + let checkboxExist, + requiredRadio, + showAlert = false, + widgetKey, + radioExist, + requiredCheckbox; - for (let i = 0; i < checkUser[0].placeHolder.length; i++) { - for (let j = 0; j < checkUser[0].placeHolder[i].pos.length; j++) { - checkboxExist = - checkUser[0].placeHolder[i].pos[j].type === "checkbox"; - radioExist = - checkUser[0].placeHolder[i].pos[j].type === radioButtonWidget; - if (checkboxExist) { - requiredCheckbox = checkUser[0].placeHolder[i].pos.filter( - (position) => - !position.options?.isReadOnly && position.type === "checkbox" - ); + for (let i = 0; i < checkUser[0].placeHolder.length; i++) { + for (let j = 0; j < checkUser[0].placeHolder[i].pos.length; j++) { + checkboxExist = + checkUser[0].placeHolder[i].pos[j].type === "checkbox"; + radioExist = + checkUser[0].placeHolder[i].pos[j].type === radioButtonWidget; + if (checkboxExist) { + requiredCheckbox = checkUser[0].placeHolder[i].pos.filter( + (position) => + !position.options?.isReadOnly && position.type === "checkbox" + ); - if (requiredCheckbox && requiredCheckbox.length > 0) { - for (let i = 0; i < requiredCheckbox.length; i++) { - const minCount = - requiredCheckbox[i].options?.validation?.minRequiredCount; - const parseMin = minCount && parseInt(minCount); - const maxCount = - requiredCheckbox[i].options?.validation?.maxRequiredCount; - const parseMax = maxCount && parseInt(maxCount); - const response = - requiredCheckbox[i].options?.response?.length; - const defaultValue = - requiredCheckbox[i].options?.defaultValue?.length; - if (parseMin === 0 && parseMax === 0) { - if (!showAlert) { - showAlert = false; - setminRequiredCount(null); - } - } else if (parseMin === 0 && parseMax > 0) { - if (!showAlert) { - showAlert = false; - setminRequiredCount(null); - } - } else if (!response) { - if (!defaultValue) { - if (!showAlert) { - showAlert = true; - widgetKey = requiredCheckbox[i].key; - setminRequiredCount(parseMin); - } - } - } else if (parseMin > 0 && parseMin > response) { + if (requiredCheckbox && requiredCheckbox.length > 0) { + for (let i = 0; i < requiredCheckbox.length; i++) { + const minCount = + requiredCheckbox[i].options?.validation?.minRequiredCount; + const parseMin = minCount && parseInt(minCount); + const maxCount = + requiredCheckbox[i].options?.validation?.maxRequiredCount; + const parseMax = maxCount && parseInt(maxCount); + const response = requiredCheckbox[i].options?.response?.length; + const defaultValue = + requiredCheckbox[i].options?.defaultValue?.length; + if (parseMin === 0 && parseMax === 0) { + if (!showAlert) { + showAlert = false; + setminRequiredCount(null); + } + } else if (parseMin === 0 && parseMax > 0) { + if (!showAlert) { + showAlert = false; + setminRequiredCount(null); + } + } else if (!response) { + if (!defaultValue) { if (!showAlert) { showAlert = true; widgetKey = requiredCheckbox[i].key; setminRequiredCount(parseMin); } } + } else if (parseMin > 0 && parseMin > response) { + if (!showAlert) { + showAlert = true; + widgetKey = requiredCheckbox[i].key; + setminRequiredCount(parseMin); + } } } - } else if (radioExist) { - requiredRadio = checkUser[0].placeHolder[i].pos.filter( - (position) => - !position.options?.isReadOnly && - position.type === radioButtonWidget - ); - if (requiredRadio && requiredRadio?.length > 0) { - let checkSigned; - for (let i = 0; i < requiredRadio?.length; i++) { - checkSigned = requiredRadio[i]?.options.response; - if (!checkSigned) { - let checkDefaultSigned = - requiredRadio[i]?.options.defaultValue; + } + } else if (radioExist) { + requiredRadio = checkUser[0].placeHolder[i].pos.filter( + (position) => + !position.options?.isReadOnly && + position.type === radioButtonWidget + ); + if (requiredRadio && requiredRadio?.length > 0) { + let checkSigned; + for (let i = 0; i < requiredRadio?.length; i++) { + checkSigned = requiredRadio[i]?.options.response; + if (!checkSigned) { + let checkDefaultSigned = + requiredRadio[i]?.options.defaultValue; + if (!checkDefaultSigned) { + if (!showAlert) { + showAlert = true; + widgetKey = requiredRadio[i].key; + setminRequiredCount(null); + } + } + } + } + } + } else { + const requiredWidgets = checkUser[0].placeHolder[i].pos.filter( + (position) => + position.options?.status === "required" && + position.type !== radioButtonWidget && + position.type !== "checkbox" + ); + if (requiredWidgets && requiredWidgets?.length > 0) { + let checkSigned; + for (let i = 0; i < requiredWidgets?.length; i++) { + checkSigned = requiredWidgets[i]?.options?.response; + if (!checkSigned) { + const checkSignUrl = requiredWidgets[i]?.pos?.SignUrl; + + let checkDefaultSigned = + requiredWidgets[i]?.options?.defaultValue; + if (!checkSignUrl) { if (!checkDefaultSigned) { if (!showAlert) { showAlert = true; - widgetKey = requiredRadio[i].key; + widgetKey = requiredWidgets[i].key; setminRequiredCount(null); } } } } } - } else { - const requiredWidgets = checkUser[0].placeHolder[i].pos.filter( - (position) => - position.options?.status === "required" && - position.type !== radioButtonWidget && - position.type !== "checkbox" - ); - if (requiredWidgets && requiredWidgets?.length > 0) { - let checkSigned; - for (let i = 0; i < requiredWidgets?.length; i++) { - checkSigned = requiredWidgets[i]?.options?.response; - if (!checkSigned) { - const checkSignUrl = requiredWidgets[i]?.pos?.SignUrl; - - let checkDefaultSigned = - requiredWidgets[i]?.options?.defaultValue; - if (!checkSignUrl) { - if (!checkDefaultSigned) { - if (!showAlert) { - showAlert = true; - widgetKey = requiredWidgets[i].key; - setminRequiredCount(null); - } - } - } - } - } - } } } } + } - if (checkboxExist && requiredCheckbox && showAlert) { - setUnSignedWidgetId(widgetKey); - setWidgetsTour(true); - } else if (radioExist && showAlert) { - setUnSignedWidgetId(widgetKey); - setWidgetsTour(true); - } else if (showAlert) { - setUnSignedWidgetId(widgetKey); - setWidgetsTour(true); - } else { - setIsUiLoading(true); - const pngUrl = checkUser[0].placeHolder; - // Load a PDFDocument from the existing PDF bytes - const existingPdfBytes = await fetch(pdfUrl).then((res) => - res.arrayBuffer() - ); - const pdfDoc = await PDFDocument.load(existingPdfBytes, { - ignoreEncryption: true - }); - const flag = false; - const extUserPtr = pdfDetails[0].ExtUserPtr; - const HeaderDocId = extUserPtr?.HeaderDocId; - //embed document's object id to all pages in pdf document - if (!HeaderDocId) { - if (!isDocId) { - await embedDocId(pdfDoc, documentId, allPages); - } + if (checkboxExist && requiredCheckbox && showAlert) { + setUnSignedWidgetId(widgetKey); + setWidgetsTour(true); + } else if (radioExist && showAlert) { + setUnSignedWidgetId(widgetKey); + setWidgetsTour(true); + } else if (showAlert) { + setUnSignedWidgetId(widgetKey); + setWidgetsTour(true); + } else { + setIsUiLoading(true); + const pngUrl = checkUser[0].placeHolder; + // Load a PDFDocument from the existing PDF bytes + const existingPdfBytes = await fetch(pdfUrl).then((res) => + res.arrayBuffer() + ); + const pdfDoc = await PDFDocument.load(existingPdfBytes, { + ignoreEncryption: true + }); + const flag = false; + const extUserPtr = pdfDetails[0].ExtUserPtr; + const HeaderDocId = extUserPtr?.HeaderDocId; + //embed document's object id to all pages in pdf document + if (!HeaderDocId) { + if (!isDocId) { + await embedDocId(pdfDoc, documentId, allPages); } - //embed multi signature in pdf - const pdfBytes = await multiSignEmbed( - pngUrl, - pdfDoc, - pdfOriginalWidth, - flag, - containerWH + } + //embed multi signature in pdf + const pdfBytes = await multiSignEmbed( + pngUrl, + pdfDoc, + pdfOriginalWidth, + flag, + containerWH + ); + //get ExistUserPtr object id of user class to get tenantDetails + const objectId = pdfDetails?.[0]?.ExtUserPtr?.UserId?.objectId; + //function for call to embed signature in pdf and get digital signature pdf + try { + const res = await signPdfFun( + pdfBytes, + documentId, + signerObjectId, + setIsAlert, + objectId, + isSubscribed ); - //get ExistUserPtr object id of user class to get tenantDetails - const objectId = pdfDetails?.[0]?.ExtUserPtr?.UserId?.objectId; - //function for call to embed signature in pdf and get digital signature pdf - try { - const res = await signPdfFun( - pdfBytes, - documentId, - signerObjectId, - setIsAlert, - objectId, - isSubscribed - ); - if (res && res.status === "success") { - setPdfUrl(res.data); - setIsSigned(true); - setSignedSigners([]); - setUnSignedSigners([]); - getDocumentDetails(); - if (sendInOrder) { - const index = pdfDetails?.[0].Signers.findIndex( - (x) => x.Email === jsonSender.email - ); - const requestBody = pdfDetails?.[0]?.RequestBody; - const requestSubject = pdfDetails?.[0]?.RequestSubject; + if (res && res.status === "success") { + setPdfUrl(res.data); + setIsSigned(true); + setSignedSigners([]); + setUnSignedSigners([]); + getDocumentDetails(); + if (sendInOrder) { + const index = pdfDetails?.[0].Signers.findIndex( + (x) => x.Email === jsonSender.email + ); + const requestBody = pdfDetails?.[0]?.RequestBody; + const requestSubject = pdfDetails?.[0]?.RequestSubject; - const newIndex = index + 1; - const user = pdfDetails?.[0].Signers[newIndex]; - if (user) { - const expireDate = pdfDetails?.[0].ExpiryDate.iso; - const newDate = new Date(expireDate); - const localExpireDate = newDate.toLocaleDateString("en-US", { - day: "numeric", - month: "long", - year: "numeric" - }); - let senderEmail = pdfDetails?.[0].ExtUserPtr.Email; - let senderPhone = pdfDetails?.[0]?.ExtUserPtr?.Phone; - const senderName = `${pdfDetails?.[0].ExtUserPtr.Name}`; + const newIndex = index + 1; + const user = pdfDetails?.[0].Signers[newIndex]; + if (user) { + const expireDate = pdfDetails?.[0].ExpiryDate.iso; + const newDate = new Date(expireDate); + const localExpireDate = newDate.toLocaleDateString("en-US", { + day: "numeric", + month: "long", + year: "numeric" + }); + let senderEmail = pdfDetails?.[0].ExtUserPtr.Email; + let senderPhone = pdfDetails?.[0]?.ExtUserPtr?.Phone; + const senderName = `${pdfDetails?.[0].ExtUserPtr.Name}`; - try { - const imgPng = - "https://qikinnovation.ams3.digitaloceanspaces.com/logo.png"; - let url = `${localStorage.getItem( - "baseUrl" - )}functions/sendmailv3/`; - const headers = { - "Content-Type": "application/json", - "X-Parse-Application-Id": - localStorage.getItem("parseAppId"), - sessionToken: localStorage.getItem("accesstoken") + try { + const imgPng = + "https://qikinnovation.ams3.digitaloceanspaces.com/logo.png"; + let url = `${localStorage.getItem( + "baseUrl" + )}functions/sendmailv3/`; + const headers = { + "Content-Type": "application/json", + "X-Parse-Application-Id": + localStorage.getItem("parseAppId"), + sessionToken: localStorage.getItem("accesstoken") + }; + const serverUrl = localStorage.getItem("baseUrl"); + const newServer = serverUrl.replaceAll("/", "%2F"); + const objectId = user.objectId; + const serverParams = `${newServer}&${localStorage.getItem( + "parseAppId" + )}&${localStorage.getItem("_appName")}`; + const hostUrl = window.location.origin; + let signPdf = `${hostUrl}/login/${pdfDetails?.[0].objectId}/${user.Email}/${objectId}/${serverParams}`; + const openSignUrl = "https://www.opensignlabs.com/contact-us"; + const orgName = pdfDetails[0]?.ExtUserPtr.Company + ? pdfDetails[0].ExtUserPtr.Company + : ""; + const themeBGcolor = themeColor; + let replaceVar; + if ( + requestBody && + requestSubject && + (!isEnableSubscription || isSubscribed) + ) { + const replacedRequestBody = requestBody.replace(/"/g, "'"); + const htmlReqBody = + "" + + replacedRequestBody + + " "; + + const variables = { + document_title: pdfDetails?.[0].Name, + sender_name: senderName, + sender_mail: senderEmail, + sender_phone: senderPhone, + receiver_name: user.Name, + receiver_email: user.Email, + receiver_phone: user.Phone, + expiry_date: localExpireDate, + company_name: orgName, + signing_url: `Sign here` }; - const serverUrl = localStorage.getItem("baseUrl"); - const newServer = serverUrl.replaceAll("/", "%2F"); - const objectId = user.objectId; - const serverParams = `${newServer}&${localStorage.getItem( - "parseAppId" - )}&${localStorage.getItem("_appName")}`; - const hostUrl = window.location.origin; - let signPdf = `${hostUrl}/login/${pdfDetails?.[0].objectId}/${user.Email}/${objectId}/${serverParams}`; - const openSignUrl = - "https://www.opensignlabs.com/contact-us"; - const orgName = pdfDetails[0]?.ExtUserPtr.Company - ? pdfDetails[0].ExtUserPtr.Company - : ""; - const themeBGcolor = themeColor; - let replaceVar; - if ( - requestBody && - requestSubject && - (!isEnableSubscription || isSubscribed) - ) { - const replacedRequestBody = requestBody.replace( - /"/g, - "'" - ); - const htmlReqBody = - "" + - replacedRequestBody + - " "; - - const variables = { - document_title: pdfDetails?.[0].Name, - sender_name: senderName, - sender_mail: senderEmail, - sender_phone: senderPhone, - receiver_name: user.Name, - receiver_email: user.Email, - receiver_phone: user.Phone, - expiry_date: localExpireDate, - company_name: orgName, - signing_url: `Sign here` - }; - replaceVar = replaceMailVaribles( - requestSubject, - htmlReqBody, - variables - ); - } - - let params = { - extUserId: extUserId, - recipient: user.Email, - subject: requestSubject - ? replaceVar?.subject - : `${pdfDetails?.[0].ExtUserPtr.Name} has requested you to sign ${pdfDetails?.[0].Name}`, - from: senderEmail, - html: requestBody - ? replaceVar?.body - : "

Digital Signature Request

" + - pdfDetails?.[0].ExtUserPtr.Name + - " has requested you to review and sign " + - pdfDetails?.[0].Name + - ".

Sender " + - senderEmail + - "
Organization " + - orgName + - "
Expires on " + - localExpireDate + - "

This is an automated email from OpenSign™. For any queries regarding this email, please contact the sender " + - senderEmail + - " directly.If you think this email is inappropriate or spam, you may file a complaint with OpenSign™ here.

" - }; - await axios.post(url, params, { - headers: headers - }); - } catch (error) { - console.log("error", error); + replaceVar = replaceMailVaribles( + requestSubject, + htmlReqBody, + variables + ); } + + let params = { + extUserId: extUserId, + recipient: user.Email, + subject: requestSubject + ? replaceVar?.subject + : `${pdfDetails?.[0].ExtUserPtr.Name} has requested you to sign ${pdfDetails?.[0].Name}`, + from: senderEmail, + html: requestBody + ? replaceVar?.body + : "

Digital Signature Request

" + + pdfDetails?.[0].ExtUserPtr.Name + + " has requested you to review and sign " + + pdfDetails?.[0].Name + + ".

Sender " + + senderEmail + + "
Organization " + + orgName + + "
Expires on " + + localExpireDate + + "

This is an automated email from OpenSign™. For any queries regarding this email, please contact the sender " + + senderEmail + + " directly.If you think this email is inappropriate or spam, you may file a complaint with OpenSign™ here.

" + }; + await axios.post(url, params, { + headers: headers + }); + } catch (error) { + console.log("error", error); } } - } else { - setIsAlert({ - isShow: true, - alertMessage: "something went wrong" - }); } - } catch (err) { + } else { setIsAlert({ isShow: true, alertMessage: "something went wrong" }); } + } catch (err) { + setIsAlert({ + isShow: true, + alertMessage: "something went wrong" + }); } - setIsSignPad(false); - } else { - setIsAlert({ - isShow: true, - alertMessage: "something went wrong" - }); } + setIsSignPad(false); } else { setIsAlert({ isShow: true, - alertMessage: - "Please wait for your turn to sign this document, as it has been set up by the creator to be signed in a specific order; you'll be notified when it's your turn." + alertMessage: "something went wrong" }); } + + // } + // else { + // setIsAlert({ + // isShow: true, + // alertMessage: + // "Please wait for your turn to sign this document, as it has been set up by the creator to be signed in a specific order; you'll be notified when it's your turn." + // }); + // } } //function for update TourStatus diff --git a/apps/OpenSign/src/pages/PlaceHolderSign.js b/apps/OpenSign/src/pages/PlaceHolderSign.js index 42e9dda67..7dd5fb6f3 100644 --- a/apps/OpenSign/src/pages/PlaceHolderSign.js +++ b/apps/OpenSign/src/pages/PlaceHolderSign.js @@ -16,6 +16,7 @@ import Loader from "../primitives/LoaderWithMsg"; import HandleError from "../primitives/HandleError"; import SignerListPlace from "../components/pdf/SignerListPlace"; import Header from "../components/pdf/PdfHeader"; +import { RWebShare } from "react-web-share"; import { pdfNewWidthFun, contractDocument, @@ -30,7 +31,8 @@ import { radioButtonWidget, color, getTenantDetails, - replaceMailVaribles + replaceMailVaribles, + copytoData } from "../constant/Utils"; import RenderPdf from "../components/pdf/RenderPdf"; import { useNavigate } from "react-router-dom"; @@ -44,6 +46,7 @@ import WidgetNameModal from "../components/pdf/WidgetNameModal"; import { SaveFileSize } from "../constant/saveFileSize"; import { EmailBody } from "../components/pdf/EmailBody"; import Upgrade from "../primitives/Upgrade"; +import Alert from "../primitives/Alert"; function PlaceHolderSign() { const editorRef = useRef(); @@ -63,6 +66,7 @@ function PlaceHolderSign() { const [isSelectListId, setIsSelectId] = useState(); const [isSendAlert, setIsSendAlert] = useState({}); const [isSend, setIsSend] = useState(false); + const [copied, setCopied] = useState(false); const [isLoading, setIsLoading] = useState({ isLoad: true, message: "This might take some time" @@ -857,6 +861,7 @@ function PlaceHolderSign() { mssg: "confirm", alert: true }; + saveDocumentDetails(); setIsSendAlert(alert); } } else { @@ -868,10 +873,146 @@ function PlaceHolderSign() { } }; + //function to use save placeholder details in contracts_document + const saveDocumentDetails = async () => { + let signerMail = signersdata.slice(); + if (pdfDetails?.[0]?.SendinOrder && pdfDetails?.[0]?.SendinOrder === true) { + signerMail.splice(1); + } + const pdfUrl = await embedPrefilllData(); + const signers = signersdata?.map((x) => { + return { + __type: "Pointer", + className: "contracts_Contactbook", + objectId: x.objectId + }; + }); + const addExtraDays = pdfDetails[0]?.TimeToCompleteDays + ? pdfDetails[0].TimeToCompleteDays + : 15; + const currentUser = signersdata.find((x) => x.Email === currentId); + setCurrentId(currentUser?.objectId); + if (pdfDetails?.[0]?.SendinOrder && pdfDetails?.[0]?.SendinOrder === true) { + const currentUserMail = Parse.User.current()?.getEmail(); + const isCurrentUser = signerMail?.[0]?.Email === currentUserMail; + setIsCurrUser(isCurrentUser); + } else { + setIsCurrUser(currentUser?.objectId ? true : false); + } + let updateExpiryDate, data; + updateExpiryDate = new Date(); + updateExpiryDate.setDate(updateExpiryDate.getDate() + addExtraDays); + //filter label widgets after add label widgets data on pdf + const filterPrefill = signerPos.filter((data) => data.Role !== "prefill"); + + try { + if (updateExpiryDate) { + data = { + Placeholders: filterPrefill, + SignedUrl: pdfUrl, + Signers: signers, + ExpiryDate: { + iso: updateExpiryDate, + __type: "Date" + } + }; + } else { + data = { + Placeholders: filterPrefill, + SignedUrl: pdfUrl, + Signers: signers + }; + } + await axios + .put( + `${localStorage.getItem("baseUrl")}classes/${localStorage.getItem( + "_appName" + )}_Document/${documentId}`, + data, + { + headers: { + "Content-Type": "application/json", + "X-Parse-Application-Id": localStorage.getItem("parseAppId"), + "X-Parse-Session-Token": localStorage.getItem("accesstoken") + } + } + ) + .then(() => { + setIsMailSend(true); + setSignerPos([]); + }) + .catch((err) => { + console.log("axois err ", err); + alert("something went wrong"); + }); + } catch (e) { + console.log("error", e); + alert("something went wrong"); + } + }; + + const copytoclipboard = (text) => { + copytoData(text); + setCopied(true); + setTimeout(() => { + setCopied(false); + }, 1500); // Reset copied state after 1.5 seconds + }; + //function show signer list and share link to share signUrl + const handleShareList = () => { + const shareLinkList = []; + let signerMail = signersdata.slice(); + if (pdfDetails?.[0]?.SendinOrder && pdfDetails?.[0]?.SendinOrder === true) { + signerMail.splice(1); + } + for (let i = 0; i < signerMail.length; i++) { + const serverUrl = localStorage.getItem("baseUrl"); + const newServer = serverUrl.replaceAll("/", "%2F"); + const objectId = signerMail[i].objectId; + const serverParams = `${newServer}&${localStorage.getItem( + "parseAppId" + )}&${localStorage.getItem("_appName")}`; + + const hostUrl = window.location.origin; + let signPdf = `${hostUrl}/login/${pdfDetails?.[0].objectId}/${signerMail[i].Email}/${objectId}/${serverParams}`; + shareLinkList.push({ signerEmail: signerMail[i].Email, url: signPdf }); + } + return shareLinkList.map((data, ind) => { + return ( +
+ {copied && Copied} + {data.signerEmail} +
+ copytoclipboard(data.url)} + > + copy link + + console.log("shared successfully!")} + > + + +
+
+ ); + }); + }; const sendEmailToSigners = async () => { let htmlReqBody; setIsUiLoading(true); - const pdfUrl = await embedPrefilllData(); setIsSendAlert({}); let sendMail; const expireDate = pdfDetails?.[0].ExpiryDate.iso; @@ -987,170 +1128,62 @@ function PlaceHolderSign() { } if (sendMail.data.result.status === "success") { setMailStatus("success"); - const signers = signersdata?.map((x) => { - return { - __type: "Pointer", - className: "contracts_Contactbook", - objectId: x.objectId - }; - }); - const addExtraDays = pdfDetails[0]?.TimeToCompleteDays - ? pdfDetails[0].TimeToCompleteDays - : 15; - const currentUser = signersdata.find((x) => x.Email === currentId); - setCurrentId(currentUser?.objectId); + if ( - pdfDetails?.[0]?.SendinOrder && - pdfDetails?.[0]?.SendinOrder === true + requestBody && + requestSubject && + isCustomize && + (isSubscribe || !isEnableSubscription) ) { - const currentUserMail = Parse.User.current()?.getEmail(); - const isCurrentUser = signerMail?.[0]?.Email === currentUserMail; - setIsCurrUser(isCurrentUser); - } else { - setIsCurrUser(currentUser?.objectId ? true : false); - } - let updateExpiryDate, data; - updateExpiryDate = new Date(); - updateExpiryDate.setDate(updateExpiryDate.getDate() + addExtraDays); - //filter label widgets after add label widgets data on pdf - const filterPrefill = signerPos.filter((data) => data.Role !== "prefill"); + try { + const data = { + RequestBody: htmlReqBody, + RequestSubject: requestSubject + }; - try { - if (updateExpiryDate) { - if (isCustomize) { - data = { - RequestBody: htmlReqBody, - RequestSubject: requestSubject, - Placeholders: filterPrefill, - SignedUrl: pdfUrl, - Signers: signers, - ExpiryDate: { - iso: updateExpiryDate, - __type: "Date" + await axios + .put( + `${localStorage.getItem("baseUrl")}classes/${localStorage.getItem( + "_appName" + )}_Document/${documentId}`, + data, + { + headers: { + "Content-Type": "application/json", + "X-Parse-Application-Id": localStorage.getItem("parseAppId"), + "X-Parse-Session-Token": localStorage.getItem("accesstoken") + } } - }; - } else { - data = { - Placeholders: filterPrefill, - SignedUrl: pdfUrl, - Signers: signers, - ExpiryDate: { - iso: updateExpiryDate, - __type: "Date" - } - }; - } - } else { - if (isCustomize) { - data = { - RequestBody: htmlReqBody, - RequestSubject: requestSubject, - Placeholders: filterPrefill, - SignedUrl: pdfUrl, - Signers: signers - }; - } else { - data = { - Placeholders: filterPrefill, - SignedUrl: pdfUrl, - Signers: signers - }; - } + ) + .then(() => { + setIsSend(true); + setIsMailSend(true); + const loadObj = { + isLoad: false + }; + setIsLoading(loadObj); + setIsUiLoading(false); + }) + .catch((err) => { + console.log("axois err ", err); + }); + } catch (e) { + console.log("error", e); } - - await axios - .put( - `${localStorage.getItem("baseUrl")}classes/${localStorage.getItem( - "_appName" - )}_Document/${documentId}`, - data, - { - headers: { - "Content-Type": "application/json", - "X-Parse-Application-Id": localStorage.getItem("parseAppId"), - "X-Parse-Session-Token": localStorage.getItem("accesstoken") - } - } - ) - .then(() => { - setIsSend(true); - setIsMailSend(true); - const loadObj = { - isLoad: false - }; - setIsLoading(loadObj); - setIsUiLoading(false); - }) - .catch((err) => { - console.log("axois err ", err); - }); - } catch (e) { - console.log("error", e); } + + setIsSend(true); + setIsMailSend(true); + const loadObj = { + isLoad: false + }; + setIsLoading(loadObj); + setIsUiLoading(false); } else { setMailStatus("failed"); - const signers = signersdata?.map((x) => { - return { - __type: "Pointer", - className: "contracts_Contactbook", - objectId: x.objectId - }; - }); - const addExtraDays = pdfDetails[0]?.TimeToCompleteDays - ? pdfDetails[0].TimeToCompleteDays - : 15; - const currentUser = signersdata.find((x) => x.Email === currentId); - setIsCurrUser(currentUser?.objectId ? true : false); - setCurrentId(currentUser?.objectId); - let updateExpiryDate, data; - updateExpiryDate = new Date(); - updateExpiryDate.setDate(updateExpiryDate.getDate() + addExtraDays); - const filterPrefill = signerPos.filter((data) => data.Role !== "prefill"); - - try { - if (updateExpiryDate) { - data = { - Placeholders: filterPrefill, - SignedUrl: pdfUrl, - Signers: signers, - ExpiryDate: { - iso: updateExpiryDate, - __type: "Date" - } - }; - } else { - data = { - Placeholders: filterPrefill, - SignedUrl: pdfUrl, - Signers: signers - }; - } - - await axios - .put( - `${localStorage.getItem("baseUrl")}classes/${localStorage.getItem( - "_appName" - )}_Document/${documentId}`, - data, - { - headers: { - "Content-Type": "application/json", - "X-Parse-Application-Id": localStorage.getItem("parseAppId"), - "X-Parse-Session-Token": localStorage.getItem("accesstoken") - } - } - ) - .then(() => { - setIsSend(true); - setIsMailSend(true); - setIsUiLoading(false); - }) - .catch((err) => { - console.log("axois err ", err); - }); - } catch (e) { - console.log("error", e); - } + setIsSend(true); + setIsMailSend(true); + setIsUiLoading(false); } }; const handleDontShow = (isChecked) => { @@ -1615,92 +1648,112 @@ function PlaceHolderSign() { ) : ( isSendAlert.mssg === "confirm" && ( <> -

- Are you sure you want to send out this document for - signatures? -

- <> + {!isCustomize && ( + + Are you sure you want to send out this document + for signatures? + + )} + {isCustomize && + (!isEnableSubscription || isSubscribe) && ( + <> + +
{ + setRequestBody(defaultBody); + setRequestSubject(defaultSubject); + }} + > + Reset to default +
+ + )}
{ - isSubscribe || - (!isEnableSubscription && - setIsCustomize(!isCustomize)); - }} > - - Cutomize Email - +
+ + {isCustomize && ( + + )} +
+ + {!isCustomize && ( + { + isSubscribe || + (!isEnableSubscription && + setIsCustomize(!isCustomize)); + }} + > + Cutomize Email + + )} {!isSubscribe && isEnableSubscription && ( )}
- - {isCustomize && - (!isEnableSubscription || isSubscribe) && ( - <> - -
{ - setRequestBody(defaultBody); - setRequestSubject(defaultSubject); - }} - > - Reset to default -
- - )} ) )} -
- {isSendAlert.mssg === "confirm" && ( - + <> +
+ + or + +
+
{handleShareList()}
+ )} - @@ -1746,6 +1799,7 @@ function PlaceHolderSign() { Yes )} +