Skip to content

Commit b98040f

Browse files
fix: document decline event not trigger on revoke
1 parent 07d5f39 commit b98040f

File tree

5 files changed

+97
-30
lines changed

5 files changed

+97
-30
lines changed

apps/OpenSign/src/pages/PdfRequestFiles.js

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,31 +1220,26 @@ function PdfRequestFiles(props) {
12201220
);
12211221
const jsonSender = JSON.parse(senderUser);
12221222
setIsDecline({ isDeclined: false });
1223-
const data = {
1224-
IsDeclined: true,
1225-
DeclineReason: reason,
1226-
DeclineBy: {
1227-
__type: "Pointer",
1228-
className: "_User",
1229-
objectId: jsonSender?.objectId
1230-
}
1231-
};
12321223
setIsUiLoading(true);
1233-
1224+
const email =
1225+
pdfDetails?.[0].Signers?.find((x) => x.objectId === signerObjectId)
1226+
?.Email || jsonSender?.email;
1227+
const userId =
1228+
pdfDetails?.[0].Signers?.find((x) => x.objectId === signerObjectId)
1229+
?.UserId?.objectId || jsonSender?.objectId;
1230+
const params = {
1231+
docId: pdfDetails?.[0].objectId,
1232+
reason: reason,
1233+
userId: userId
1234+
};
12341235
await axios
1235-
.put(
1236-
`${localStorage.getItem(
1237-
"baseUrl"
1238-
)}classes/contracts_Document/${documentId}`,
1239-
data,
1240-
{
1241-
headers: {
1242-
"Content-Type": "application/json",
1243-
"X-Parse-Application-Id": localStorage.getItem("parseAppId"),
1244-
"X-Parse-Session-Token": localStorage.getItem("accesstoken")
1245-
}
1236+
.post(`${localStorage.getItem("baseUrl")}functions/declinedoc`, params, {
1237+
headers: {
1238+
"Content-Type": "application/json",
1239+
"X-Parse-Application-Id": localStorage.getItem("parseAppId"),
1240+
"X-Parse-Session-Token": localStorage.getItem("accesstoken")
12461241
}
1247-
)
1242+
})
12481243
.then(async (result) => {
12491244
const res = result.data;
12501245
if (res) {
@@ -1264,7 +1259,8 @@ function PdfRequestFiles(props) {
12641259
email: x?.Email,
12651260
phone: x?.Phone
12661261
})),
1267-
declinedBy: jsonSender.email,
1262+
declinedBy: email,
1263+
declinedReason: reason,
12681264
declinedAt: new Date(),
12691265
createdAt: pdfDetails?.[0].createdAt
12701266
}
@@ -1715,11 +1711,7 @@ function PdfRequestFiles(props) {
17151711
{/* this modal is used to show decline alert */}
17161712
<PdfDeclineModal
17171713
show={isDecline.isDeclined}
1718-
headMsg={
1719-
pdfDetails[0]?.IsDeclined
1720-
? t("document-declined")
1721-
: t("document-decline")
1722-
}
1714+
headMsg={t("document-declined")}
17231715
bodyMssg={
17241716
isDecline.currnt === "Sure"
17251717
? t("decline-alert-1")

apps/OpenSign/src/primitives/GetReportDisplay.js

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,6 @@ const ReportTable = (props) => {
516516
.then(async (result) => {
517517
const res = result.data;
518518
if (res) {
519-
setReason("");
520519
setActLoader({});
521520
setIsAlert(true);
522521
setAlertMsg({
@@ -528,7 +527,43 @@ const ReportTable = (props) => {
528527
(x) => x.objectId !== item.objectId
529528
);
530529
props.setList(upldatedList);
530+
const params = {
531+
event: "declined",
532+
body: {
533+
objectId: item.objectId,
534+
file: item?.SignedUrl || item?.URL,
535+
name: item?.Name,
536+
note: item?.Note || "",
537+
description: item?.Description || "",
538+
signers: item?.Signers?.map((x) => ({
539+
name: x?.Name,
540+
email: x?.Email,
541+
phone: x?.Phone
542+
})),
543+
declinedBy: jsonSender?.email,
544+
declinedReason: reason,
545+
declinedAt: new Date(),
546+
createdAt: item?.createdAt
547+
}
548+
};
549+
550+
try {
551+
await axios.post(
552+
`${localStorage.getItem("baseUrl")}functions/callwebhook`,
553+
params,
554+
{
555+
headers: {
556+
"Content-Type": "application/json",
557+
"X-Parse-Application-Id": localStorage.getItem("parseAppId"),
558+
sessiontoken: localStorage.getItem("accesstoken")
559+
}
560+
}
561+
);
562+
} catch (err) {
563+
console.log("Err ", err);
564+
}
531565
}
566+
setReason("");
532567
})
533568
.catch((err) => {
534569
console.log("err", err);

apps/OpenSign/src/primitives/PdfDeclineModal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ function CustomModal(props) {
4141
className="op-btn op-btn-primary mr-2 px-6"
4242
type="button"
4343
onClick={() => {
44-
setReason("");
4544
props.declineDoc(reason);
45+
setReason("");
4646
}}
4747
>
4848
{t("yes")}

apps/OpenSignServer/cloud/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ import AllowedCredits from './parsefunction/AllowedCredits.js';
6767
import BuyCredits from './parsefunction/BuyCredits.js';
6868
import getContact from './parsefunction/getContact.js';
6969
import updateContactTour from './parsefunction/updateContactTour.js';
70+
import declinedocument from './parsefunction/declinedocument.js';
7071

7172
// This afterSave function triggers after an object is added or updated in the specified class, allowing for post-processing logic.
7273
Parse.Cloud.afterSave('contracts_Document', DocumentAftersave);
@@ -146,3 +147,4 @@ Parse.Cloud.define('allowedcredits', AllowedCredits);
146147
Parse.Cloud.define('buycredits', BuyCredits);
147148
Parse.Cloud.define('getcontact', getContact);
148149
Parse.Cloud.define('updatecontacttour', updateContactTour);
150+
Parse.Cloud.define('declinedoc', declinedocument);
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
export default async function declinedocument(request) {
2+
const docId = request.params.docId;
3+
const reason = request.params?.reason || '';
4+
const declineBy = {
5+
__type: 'Pointer',
6+
className: '_User',
7+
objectId: request.params?.userId,
8+
};
9+
10+
try {
11+
const docCls = new Parse.Query('contracts_Document');
12+
const updateDoc = await docCls.get(docId, { useMasterKey: true });
13+
if (updateDoc) {
14+
const isEnableOTP = updateDoc?.get('IsEnableOTP') || false;
15+
if (!isEnableOTP) {
16+
updateDoc.set('IsDeclined', true);
17+
updateDoc.set('DeclineReason', reason);
18+
updateDoc.set('DeclineBy', declineBy);
19+
await updateDoc.save(null, { useMasterKey: true });
20+
return 'document declined';
21+
} else {
22+
if (!request?.user) {
23+
throw new Parse.Error(Parse.Error.INVALID_SESSION_TOKEN, 'User is not authenticated.');
24+
}
25+
updateDoc.set('IsDeclined', true);
26+
updateDoc.set('DeclineReason', reason);
27+
updateDoc.set('DeclineBy', declineBy);
28+
await updateDoc.save(null, { useMasterKey: true });
29+
return 'document declined';
30+
}
31+
} else {
32+
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Document not found.');
33+
}
34+
} catch (err) {
35+
console.log('err while decling doc', err);
36+
throw err;
37+
}
38+
}

0 commit comments

Comments
 (0)