🔥 The free & Open Source DocuSign alternative
JavaScript digital-signaturedocument-signingdocusign-alternativedocusign-freee-signatureelectronic-signatureelectronic-signaturesesignesignaturehacktoberfestjavascriptlegaltechmongodbnodejsopen-sourcepdf-signpdf-signaturereactjsself-hostedsign-pdf-files
fix: document decline event not trigger on revoke
prafull-opensignlabsb98040faac84
diff --git a/apps/OpenSign/src/pages/PdfRequestFiles.js b/apps/OpenSign/src/pages/PdfRequestFiles.jsindex 6b5cad2ae..ed07b180a 100644--- a/apps/OpenSign/src/pages/PdfRequestFiles.js+++ b/apps/OpenSign/src/pages/PdfRequestFiles.js@@ -1220,31 +1220,26 @@ function PdfRequestFiles(props) {);const jsonSender = JSON.parse(senderUser);setIsDecline({ isDeclined: false });- const data = {- IsDeclined: true,- DeclineReason: reason,- DeclineBy: {- __type: "Pointer",- className: "_User",- objectId: jsonSender?.objectId- }- };setIsUiLoading(true);-+ const email =+ pdfDetails?.[0].Signers?.find((x) => x.objectId === signerObjectId)+ ?.Email || jsonSender?.email;+ const userId =+ pdfDetails?.[0].Signers?.find((x) => x.objectId === signerObjectId)+ ?.UserId?.objectId || jsonSender?.objectId;+ const params = {+ docId: pdfDetails?.[0].objectId,+ reason: reason,+ userId: userId+ };await axios- .put(- `${localStorage.getItem(- "baseUrl"- )}classes/contracts_Document/${documentId}`,- data,- {- headers: {- "Content-Type": "application/json",- "X-Parse-Application-Id": localStorage.getItem("parseAppId"),- "X-Parse-Session-Token": localStorage.getItem("accesstoken")- }+ .post(`${localStorage.getItem("baseUrl")}functions/declinedoc`, params, {+ headers: {+ "Content-Type": "application/json",+ "X-Parse-Application-Id": localStorage.getItem("parseAppId"),+ "X-Parse-Session-Token": localStorage.getItem("accesstoken")}- )+ }).then(async (result) => {const res = result.data;if (res) {@@ -1264,7 +1259,8 @@ function PdfRequestFiles(props) {email: x?.Email,phone: x?.Phone})),- declinedBy: jsonSender.email,+ declinedBy: email,+ declinedReason: reason,declinedAt: new Date(),createdAt: pdfDetails?.[0].createdAt}@@ -1715,11 +1711,7 @@ function PdfRequestFiles(props) {{/* this modal is used to show decline alert */}<PdfDeclineModalshow={isDecline.isDeclined}- headMsg={- pdfDetails[0]?.IsDeclined- ? t("document-declined")- : t("document-decline")- }+ headMsg={t("document-declined")}bodyMssg={isDecline.currnt === "Sure"? t("decline-alert-1")diff --git a/apps/OpenSign/src/primitives/GetReportDisplay.js b/apps/OpenSign/src/primitives/GetReportDisplay.jsindex ed5a69921..5f7dd97e1 100644--- a/apps/OpenSign/src/primitives/GetReportDisplay.js+++ b/apps/OpenSign/src/primitives/GetReportDisplay.js@@ -516,7 +516,6 @@ const ReportTable = (props) => {.then(async (result) => {const res = result.data;if (res) {- setReason("");setActLoader({});setIsAlert(true);setAlertMsg({@@ -528,7 +527,43 @@ const ReportTable = (props) => {(x) => x.objectId !== item.objectId);props.setList(upldatedList);+ const params = {+ event: "declined",+ body: {+ objectId: item.objectId,+ file: item?.SignedUrl || item?.URL,+ name: item?.Name,+ note: item?.Note || "",+ description: item?.Description || "",+ signers: item?.Signers?.map((x) => ({+ name: x?.Name,+ email: x?.Email,+ phone: x?.Phone+ })),+ declinedBy: jsonSender?.email,+ declinedReason: reason,+ declinedAt: new Date(),+ createdAt: item?.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);+ }}+ setReason("");}).catch((err) => {console.log("err", err);diff --git a/apps/OpenSign/src/primitives/PdfDeclineModal.js b/apps/OpenSign/src/primitives/PdfDeclineModal.jsindex 37c89cce5..cb42ef6a7 100644--- a/apps/OpenSign/src/primitives/PdfDeclineModal.js+++ b/apps/OpenSign/src/primitives/PdfDeclineModal.js@@ -41,8 +41,8 @@ function CustomModal(props) {className="op-btn op-btn-primary mr-2 px-6"type="button"onClick={() => {- setReason("");props.declineDoc(reason);+ setReason("");}}>{t("yes")}diff --git a/apps/OpenSignServer/cloud/main.js b/apps/OpenSignServer/cloud/main.jsindex bfabaf1bc..a87022e44 100644--- a/apps/OpenSignServer/cloud/main.js+++ b/apps/OpenSignServer/cloud/main.js@@ -67,6 +67,7 @@ import AllowedCredits from './parsefunction/AllowedCredits.js';import BuyCredits from './parsefunction/BuyCredits.js';import getContact from './parsefunction/getContact.js';import updateContactTour from './parsefunction/updateContactTour.js';+import declinedocument from './parsefunction/declinedocument.js';// This afterSave function triggers after an object is added or updated in the specified class, allowing for post-processing logic.Parse.Cloud.afterSave('contracts_Document', DocumentAftersave);@@ -146,3 +147,4 @@ Parse.Cloud.define('allowedcredits', AllowedCredits);Parse.Cloud.define('buycredits', BuyCredits);Parse.Cloud.define('getcontact', getContact);Parse.Cloud.define('updatecontacttour', updateContactTour);+Parse.Cloud.define('declinedoc', declinedocument);diff --git a/apps/OpenSignServer/cloud/parsefunction/declinedocument.js b/apps/OpenSignServer/cloud/parsefunction/declinedocument.jsnew file mode 100644index 000000000..07c2a90fd--- /dev/null+++ b/apps/OpenSignServer/cloud/parsefunction/declinedocument.js@@ -0,0 +1,38 @@+export default async function declinedocument(request) {+ const docId = request.params.docId;+ const reason = request.params?.reason || '';+ const declineBy = {+ __type: 'Pointer',+ className: '_User',+ objectId: request.params?.userId,+ };++ try {+ const docCls = new Parse.Query('contracts_Document');+ const updateDoc = await docCls.get(docId, { useMasterKey: true });+ if (updateDoc) {+ const isEnableOTP = updateDoc?.get('IsEnableOTP') || false;+ if (!isEnableOTP) {+ updateDoc.set('IsDeclined', true);+ updateDoc.set('DeclineReason', reason);+ updateDoc.set('DeclineBy', declineBy);+ await updateDoc.save(null, { useMasterKey: true });+ return 'document declined';+ } else {+ if (!request?.user) {+ throw new Parse.Error(Parse.Error.INVALID_SESSION_TOKEN, 'User is not authenticated.');+ }+ updateDoc.set('IsDeclined', true);+ updateDoc.set('DeclineReason', reason);+ updateDoc.set('DeclineBy', declineBy);+ await updateDoc.save(null, { useMasterKey: true });+ return 'document declined';+ }+ } else {+ throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Document not found.');+ }+ } catch (err) {+ console.log('err while decling doc', err);+ throw err;+ }+}