From 4da307315ced4ebfe3c95f8f6b422de4d9ea1f4c Mon Sep 17 00:00:00 2001 From: prafull-opensignlabs Date: Thu, 16 May 2024 19:34:28 +0530 Subject: [PATCH] feat: add resend mail functionality for inprogress document --- apps/OpenSign/src/json/ReportJson.js | 8 + .../src/primitives/GetReportDisplay.js | 279 +++++++++++++++++- apps/OpenSign/src/primitives/ModalUi.js | 2 +- .../cloud/parsefunction/reportsJson.js | 3 + 4 files changed, 287 insertions(+), 5 deletions(-) diff --git a/apps/OpenSign/src/json/ReportJson.js b/apps/OpenSign/src/json/ReportJson.js index 35553130f..87627b968 100644 --- a/apps/OpenSign/src/json/ReportJson.js +++ b/apps/OpenSign/src/json/ReportJson.js @@ -85,6 +85,14 @@ export default function reportJson(id) { btnIcon: "fa-solid fa-ellipsis-vertical fa-lg", action: "option", subaction: [ + { + btnId: "1630", + btnLabel: "Resend", + hoverLabel: "Resend", + btnIcon: "fa-solid fa-envelope", + redirectUrl: "", + action: "resend" + }, { btnId: "1688", btnLabel: "Revoke", diff --git a/apps/OpenSign/src/primitives/GetReportDisplay.js b/apps/OpenSign/src/primitives/GetReportDisplay.js index 927a0e14f..e5e603d74 100644 --- a/apps/OpenSign/src/primitives/GetReportDisplay.js +++ b/apps/OpenSign/src/primitives/GetReportDisplay.js @@ -11,6 +11,13 @@ import { RWebShare } from "react-web-share"; import Tour from "reactour"; import Parse from "parse"; import { saveAs } from "file-saver"; +import { replaceMailVaribles } from "../constant/Utils"; +import EditorToolbar, { + module1, + formats +} from "../components/pdf/EditorToolbar"; +import ReactQuill from "react-quill"; +import "react-quill/dist/quill.snow.css"; const ReportTable = (props) => { const navigate = useNavigate(); @@ -28,6 +35,10 @@ const ReportTable = (props) => { const [alertMsg, setAlertMsg] = useState({ type: "success", message: "" }); const [isTour, setIsTour] = useState(false); const [tourStatusArr, setTourStatusArr] = useState([]); + const [isResendMail, setIsResendMail] = useState({}); + const [mail, setMail] = useState({ subject: "", body: "" }); + const [userDetails, setUserDetails] = useState({}); + const [isNextStep, setIsNextStep] = useState({}); const startIndex = (currentPage - 1) * props.docPerPage; const { isMoreDocs, setIsNextRecord } = props; // For loop is used to calculate page numbers visible below table @@ -89,8 +100,6 @@ const ReportTable = (props) => { } } ); - - // console.log("templateDeatils.data ", templateDeatils.data); const templateData = templateDeatils.data && templateDeatils.data.result; if (!templateData.error) { @@ -149,7 +158,6 @@ const ReportTable = (props) => { } ); - // console.log("Res ", res.data); if (res.data && res.data.objectId) { setActLoader({}); setIsAlert(true); @@ -210,6 +218,8 @@ const ReportTable = (props) => { setIsRevoke({ [item.objectId]: true }); } else if (act.action === "option") { setIsOption({ [item.objectId]: !isOption[item.objectId] }); + } else if (act.action === "resend") { + setIsResendMail({ [item.objectId]: true }); } }; // Get current list @@ -254,7 +264,6 @@ const ReportTable = (props) => { "X-Parse-Session-Token": localStorage.getItem("accesstoken") } }); - // console.log("Res ", res.data); if (res.data && res.data.updatedAt) { setActLoader({}); setIsAlert(true); @@ -437,6 +446,161 @@ const ReportTable = (props) => { } } }; + + // `handleSubjectChange` is used to add or change subject of resend mail + const handleSubjectChange = (subject, doc) => { + const encodeBase64 = btoa( + `${doc.objectId}/${userDetails.Email}/${userDetails.objectId}` + ); + const expireDate = doc.ExpiryDate.iso; + const newDate = new Date(expireDate); + const localExpireDate = newDate.toLocaleDateString("en-US", { + day: "numeric", + month: "long", + year: "numeric" + }); + const signPdf = `${window.location.origin}/login/${encodeBase64}`; + const variables = { + document_title: doc.Name, + sender_name: doc.ExtUserPtr.Name, + sender_mail: doc.ExtUserPtr.Email, + sender_phone: doc.ExtUserPtr.Phone, + receiver_name: userDetails.Name, + receiver_email: userDetails.Email, + receiver_phone: userDetails.Phone, + expiry_date: localExpireDate, + company_name: doc.ExtUserPtr.Company, + signing_url: `Sign here` + }; + const res = replaceMailVaribles(subject, "", variables); + + setMail((prev) => ({ ...prev, subject: res.subject })); + }; + // `handlebodyChange` is used to add or change body of resend mail + const handlebodyChange = (body, doc) => { + const encodeBase64 = btoa( + `${doc.objectId}/${userDetails.Email}/${userDetails.objectId}` + ); + const expireDate = doc.ExpiryDate.iso; + const newDate = new Date(expireDate); + const localExpireDate = newDate.toLocaleDateString("en-US", { + day: "numeric", + month: "long", + year: "numeric" + }); + const signPdf = `${window.location.origin}/login/${encodeBase64}`; + const variables = { + document_title: doc.Name, + sender_name: doc.ExtUserPtr.Name, + sender_mail: doc.ExtUserPtr.Email, + sender_phone: doc.ExtUserPtr.Phone, + receiver_name: userDetails.Name, + receiver_email: userDetails.Email, + receiver_phone: userDetails.Phone, + expiry_date: localExpireDate, + company_name: doc.ExtUserPtr.Company, + signing_url: `Sign here` + }; + const res = replaceMailVaribles("", body, variables); + + if (body) { + setMail((prev) => ({ ...prev, body: res.body })); + } + }; + // `handleNextBtn` is used to open edit mail template screen in resend mail modal + // as well as replace variable with original one + const handleNextBtn = (user, doc) => { + setUserDetails(user); + const encodeBase64 = btoa(`${doc.objectId}/${user.Email}/${user.objectId}`); + const expireDate = doc.ExpiryDate.iso; + const newDate = new Date(expireDate); + const localExpireDate = newDate.toLocaleDateString("en-US", { + day: "numeric", + month: "long", + year: "numeric" + }); + const signPdf = `${window.location.origin}/login/${encodeBase64}`; + const variables = { + document_title: doc.Name, + sender_name: doc.ExtUserPtr.Name, + sender_mail: doc.ExtUserPtr.Email, + sender_phone: doc.ExtUserPtr.Phone, + receiver_name: user.Name, + receiver_email: user.Email, + receiver_phone: user.Phone, + expiry_date: localExpireDate, + company_name: doc.ExtUserPtr.Company, + signing_url: `Sign here` + }; + + const subject = + doc?.RequestSubject || + "{{sender_name}} has requested you to sign {{document_title}}"; + const body = + doc?.RequestBody || + "

Hi {{receiver_name}},


We hope this email finds you well. {{sender_name}} has requested you to review and sign {{document_title}}.

Your signature is crucial to proceed with the next steps as it signifies your agreement and authorization.


{{signing_url}}


If you have any questions or need further clarification regarding the document or the signing process, please contact the sender.


Thanks

Team OpenSign™


"; + const res = replaceMailVaribles(subject, body, variables); + setMail((prev) => ({ ...prev, subject: res.subject, body: res.body })); + setIsNextStep({ [user.objectId]: true }); + }; + const handleResendMail = async (e, doc, user) => { + e.preventDefault(); + setActLoader({ [user.objectId]: true }); + setIsAlert(true); + const url = `${localStorage.getItem("baseUrl")}functions/sendmailv3`; + const headers = { + "Content-Type": "application/json", + "X-Parse-Application-Id": localStorage.getItem("parseAppId"), + sessionToken: localStorage.getItem("accesstoken") + }; + let params = { + mailProvider: doc?.ExtUserPtr?.active_mail_adapter, + extUserId: doc?.ExtUserPtr?.objectId, + recipient: userDetails.Email, + subject: mail.subject, + from: doc?.ExtUserPtr?.Email, + html: mail.body + }; + try { + const res = await axios.post(url, params, { headers: headers }); + if (res) { + setAlertMsg({ type: "success", message: "Mail sent successfully." }); + } + } catch (err) { + console.log("err in sendmail", err); + setAlertMsg({ + type: "danger", + message: "Something went wrong, please try again later!" + }); + } finally { + setTimeout(() => setIsAlert(false), 1500); + setIsNextStep({}); + setUserDetails({}); + setActLoader({}); + } + }; + const fetchUserStatus = (user, doc) => { + const audit = doc.AuditTrail.find( + (x) => x.UserPtr.objectId === user.objectId + ); + return ( +
+
+ {audit?.Activity ? audit?.Activity : "Awaited"} +
+ + +
+ ); + }; return (
{Object.keys(actLoader)?.length > 0 && ( @@ -753,6 +917,113 @@ const ReportTable = (props) => {
)} + {isResendMail[item.objectId] && ( + { + setIsResendMail({}); + setIsNextStep({}); + setUserDetails({}); + }} + > +
+ {item?.Signers.map((user) => ( + + {isNextStep[user.objectId] && ( +
+ {actLoader[user.objectId] && ( +
+
+
+ )} + +
+ handleResendMail(e, item, user) + } + className="w-full flex flex-col gap-2 p-3 text-black" + > +
+ + + handleSubjectChange( + e.target.value, + item + ) + } + required + /> +
+
+ + + + handlebodyChange(value, item) + } + /> +
+ +
+
+ )} + {Object?.keys(isNextStep) <= 0 && ( +
+
+ {user.Name} +
+ <>{fetchUserStatus(user, item)} +
+ )} +
+ ))} +
+
+ )} ) diff --git a/apps/OpenSign/src/primitives/ModalUi.js b/apps/OpenSign/src/primitives/ModalUi.js index 01b59d94b..dcc726f18 100644 --- a/apps/OpenSign/src/primitives/ModalUi.js +++ b/apps/OpenSign/src/primitives/ModalUi.js @@ -16,7 +16,7 @@ const ModalUi = ({ return ( <> {isOpen && ( -
+