diff --git a/README.md b/README.md index 24e1046fc..ede88954f 100644 --- a/README.md +++ b/README.md @@ -136,7 +136,7 @@ We would like to thank all our contributors and users for their support and feed Vikram
Vikram

đź’» ugoconsonni
ugoconsonni

đź’» Daniel Mutwiri
Daniel Mutwiri

đź’» - Zathiel
Zathiel

đź’» + Zathiel
Zathiel

💻🛡️ diff --git a/apps/OpenSign/src/components/pdf/PdfHeader.js b/apps/OpenSign/src/components/pdf/PdfHeader.js index ad230f29d..419983798 100644 --- a/apps/OpenSign/src/components/pdf/PdfHeader.js +++ b/apps/OpenSign/src/components/pdf/PdfHeader.js @@ -1,15 +1,15 @@ import React, { useState } from "react"; import PrevNext from "./PrevNext"; -import printModule from "print-js"; -import { getBase64FromUrl } from "../../constant/Utils"; -import { saveAs } from "file-saver"; +import { + handleDownloadCertificate, + handleDownloadPdf, + handleToPrint +} from "../../constant/Utils"; import "../../styles/signature.css"; import * as DropdownMenu from "@radix-ui/react-dropdown-menu"; import { useNavigate } from "react-router-dom"; import { themeColor } from "../../constant/const"; -import axios from "axios"; import ModalUi from "../../primitives/ModalUi"; -import { appInfo } from "../../constant/appinfo"; function Header({ isPdfRequestFiles, @@ -59,130 +59,6 @@ function Header({ setIsDecline(currentDecline); }; - //function for print digital sign pdf - const handleToPrint = async (event) => { - event.preventDefault(); - setIsDownloading("pdf"); - 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"); - setIsDownloading(""); - } else { - printModule({ printable: pdf, type: "pdf", base64: true }); - setIsDownloading(""); - } - } catch (err) { - setIsDownloading(""); - console.log("err in getsignedurl", err); - alert("something went wrong, please try again later."); - } - }; - - //handle download signed pdf - const handleDownloadPdf = async () => { - setIsDownloading("pdf"); - 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`); - setIsDownloading(""); - } catch (err) { - console.log("err in getsignedurl", err); - setIsDownloading(""); - alert("something went wrong, please try again later."); - } - }; - - const sanitizeFileName = (pdfName) => { - // Replace spaces with underscore - return pdfName.replace(/ /g, "_"); - }; - - //handle download signed pdf - const handleDownloadCertificate = async () => { - 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 { - setIsDownloading("certificate"); - 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`); - setIsDownloading(""); - } else { - setIsDownloading("certificate"); - } - } - } catch (err) { - setIsDownloading(""); - console.log("err in download in certificate", err); - alert("something went wrong, please try again later."); - } - } - }; - return (
{isMobile && isShowHeader ? ( @@ -255,7 +131,9 @@ function Header({ > handleDownloadPdf()} + onClick={() => + handleDownloadPdf(pdfDetails, pdfUrl, setIsDownloading) + } >
handleDownloadCertificate()} + onClick={() => + handleDownloadCertificate( + pdfDetails, + setIsDownloading + ) + } >
+ handleToPrint(e, pdfUrl, setIsDownloading) + } >
handleDownloadPdf()} + onClick={() => + handleDownloadPdf( + pdfDetails, + pdfUrl, + setIsDownloading + ) + } > handleDownloadCertificate()} + onClick={() => + handleDownloadCertificate(pdfDetails, setIsDownloading) + } className="flex flex-row items-center shadow rounded-[3px] py-[3px] px-[11px] text-white font-[500] text-[13px] mr-[5px] bg-[#08bc66]" > handleToPrint(e, pdfUrl, setIsDownloading)} type="button" className="flex flex-row items-center shadow rounded-[3px] py-[3px] px-[11px] text-white font-[500] text-[13px] mr-[5px] bg-[#188ae2]" > @@ -505,7 +398,9 @@ function Header({ + {isCompleted?.message ? ( +

{isCompleted?.message}

+ ) : ( +
+ + Congratulations! 🎉 This document has been + successfully signed by all participants! + +
+ )} + {!isCompleted?.message && ( +
+ + + +
+ )} +
+ + {isDownloading === "pdf" && ( +
+
+
+ )} + setIsDownloading("")} + > +
+ {isDownloading === "certificate"}{" "} +

+ Your completion certificate is being generated. Please + wait momentarily. +

+

+ If the download doesn't start shortly, click the + button again. +

- {/* this component is used for signature pad modal */} { return ( @@ -18,11 +18,11 @@ const ModalUi = ({ {isOpen && (
{showHeader && (