import React from "react"; import PrevNext from "./prevNext"; import { PDFDownloadLink } from "@react-pdf/renderer"; import Certificate from "../Certificate/Certificate"; import printModule from "print-js"; import { getBase64FromUrl } from "../../utils/Utils"; import { saveAs } from "file-saver"; import "../../css/signature.css"; import * as DropdownMenu from "@radix-ui/react-dropdown-menu"; import { useNavigate } from "react-router-dom"; import { themeColor } from "../../utils/ThemeColor/backColor"; function Header({ isPdfRequestFiles, isPlaceholder, recipient, setIsDecline, pageNumber, isAlreadySign, allPages, changePage, pdfUrl, documentStatus, embedImages, pdfDetails, signerPos, signersdata, isMailSend, alertSendEmail, isCompleted, isShowHeader, decline, currentSigner, dataTut4, alreadySign, isSignYourself, setIsEmail }) { const isMobile = window.innerWidth < 767; const navigate = useNavigate(); const isGuestSigner = localStorage.getItem("isGuestSigner"); //for go to previous page function previousPage() { changePage(-1); } //for go to next page function nextPage() { changePage(1); } //function for show decline alert const handleDeclinePdfAlert = async () => { const currentDecline = { currnt: "Sure", isDeclined: true }; setIsDecline(currentDecline); }; //function for print digital sign 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 = () => { const pdfName = pdfDetails[0] && pdfDetails[0].Name; saveAs(pdfUrl, `${sanitizeFileName(pdfName)}_signed_by_OpenSign™.pdf`); }; const sanitizeFileName = (pdfName) => { // Replace spaces with underscore return pdfName.replace(/ /g, "_"); }; //certificate generate and download component in mobile view const CertificateDropDown = () => { //after generate download certifcate pdf const handleDownload = (pdfBlob, fileName) => { if (pdfBlob) { const url = window.URL.createObjectURL(pdfBlob); // Create a temporary anchor element const link = document.createElement("a"); link.href = url; link.download = fileName; // Append the anchor to the body document.body.appendChild(link); // Programmatically click the anchor to trigger the download link.click(); // Remove the anchor from the body document.body.removeChild(link); // Release the object URL to free up resources window.URL.revokeObjectURL(url); } }; return ( e.preventDefault()} style={{ textDecoration: "none", zIndex: "35" }} document={} > {({ blob, url, loading, error }) => ( <> {loading ? (
Certificate
) : (
handleDownload( blob, `completion certificate-${ pdfDetails[0] && pdfDetails[0].Name }.pdf` ) } > Certificate
)} )}
); }; const CertificateComponent = () => { return ( } fileName={`completion certificate-${ pdfDetails[0] && pdfDetails[0].Name }.pdf`} > {({ blob, url, loading, error }) => loading ? ( ) : ( ) } ); }; return (
{isMobile && isShowHeader ? ( ) : (
{recipient ? ( pdfUrl || isAlreadySign.mssg ? (
{pdfDetails[0] && pdfDetails.length > 0 && ( )}
) : (
) ) : isPlaceholder ? ( <> {!isMailSend && signersdata.Signers && signersdata.Signers.length !== signerPos.length && (
{signerPos.length === 0 ? ( Add all {signersdata.Signers.length - signerPos.length}{" "} recipients signature ) : ( Add {signersdata.Signers.length - signerPos.length} more recipients signature )}
)}
) : isPdfRequestFiles ? ( alreadySign ? (
{isCompleted.isCertificate && }
) : (
{currentSigner && ( <> )}
) ) : pdfUrl || (documentStatus && documentStatus.isCompleted) ? (
) : (
)}
)}
); } export default Header;