import React from "react"; import RSC from "react-scrollbars-custom"; import Toast from "react-bootstrap/Toast"; import { Rnd } from "react-rnd"; import { themeColor } from "../../utils/ThemeColor/backColor"; import { Document, Page, pdfjs } from "react-pdf"; pdfjs.GlobalWorkerOptions.workerSrc = `//cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjs.version}/pdf.worker.js`; function RenderPdf({ pageNumber, pdfOriginalWidth, pdfNewWidth, drop, signerPos, successEmail, nodeRef, handleTabDrag, handleStop, handleImageResize, isDragging, setIsSignPad, setIsStamp, handleDeleteSign, setSignKey, pdfDetails, xyPostion, pdfRef, pdfUrl, numPages, pageDetails, recipient, isAlreadySign, pdfRequest, setCurrentSigner, signerObjectId, signedSigners, setPdfLoadFail, placeholder, pdfLoadFail }) { const isMobile = window.innerWidth < 767; const newWidth = window.innerWidth; const scale = isMobile ? pdfOriginalWidth / newWidth : 1; //function for render placeholder block over pdf document const checkSignedSignes = (data) => { const checkSign = signedSigners.filter( (sign) => sign.objectId === data.signerObjId ); if (data.signerObjId === signerObjectId) { setCurrentSigner(true); } const xPos = (pos) => { //checking both condition mobile and desktop view if (isMobile) { //if pos.isMobile false -- placeholder saved from desktop view then handle position in mobile view divided by scale if (!pos.isMobile) { return pos.xPosition / scale; } //pos.isMobile true -- placeholder save from mobile view(small device) handle position in mobile view(small screen) view divided by scale else { return pos.xPosition * (pos.scale / scale); } } else { //else if pos.isMobile true -- placeholder saved from mobile or tablet view then handle position in desktop view divide by scale if (pos.isMobile) { return pos.scale && pos.xPosition * pos.scale + 50; } //else placeholder save from desktop(bigscreen) and show in desktop(bigscreen) else { return pos.xPosition; } } }; const yPos = (pos) => { //checking both condition mobile and desktop view if (isMobile) { //if pos.isMobile false -- placeholder saved from desktop view then handle position in mobile view divided by scale if (!pos.isMobile) { return pos.yPosition / scale; } //pos.isMobile true -- placeholder save from mobile view(small device) handle position in mobile view(small screen) view divided by scale else { return pos.yPosition * (pos.scale / scale); } } else { //else if pos.isMobile true -- placeholder saved from mobile or tablet view then handle position in desktop view divide by scale if (pos.isMobile) { return pos.scale && pos.yPosition * pos.scale + 50; } //else placeholder save from desktop(bigscreen) and show in desktop(bigscreen) else { return pos.yPosition; } } }; return ( checkSign.length === 0 && data.placeHolder.map((placeData, key) => { return ( {placeData.pageNumber === pageNumber && placeData.pos.map((pos, index) => { return pos && pos.SignUrl ? ( { setIsSignPad(true); setSignKey(pos.key); }} >
no img { setIsSignPad(true); setSignKey(pos.key); }} src={pos.SignUrl} style={{ width: "100%", height: "100%", objectFit: "contain" }} />
) : ( { if (data.signerObjId === signerObjectId) { setIsSignPad(true); setSignKey(pos.key); setIsStamp(pos.isStamp); } }} style={{ padding: "0px", cursor: "all-scroll", zIndex: 1, position: "absolute", borderStyle: "dashed", width: "200px", height: "30px", borderColor: themeColor(), background: data.blockColor, textAlign: "center", justifyContent: "center", borderWidth: "0.2px" }} default={{ x: xPos(pos), y: yPos(pos) }} size={{ width: pos.Width ? pos.Width : 150, height: pos.Height ? pos.Height : 60 }} lockAspectRatio={pos.Width ? pos.Width / pos.Height : 2.5} >
{pos.isStamp ? "stamp" : "signature"}
); })}
); }) ); }; return ( <> {isMobile && scale ? (
Email sent successful!
{pdfLoadFail.status && (recipient ? !pdfUrl && !isAlreadySign.mssg && xyPostion.length > 0 && xyPostion.map((data, ind) => { return ( {data.pageNumber === pageNumber && data.pos.map((pos) => { return pos && pos.SignUrl ? ( { setIsSignPad(true); setSignKey(pos.key); }} >
no img { setIsSignPad(true); setSignKey(pos.key); }} src={pos.SignUrl} style={{ width: "100%", height: "100%", objectFit: "contain" }} />
) : ( { setIsSignPad(true); setSignKey(pos.key); setIsStamp(pos.isStamp); }} >
{pos.isStamp ? "stamp" : "signature"}
); })}
); }) : pdfRequest ? signerPos.map((data, key) => { return ( {checkSignedSignes(data)} ); }) : placeholder ? signerPos.map((data, ind) => { return ( {data.placeHolder.map((placeData, index) => { return ( {placeData.pageNumber === pageNumber && placeData.pos.map((pos) => { return ( handleTabDrag(pos.key, data.signerObjId) } size={{ width: pos.Width ? pos.Width : 150, height: pos.Height ? pos.Height : 60 }} lockAspectRatio={ pos.Width ? pos.Width / pos.Height : 2.5 } resizeHandleStyles={{ bottom: { display: "none" }, right: { display: "none" }, bottomRight: { display: "block" } }} onDragStop={(event, dragElement) => handleStop( event, dragElement, data.signerObjId, pos.key ) } default={{ x: pos.xPosition, y: pos.yPosition }} onResize={( e, direction, ref, delta, position ) => { handleImageResize( ref, pos.key, data.signerObjId, position ); }} >
{ e.stopPropagation(); handleDeleteSign( pos.key, data.signerObjId ); }} style={{ position: "absolute", right: 0, display: "inline-block", background: themeColor(), cursor: "pointer", padding: "0px 10px", zIndex: 10 }} > x
{pos.isStamp ? "stamp" : "signature"}
); })}
); })}
); }) : xyPostion.map((data, ind) => { return ( {data.pageNumber === pageNumber && data.pos.map((pos) => { return pos && pos.SignUrl ? ( handleTabDrag(pos.key)} onDragStop={handleStop} onResize={( e, direction, ref, delta, position ) => { handleImageResize( ref, pos.key, direction, position ); }} > {" "}
{ if (!isDragging) { setTimeout(() => { e.stopPropagation(); setIsSignPad(true); setSignKey(pos.key); setIsStamp(pos.isStamp); }, 500); } }} >
{ e.stopPropagation(); handleDeleteSign(pos.key); setIsStamp(false); }} style={{ position: "absolute", right: 0, display: "inline-block", background: themeColor(), cursor: "pointer", padding: "0px 10px" }} > x
signimg { setSignKey(pos.key); setIsSignPad(true); setIsStamp(pos.isStamp); }} src={pos.SignUrl} style={{ width: "100%", height: "100%", objectFit: "contain" }} />
) : ( <> { handleTabDrag(pos.key, e); }} onDragStop={handleStop} size={{ width: pos.Width ? pos.Width : 150, height: pos.Height ? pos.Height : 60 }} default={{ x: pos.xPosition, y: pos.yPosition }} >
{ if (!isDragging) { setTimeout(() => { setIsSignPad(true); setSignKey(pos.key); setIsStamp(pos.isStamp); }, 500); } }} className="dragElm" style={{ padding: "0px", cursor: "all-scroll", zIndex: 20, position: "absolute", borderStyle: "dashed", width: "150px", height: "60px", borderColor: themeColor(), background: "#daebe0", textAlign: "center", justifyContent: "center", borderWidth: "0.2px", overflow: "hidden" }} >
{ e.stopPropagation(); e.preventDefault(); handleDeleteSign(pos.key); setIsStamp(false); }} onClick={(e) => { e.stopPropagation(); // Prevent further event propagation }} style={{ position: "absolute", right: 0, display: "inline-block", background: themeColor(), cursor: "pointer", padding: "0px 10px" }} > x
{pos.isStamp ? "stamp" : "signature"}
); })}
); }))} {/* this component for render pdf document is in middle of the component */}
{ if (recipient) { setPdfLoadFail(true); } }} onLoadSuccess={pageDetails} ref={pdfRef} file={pdfUrl ? pdfUrl : pdfDetails[0] && pdfDetails[0].URL} > {Array.from(new Array(numPages), (el, index) => ( { console.log("annotation error", error); }} /> ))}
) : ( pdfNewWidth ? pdfNewWidth : pdfOriginalWidth, height: window.innerHeight - 110 + "px" }} noScrollY={false} noScrollX={pdfNewWidth < pdfOriginalWidth ? false : true} >
Email sent successful!
{pdfLoadFail.status && (recipient ? !pdfUrl && !isAlreadySign.mssg && xyPostion.length > 0 && xyPostion.map((data, ind) => { return ( {data.pageNumber === pageNumber && data.pos.map((pos) => { return pos && pos.SignUrl ? ( { setIsSignPad(true); setSignKey(pos.key); }} >
no img { setIsSignPad(true); setSignKey(pos.key); }} src={pos.SignUrl} style={{ width: "100%", height: "100%", objectFit: "contain" }} />
) : ( { setIsSignPad(true); setSignKey(pos.key); setIsStamp(pos.isStamp); }} >
{pos.isStamp ? "stamp" : "signature"}
); })}
); }) : pdfRequest ? signerPos.map((data, key) => { return ( {checkSignedSignes(data)} ); }) : placeholder ? signerPos.map((data, ind) => { return ( {data.placeHolder.map((placeData, index) => { return ( {placeData.pageNumber === pageNumber && placeData.pos.map((pos) => { return ( handleTabDrag(pos.key, data.signerObjId) } size={{ width: pos.Width ? pos.Width : 150, height: pos.Height ? pos.Height : 60 }} lockAspectRatio={ pos.Width ? pos.Width / pos.Height : 2.5 } resizeHandleStyles={{ bottom: { display: "none" }, right: { display: "none" }, bottomRight: { display: "block" } }} onDragStop={(event, dragElement) => handleStop( event, dragElement, data.signerObjId, pos.key ) } default={{ x: pos.xPosition, y: pos.yPosition }} onResize={( e, direction, ref, delta, position ) => { handleImageResize( ref, pos.key, data.signerObjId, position ); }} >
{ e.stopPropagation(); handleDeleteSign( pos.key, data.signerObjId ); }} style={{ position: "absolute", right: 0, display: "inline-block", background: themeColor(), cursor: "pointer", padding: "0px 10px", zIndex: 10 }} > x
{pos.isStamp ? "stamp" : "signature"}
); })}
); })}
); }) : xyPostion.map((data, ind) => { return ( {data.pageNumber === pageNumber && data.pos.map((pos) => { return pos && pos.SignUrl ? ( handleTabDrag(pos.key)} size={{ width: pos.Width ? pos.Width : 150, height: pos.Height ? pos.Height : 60 }} onDragStop={handleStop} default={{ x: pos.xPosition, y: pos.yPosition }} onResize={( e, direction, ref, delta, position ) => { handleImageResize( ref, pos.key, direction, position ); }} onClick={() => { if (!isDragging) { setIsSignPad(true); setSignKey(pos.key); setIsStamp(pos.isStamp); } }} >
{ e.stopPropagation(); handleDeleteSign(pos.key); setIsStamp(false); }} style={{ position: "absolute", right: 0, display: "inline-block", background: themeColor(), cursor: "pointer", padding: "0px 10px" }} > x
signimg { setSignKey(pos.key); setIsSignPad(true); setIsStamp(pos.isStamp); }} src={pos.SignUrl} style={{ width: "100%", height: "100%", objectFit: "contain" }} />
) : ( handleTabDrag(pos.key, e)} size={{ width: pos.Width ? pos.Width : 150, height: pos.Height ? pos.Height : 60 }} onDragStop={handleStop} default={{ x: pos.xPosition, y: pos.yPosition }} >
{ if (!isDragging) { e.stopPropagation(); setIsSignPad(true); setSignKey(pos.key); setIsStamp(pos.isStamp); } }} style={{ cursor: "all-scroll", zIndex: 10, position: "absolute", borderStyle: "dashed", width: "150px", height: "60px", borderColor: themeColor(), background: "#daebe0", textAlign: "center", justifyContent: "center", alignItems: "center", borderWidth: "0.2px" }} >
{ e.stopPropagation(); handleDeleteSign(pos.key); setIsStamp(false); }} style={{ position: "absolute", right: 0, display: "inline-block", background: themeColor(), cursor: "pointer", padding: "0px 10px" }} > x
{pos.isStamp ? "stamp" : "signature"}
); })}
); }))} {/* this component for render pdf document is in middle of the component */} { if (recipient) { const load = { status: false, type: "failed" }; setPdfLoadFail(load); } }} onLoadSuccess={pageDetails} ref={pdfRef} file={pdfUrl ? pdfUrl : pdfDetails[0] && pdfDetails[0].URL} > {Array.from(new Array(numPages), (el, index) => ( { console.log("annotation error", error); }} /> ))}
)} ); } export default RenderPdf;