From 69308e22d82628f9410906c25c83122ca39d28f5 Mon Sep 17 00:00:00 2001 From: RaktimaNXG Date: Thu, 8 Aug 2024 15:06:43 +0530 Subject: [PATCH] fix: error in auto-sign feature unexpected issue encountered - something went wrong --- .../src/components/pdf/EmailComponent.js | 57 +- apps/OpenSign/src/constant/Utils.js | 49 +- apps/OpenSign/src/pages/PdfRequestFiles.js | 541 +++++++++--------- apps/OpenSign/src/pages/SignyourselfPdf.js | 231 ++++---- 4 files changed, 436 insertions(+), 442 deletions(-) diff --git a/apps/OpenSign/src/components/pdf/EmailComponent.js b/apps/OpenSign/src/components/pdf/EmailComponent.js index 2ee4a9a7e..f799feb27 100644 --- a/apps/OpenSign/src/components/pdf/EmailComponent.js +++ b/apps/OpenSign/src/components/pdf/EmailComponent.js @@ -1,9 +1,7 @@ import React, { useState } from "react"; -import { saveAs } from "file-saver"; import axios from "axios"; -import { getBase64FromUrl } from "../../constant/Utils"; +import { handleDownloadPdf, handleToPrint } from "../../constant/Utils"; import { themeColor, emailRegex } from "../../constant/const"; -import printModule from "print-js"; import Loader from "../../primitives/Loader"; import ModalUi from "../../primitives/ModalUi"; @@ -12,7 +10,7 @@ function EmailComponent({ pdfUrl, setIsEmail, setSuccessEmail, - pdfName, + pdfDetails, sender, setIsAlert, extUserId, @@ -22,8 +20,11 @@ function EmailComponent({ const [emailValue, setEmailValue] = useState(""); const [isLoading, setIsLoading] = useState(false); const [emailErr, setEmailErr] = useState(false); + const [isDownloading, setIsDownloading] = useState(""); + const isAndroid = /Android/i.test(navigator.userAgent); //function for send email const sendEmail = async () => { + const pdfName = pdfDetails[0]?.Name; setIsLoading(true); let sendMail; @@ -138,43 +139,6 @@ function EmailComponent({ } } }; - - // function for print signed pdf - const handleToPrint = async (event) => { - event.preventDefault(); - - const pdf = await getBase64FromUrl(pdfUrl); - 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 }); - } - }; - - //handle download signed pdf - const handleDownloadPdf = () => { - saveAs(pdfUrl, `${sanitizeFileName(pdfName)}_signed_by_OpenSign™.pdf`); - }; - - const sanitizeFileName = (pdfName) => { - // Replace spaces with underscore - return pdfName.replace(/ /g, "_"); - }; - - const isAndroid = /Android/i.test(navigator.userAgent); - return (
{/* isEmail */} @@ -188,6 +152,11 @@ function EmailComponent({
)} + {isDownloading === "pdf" && ( +
+ +
+ )}
Successfully signed! @@ -195,7 +164,7 @@ function EmailComponent({
{!isAndroid && (