From 9fa97f27f07147a040cd43a80d651c832b2bc118 Mon Sep 17 00:00:00 2001 From: RaktimaNXG Date: Thu, 8 Aug 2024 15:55:11 +0530 Subject: [PATCH] fix: error in auto-sign feature unexpected issue encountered - something went wrong --- .../src/components/pdf/EmailComponent.js | 60 +- apps/OpenSign/src/constant/Utils.js | 49 +- apps/OpenSign/src/pages/PdfRequestFiles.js | 539 +++++++++--------- apps/OpenSign/src/pages/SignyourselfPdf.js | 229 ++++---- 4 files changed, 437 insertions(+), 440 deletions(-) diff --git a/apps/OpenSign/src/components/pdf/EmailComponent.js b/apps/OpenSign/src/components/pdf/EmailComponent.js index a41f82cbb..77ee86b9c 100644 --- a/apps/OpenSign/src/components/pdf/EmailComponent.js +++ b/apps/OpenSign/src/components/pdf/EmailComponent.js @@ -1,7 +1,11 @@ import React, { useState } from "react"; import { saveAs } from "file-saver"; import axios from "axios"; -import { getBase64FromUrl } from "../../constant/Utils"; +import { + getBase64FromUrl, + handleDownloadPdf, + handleToPrint +} from "../../constant/Utils"; import { themeColor, emailRegex } from "../../constant/const"; import printModule from "print-js"; import Loader from "../../primitives/Loader"; @@ -13,7 +17,7 @@ function EmailComponent({ pdfUrl, setIsEmail, setSuccessEmail, - pdfName, + pdfDetails, sender, setIsAlert, extUserId, @@ -24,10 +28,12 @@ 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; for (let i = 0; i < emailList.length; i++) { try { @@ -140,43 +146,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 */} @@ -190,6 +159,11 @@ function EmailComponent({
)} + {isDownloading === "pdf" && ( +
+ +
+ )}
{t("successfully-signed")} @@ -197,7 +171,7 @@ function EmailComponent({
{!isAndroid && (