Skip to content

🔥 The free & Open Source DocuSign alternative

Merge branch 'staging' into raktima-opensignlabs-patch-8

Raktimac40a92338807
diff --cc apps/OpenSign/src/constant/Utils.js
index dfb94fd7c,9d310dd82..7cb9be16b
--- a/apps/OpenSign/src/constant/Utils.js
+++ b/apps/OpenSign/src/constant/Utils.js
@@@ -2032,121 -2030,24 +2033,140 @@@ export const handleSendOTP = async (ema
alert(error.message);
}
};
-
+//handle download signed pdf
+export const handleDownloadPdf = async (pdfDetails, pdfUrl) => {
+ const pdfName = pdfDetails[0] && pdfDetails[0].Name;
+ try {
+ // const url = await Parse.Cloud.run("getsignedurl", { url: pdfUrl });
+ const axiosRes = await axios.post(
+ `${appInfo.baseUrl}/functions/getsignedurl`,
+ { url: pdfUrl },
+ {
+ headers: {
+ "content-type": "Application/json",
+ "X-Parse-Application-Id": appInfo.appId,
+ "X-Parse-Session-Token": localStorage.getItem("accesstoken")
+ }
+ }
+ );
+ const url = axiosRes.data.result;
+ saveAs(url, `${sanitizeFileName(pdfName)}_signed_by_OpenSignâ„¢.pdf`);
+ } catch (err) {
+ console.log("err in getsignedurl", err);
+ alert("something went wrong, please try again later.");
+ }
+};
+
+export const sanitizeFileName = (pdfName) => {
+ // Replace spaces with underscore
+ return pdfName.replace(/ /g, "_");
+};
+//function for print digital sign pdf
+export const handleToPrint = async (event, pdfUrl) => {
+ event.preventDefault();
-export async function findContact(value) {
+ try {
+ // const url = await Parse.Cloud.run("getsignedurl", { url: pdfUrl });
+ const axiosRes = await axios.post(
+ `${appInfo.baseUrl}/functions/getsignedurl`,
+ { url: pdfUrl },
+ {
+ headers: {
+ "content-type": "Application/json",
+ "X-Parse-Application-Id": appInfo.appId,
+ "X-Parse-Session-Token": localStorage.getItem("accesstoken")
+ }
+ }
+ );
+ const url = axiosRes.data.result;
+ const pdf = await getBase64FromUrl(url);
+ 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 });
+ }
+ } catch (err) {
+ console.log("err in getsignedurl", err);
+ alert("something went wrong, please try again later.");
+ }
+};
+
+//handle download signed pdf
+export const handleDownloadCertificate = async (
+ pdfDetails,
+ setIsCertificate
+) => {
+ if (pdfDetails?.length > 0 && pdfDetails[0]?.CertificateUrl) {
+ try {
+ await fetch(pdfDetails[0] && pdfDetails[0]?.CertificateUrl);
+ const certificateUrl = pdfDetails[0] && pdfDetails[0]?.CertificateUrl;
+ saveAs(certificateUrl, `Certificate_signed_by_OpenSignâ„¢.pdf`);
+ } catch (err) {
+ console.log("err in download in certificate", err);
+ }
+ } else {
+ setIsCertificate(true);
+ try {
+ const data = {
+ docId: pdfDetails[0]?.objectId
+ };
+ const docDetails = await axios.post(
+ `${localStorage.getItem("baseUrl")}functions/getDocument`,
+ data,
+ {
+ headers: {
+ "Content-Type": "application/json",
+ "X-Parse-Application-Id": localStorage.getItem("parseAppId"),
+ sessionToken: localStorage.getItem("accesstoken")
+ }
+ }
+ );
+ if (docDetails.data && docDetails.data.result) {
+ const doc = docDetails.data.result;
+ if (doc?.CertificateUrl) {
+ await fetch(doc?.CertificateUrl);
+ const certificateUrl = doc?.CertificateUrl;
+ saveAs(certificateUrl, `Certificate_signed_by_OpenSignâ„¢.pdf`);
+ setIsCertificate(false);
+ } else {
+ setIsCertificate(true);
+ }
+ }
+ } catch (err) {
+ console.log("err in download in certificate", err);
+ alert("something went wrong, please try again later.");
+ }
+ }
+};
++ export async function findContact(value) {
+ try {
+ const currentUser = Parse.User.current();
+ const contactbook = new Parse.Query("contracts_Contactbook");
+ contactbook.equalTo(
+ "CreatedBy",
+ Parse.User.createWithoutData(currentUser.id)
+ );
+ contactbook.notEqualTo("IsDeleted", true);
+ contactbook.matches("Email", new RegExp(value, "i"));
+
+ const contactRes = await contactbook.find();
+ if (contactRes) {
+ const res = JSON.parse(JSON.stringify(contactRes));
+ return res;
+ }
+ } catch (error) {
+ console.error("Error fetching suggestions:", error);
+ }
+ }