mirror of
https://github.com/OpenSignLabs/OpenSign.git
synced 2026-08-17 21:25:54 +02:00
Refactor code
This commit is contained in:
@@ -7,6 +7,7 @@ import Modal from "react-bootstrap/Modal";
|
||||
import ModalHeader from "react-bootstrap/esm/ModalHeader";
|
||||
import { themeColor, iconColor } from "../../utils/ThemeColor/backColor";
|
||||
import { getDrive } from "../../utils/Utils";
|
||||
import AlertComponent from "../component/alertComponent";
|
||||
|
||||
function PdfFile() {
|
||||
const scrollRef = useRef(null);
|
||||
@@ -26,6 +27,7 @@ function PdfFile() {
|
||||
const [docId, setDocId] = useState();
|
||||
const [handleError, setHandleError] = useState();
|
||||
const [folderName, setFolderName] = useState([]);
|
||||
const [isAlert, setIsAlert] = useState({ isShow: false, alertMessage: "" });
|
||||
const currentUser =
|
||||
localStorage.getItem(
|
||||
`Parse/${localStorage.getItem("parseAppId")}/currentUser`
|
||||
@@ -219,8 +221,10 @@ function PdfFile() {
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log("axois err ", err);
|
||||
alert("something went wrong");
|
||||
setIsAlert({
|
||||
isShow: true,
|
||||
alertMessage: "something went wrong"
|
||||
});
|
||||
});
|
||||
} else {
|
||||
setError("Please fill out this field");
|
||||
@@ -324,6 +328,11 @@ function PdfFile() {
|
||||
return (
|
||||
<div className="folderComponent ">
|
||||
<div>
|
||||
<AlertComponent
|
||||
isShow={isAlert.isShow}
|
||||
alertMessage={isAlert.alertMessage}
|
||||
setIsAlert={setIsAlert}
|
||||
/>
|
||||
<Modal show={isFolder}>
|
||||
<ModalHeader style={{ background: themeColor() }}>
|
||||
<span style={{ color: "white" }}>Add New Folder</span>
|
||||
|
||||
@@ -28,6 +28,7 @@ import Nodata from "./component/Nodata";
|
||||
import Header from "./component/header";
|
||||
import RenderPdf from "./component/renderPdf";
|
||||
import CustomModal from "./component/CustomModal";
|
||||
import AlertComponent from "./component/alertComponent";
|
||||
|
||||
function PdfRequestFiles() {
|
||||
const { docId } = useParams();
|
||||
@@ -61,7 +62,7 @@ function PdfRequestFiles() {
|
||||
const [isUiLoading, setIsUiLoading] = useState(false);
|
||||
const [isDecline, setIsDecline] = useState({ isDeclined: false });
|
||||
const [currentSigner, setCurrentSigner] = useState(false);
|
||||
|
||||
const [isAlert, setIsAlert] = useState({ isShow: false, alertMessage: "" });
|
||||
const [isCompleted, setIsCompleted] = useState({
|
||||
isCertificate: false,
|
||||
isModal: false
|
||||
@@ -290,26 +291,23 @@ function PdfRequestFiles() {
|
||||
);
|
||||
for (let i = 0; i < checkSign.length; i++) {
|
||||
const posData = checkSign[i].pos.filter((pos) => !pos.SignUrl);
|
||||
|
||||
if (posData && posData.length > 0) {
|
||||
checkSignUrl.push(posData);
|
||||
}
|
||||
}
|
||||
|
||||
if (checkSignUrl && checkSignUrl.length == 0) {
|
||||
alert("Please complete your signature!");
|
||||
if (checkSignUrl && checkSignUrl.length > 0) {
|
||||
setIsAlert({
|
||||
isShow: true,
|
||||
alertMessage: "Please complete your signature!"
|
||||
});
|
||||
} else {
|
||||
setIsUiLoading(true);
|
||||
|
||||
const url = pdfUrl;
|
||||
|
||||
const pngUrl = checkUser[0].placeHolder;
|
||||
|
||||
// Load a PDFDocument from the existing PDF bytes
|
||||
const existingPdfBytes = await fetch(url).then((res) =>
|
||||
const existingPdfBytes = await fetch(pdfUrl).then((res) =>
|
||||
res.arrayBuffer()
|
||||
);
|
||||
|
||||
const pdfDoc = await PDFDocument.load(existingPdfBytes, {
|
||||
ignoreEncryption: true
|
||||
});
|
||||
@@ -318,22 +316,33 @@ function PdfRequestFiles() {
|
||||
//checking if signature is only one then send image url in jpeg formate to server
|
||||
if (pngUrl.length === 1 && pngUrl[0].pos.length === 1) {
|
||||
if (isDocId) {
|
||||
pdfBase64 = await getBase64FromUrl(url);
|
||||
try {
|
||||
pdfBase64 = await getBase64FromUrl(pdfUrl);
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
} else {
|
||||
//embed document's object id to all pages in pdf document
|
||||
await embedDocId(pdfDoc, documentId, allPages);
|
||||
pdfBase64 = await pdfDoc.saveAsBase64({
|
||||
useObjectStreams: false
|
||||
});
|
||||
try {
|
||||
await embedDocId(pdfDoc, documentId, allPages);
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
try {
|
||||
pdfBase64 = await pdfDoc.saveAsBase64({
|
||||
useObjectStreams: false
|
||||
});
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
}
|
||||
for (let i = 0; i < pngUrl.length; i++) {
|
||||
const imgUrlList = pngUrl[i].pos;
|
||||
const pageNo = pngUrl[i].pageNumber;
|
||||
for (let pngData of pngUrl) {
|
||||
const imgUrlList = pngData.pos;
|
||||
const pageNo = pngData.pageNumber;
|
||||
imgUrlList.map(async (data) => {
|
||||
//cheking signUrl is defau;t signature url of custom url
|
||||
let ImgUrl = data.SignUrl;
|
||||
const checkUrl = urlValidator(ImgUrl);
|
||||
|
||||
//if default signature url then convert it in base 64
|
||||
if (checkUrl) {
|
||||
ImgUrl = await getBase64FromIMG(ImgUrl + "?get");
|
||||
@@ -355,6 +364,7 @@ function PdfRequestFiles() {
|
||||
pdfOriginalWidth,
|
||||
pngUrl,
|
||||
containerWH,
|
||||
setIsAlert,
|
||||
data,
|
||||
pdfBase64,
|
||||
pageNo
|
||||
@@ -367,11 +377,17 @@ function PdfRequestFiles() {
|
||||
setUnSignedSigners([]);
|
||||
getDocumentDetails();
|
||||
} else {
|
||||
alert("something went wrong");
|
||||
setIsAlert({
|
||||
isShow: true,
|
||||
alertMessage: "something went wrong"
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
alert("something went wrong");
|
||||
setIsAlert({
|
||||
isShow: true,
|
||||
alertMessage: "something went wrong"
|
||||
});
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
@@ -382,6 +398,7 @@ function PdfRequestFiles() {
|
||||
}
|
||||
//else if signature is more than one then embed all sign with the use of pdf-lib
|
||||
else if (pngUrl.length > 0 && pngUrl[0].pos.length > 0) {
|
||||
const flag = false;
|
||||
//embed document's object id to all pages in pdf document
|
||||
await embedDocId(pdfDoc, documentId, allPages);
|
||||
//embed multi signature in pdf
|
||||
@@ -389,40 +406,48 @@ function PdfRequestFiles() {
|
||||
pngUrl,
|
||||
pdfDoc,
|
||||
pdfOriginalWidth,
|
||||
false,
|
||||
flag,
|
||||
containerWH
|
||||
);
|
||||
// console.log(pdfBytes)
|
||||
|
||||
//function for call to embed signature in pdf and get digital signature pdf
|
||||
signPdfFun(
|
||||
pdfBytes,
|
||||
documentId,
|
||||
signerObjectId,
|
||||
pdfOriginalWidth,
|
||||
pngUrl,
|
||||
containerWH
|
||||
)
|
||||
.then((res) => {
|
||||
if (res && res.status === "success") {
|
||||
setPdfUrl(res.data);
|
||||
setIsSigned(true);
|
||||
setSignedSigners([]);
|
||||
setUnSignedSigners([]);
|
||||
getDocumentDetails();
|
||||
} else {
|
||||
alert("something went wrong");
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
alert("something went wrong");
|
||||
try {
|
||||
const res = await signPdfFun(
|
||||
pdfBytes,
|
||||
documentId,
|
||||
signerObjectId,
|
||||
pdfOriginalWidth,
|
||||
pngUrl,
|
||||
containerWH,
|
||||
setIsAlert
|
||||
);
|
||||
if (res && res.status === "success") {
|
||||
setPdfUrl(res.data);
|
||||
setIsSigned(true);
|
||||
setSignedSigners([]);
|
||||
setUnSignedSigners([]);
|
||||
getDocumentDetails();
|
||||
} else {
|
||||
setIsAlert({
|
||||
isShow: true,
|
||||
alertMessage: "something went wrong"
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
setIsAlert({
|
||||
isShow: true,
|
||||
alertMessage: "something went wrong"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
setIsSignPad(false);
|
||||
}
|
||||
} else {
|
||||
console.log("something went wrong!");
|
||||
alert("something went wrong!");
|
||||
setIsAlert({
|
||||
isShow: true,
|
||||
alertMessage: "something went wrong"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -729,6 +754,11 @@ function PdfRequestFiles() {
|
||||
)}
|
||||
|
||||
<div className="signatureContainer" ref={divRef}>
|
||||
<AlertComponent
|
||||
isShow={isAlert.isShow}
|
||||
alertMessage={isAlert.alertMessage}
|
||||
setIsAlert={setIsAlert}
|
||||
/>
|
||||
{/* this modal is used to show decline alert */}
|
||||
<CustomModal
|
||||
containerWH={containerWH}
|
||||
|
||||
@@ -33,6 +33,7 @@ import Header from "./component/header";
|
||||
import RenderPdf from "./component/renderPdf";
|
||||
import { contractUsers, contactBook, urlValidator } from "../utils/Utils";
|
||||
import { modalAlign } from "../utils/Utils";
|
||||
import AlertComponent from "./component/alertComponent";
|
||||
|
||||
//For signYourself inProgress section signer can add sign and complete doc sign.
|
||||
function SignYourSelf() {
|
||||
@@ -83,6 +84,7 @@ function SignYourSelf() {
|
||||
status: false,
|
||||
type: "load"
|
||||
});
|
||||
const [isAlert, setIsAlert] = useState({ isShow: false, alertMessage: "" });
|
||||
const divRef = useRef(null);
|
||||
const nodeRef = useRef(null);
|
||||
const [{ isOver }, drop] = useDrop({
|
||||
@@ -401,14 +403,22 @@ function SignYourSelf() {
|
||||
|
||||
for (let i = 0; i < xyPostion.length; i++) {
|
||||
const posData = xyPostion[i].pos.filter((pos) => !pos.SignUrl);
|
||||
|
||||
if (posData && posData.length > 0) {
|
||||
checkSignUrl.push(posData);
|
||||
}
|
||||
}
|
||||
|
||||
if (checkSignUrl && checkSignUrl.length == 0) {
|
||||
alert("Please complete your signature!");
|
||||
if (xyPostion.length === 0) {
|
||||
setIsAlert({
|
||||
isShow: true,
|
||||
alertMessage: "Please complete your signature!"
|
||||
});
|
||||
return;
|
||||
} else if (xyPostion.length > 0 && checkSignUrl.length > 0) {
|
||||
setIsAlert({
|
||||
isShow: true,
|
||||
alertMessage: "Please complete your signature!"
|
||||
});
|
||||
return;
|
||||
} else {
|
||||
setIsCeleb(true);
|
||||
setTimeout(() => {
|
||||
@@ -429,7 +439,7 @@ function SignYourSelf() {
|
||||
const pdfDoc = await PDFDocument.load(existingPdfBytes, {
|
||||
ignoreEncryption: true
|
||||
});
|
||||
const pngUrl = xyPostion;
|
||||
|
||||
//checking if signature is only one then send image url in jpeg formate to server
|
||||
if (xyPostion.length === 1 && xyPostion[0].pos.length === 1) {
|
||||
//embed document's object id to all pages in pdf document
|
||||
@@ -437,15 +447,14 @@ function SignYourSelf() {
|
||||
const pdfBase64 = await pdfDoc.saveAsBase64({
|
||||
useObjectStreams: false
|
||||
});
|
||||
for (let i = 0; i < xyPostion.length; i++) {
|
||||
const imgUrlList = xyPostion[i].pos;
|
||||
const pageNo = xyPostion[i].pageNumber;
|
||||
|
||||
for (let xyData of xyPostion) {
|
||||
const imgUrlList = xyData.pos;
|
||||
const pageNo = xyData.pageNumber;
|
||||
imgUrlList.map(async (data) => {
|
||||
let ImgUrl = data.SignUrl;
|
||||
//cheking signUrl is defau;t signature url of custom url
|
||||
const checkUrl = urlValidator(ImgUrl);
|
||||
|
||||
//if default signature url then convert it in base 64
|
||||
if (checkUrl) {
|
||||
ImgUrl = await getBase64FromIMG(ImgUrl + "?get");
|
||||
@@ -469,14 +478,16 @@ function SignYourSelf() {
|
||||
}
|
||||
//else if signature is more than one then embed all sign with the use of pdf-lib
|
||||
else if (xyPostion.length > 0 && xyPostion[0].pos.length > 0) {
|
||||
const flag = false;
|
||||
//embed document's object id to all pages in pdf document
|
||||
await embedDocId(pdfDoc, documentId, allPages);
|
||||
|
||||
//embed multi signature in pdf
|
||||
const pdfBytes = await multiSignEmbed(
|
||||
pngUrl,
|
||||
xyPostion,
|
||||
pdfDoc,
|
||||
pdfOriginalWidth,
|
||||
true,
|
||||
flag,
|
||||
containerWH
|
||||
);
|
||||
//function for call to embed signature in pdf and get digital signature pdf
|
||||
@@ -500,7 +511,7 @@ function SignYourSelf() {
|
||||
let singleSign;
|
||||
const newWidth = containerWH.width;
|
||||
const scale = isMobile ? pdfOriginalWidth / newWidth : 1;
|
||||
const imgWidth = xyPosData ? xyPosData.Width : 150;
|
||||
|
||||
if (xyPostion.length === 1 && xyPostion[0].pos.length === 1) {
|
||||
const height = xyPosData.Height ? xyPosData.Height : 60;
|
||||
const bottomY = xyPosData.isDrag
|
||||
@@ -856,8 +867,12 @@ function SignYourSelf() {
|
||||
marginRight: !isMobile && pdfOriginalWidth > 500 && "20px"
|
||||
}}
|
||||
>
|
||||
<AlertComponent
|
||||
isShow={isAlert.isShow}
|
||||
alertMessage={isAlert.alertMessage}
|
||||
setIsAlert={setIsAlert}
|
||||
/>
|
||||
{/* this modal is used show this document is already sign */}
|
||||
|
||||
<Modal
|
||||
show={showAlreadySignDoc.status}
|
||||
onShow={() => modalAlign()}
|
||||
@@ -921,9 +936,9 @@ function SignYourSelf() {
|
||||
isCeleb={isCeleb}
|
||||
setIsEmail={setIsEmail}
|
||||
pdfName={pdfDetails[0] && pdfDetails[0].Name}
|
||||
signObjId={documentId}
|
||||
setSuccessEmail={setSuccessEmail}
|
||||
sender={jsonSender}
|
||||
setIsAlert={setIsAlert}
|
||||
/>
|
||||
{/* pdf header which contain funish back button */}
|
||||
<Header
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import React from "react";
|
||||
import Modal from "react-bootstrap/Modal";
|
||||
import ModalHeader from "react-bootstrap/esm/ModalHeader";
|
||||
|
||||
function AlertComponent({ isShow, alertMessage, setIsAlert }) {
|
||||
return (
|
||||
<Modal show={isShow}>
|
||||
<ModalHeader className="bg-danger" style={{ color: "white" }}>
|
||||
<span>Alert</span>
|
||||
</ModalHeader>
|
||||
|
||||
<Modal.Body>
|
||||
<span>{alertMessage}</span>
|
||||
</Modal.Body>
|
||||
<Modal.Footer>
|
||||
<button
|
||||
onClick={() => {
|
||||
setIsAlert({
|
||||
isShow: false,
|
||||
alertMessage: ""
|
||||
});
|
||||
}}
|
||||
style={{
|
||||
color: "black"
|
||||
}}
|
||||
type="button"
|
||||
className="finishBtn"
|
||||
>
|
||||
Ok
|
||||
</button>
|
||||
</Modal.Footer>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
export default AlertComponent;
|
||||
@@ -16,9 +16,9 @@ function EmailComponent({
|
||||
isCeleb,
|
||||
setIsEmail,
|
||||
setSuccessEmail,
|
||||
signObjId,
|
||||
pdfName,
|
||||
sender
|
||||
sender,
|
||||
setIsAlert
|
||||
}) {
|
||||
const [emailList, setEmailList] = useState([]);
|
||||
const [emailValue, setEmailValue] = useState();
|
||||
@@ -62,11 +62,15 @@ function EmailComponent({
|
||||
} catch (error) {
|
||||
console.log("error", error);
|
||||
setIsLoading(false);
|
||||
alert("Something went wrong!");
|
||||
setIsEmail(false);
|
||||
setIsAlert({
|
||||
isShow: true,
|
||||
alertMessage: "something went wrong"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (sendMail.data.result.status === "success") {
|
||||
if (sendMail && sendMail.data.result.status === "success") {
|
||||
setSuccessEmail(true);
|
||||
setTimeout(() => {
|
||||
setSuccessEmail(false);
|
||||
@@ -76,12 +80,20 @@ function EmailComponent({
|
||||
}, 1500);
|
||||
|
||||
setIsLoading(false);
|
||||
} else if (sendMail.data.result.status === "error") {
|
||||
} else if (sendMail && sendMail.data.result.status === "error") {
|
||||
setIsLoading(false);
|
||||
alert("Something went wrong!");
|
||||
setIsEmail(false);
|
||||
setIsAlert({
|
||||
isShow: true,
|
||||
alertMessage: "something went wrong"
|
||||
});
|
||||
} else {
|
||||
setIsLoading(false);
|
||||
alert("Something went wrong!");
|
||||
setIsEmail(false);
|
||||
setIsAlert({
|
||||
isShow: true,
|
||||
alertMessage: "something went wrong"
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -63,9 +63,7 @@ function RenderPdf({
|
||||
width = pos.Width ? pos.Width : 150;
|
||||
return width;
|
||||
} else {
|
||||
width = pos.Width / scale ? pos.Width / scale : 150 / scale;
|
||||
// width =
|
||||
// pos.Width * pos.scale ? pos.Width * pos.scale : 150 * pos.scale;
|
||||
width = (pos.Width || 150) / scale;
|
||||
return width;
|
||||
}
|
||||
} else {
|
||||
@@ -78,7 +76,7 @@ function RenderPdf({
|
||||
width = pos.Width ? pos.Width : 150;
|
||||
return width;
|
||||
} else {
|
||||
width = pos.Width ? pos.Width * pos.scale : 150 * pos.scale;
|
||||
width = (pos.Width || 150) * pos.scale;
|
||||
return width;
|
||||
}
|
||||
} else {
|
||||
@@ -92,12 +90,10 @@ function RenderPdf({
|
||||
if (isMobile) {
|
||||
if (!pos.isMobile) {
|
||||
if (pos.IsResize) {
|
||||
// height = pos.Height ? pos.Height / scale : 60 / scale;
|
||||
height = pos.Height ? pos.Height : 60;
|
||||
return height;
|
||||
} else {
|
||||
height = pos.Height ? pos.Height / scale : 60 / scale;
|
||||
// height = pos.Height ? pos.Height * pos.scale : 60 * pos.scale;
|
||||
height = (pos.Height || 60) / scale;
|
||||
return height;
|
||||
}
|
||||
} else {
|
||||
@@ -110,7 +106,7 @@ function RenderPdf({
|
||||
height = pos.Height ? pos.Height : 60;
|
||||
return height;
|
||||
} else {
|
||||
height = pos.Height ? pos.Height * pos.scale : 60 * pos.scale;
|
||||
height = (pos.Height || 60) * pos.scale;
|
||||
return height;
|
||||
}
|
||||
} else {
|
||||
@@ -298,46 +294,6 @@ function RenderPdf({
|
||||
}
|
||||
};
|
||||
|
||||
const calculateWidth = (pos) => {
|
||||
let width;
|
||||
if (isMobile) {
|
||||
width = pos.Width ? pos.Width * scale : 150 * scale;
|
||||
return width;
|
||||
} else {
|
||||
if (pos.isMobile) {
|
||||
if (pos.IsResize) {
|
||||
width = pos.Width ? pos.Width : 150;
|
||||
return width;
|
||||
} else {
|
||||
width = pos.Width ? pos.Width * pos.scale : 150 * pos.scale;
|
||||
return width;
|
||||
}
|
||||
} else {
|
||||
width = pos.Width ? pos.Width : 150;
|
||||
return width;
|
||||
}
|
||||
}
|
||||
};
|
||||
const calculateHeight = (pos) => {
|
||||
let height;
|
||||
if (isMobile) {
|
||||
height = pos.Height ? pos.Height * scale : 60 * scale;
|
||||
return height;
|
||||
} else {
|
||||
if (pos.isMobile) {
|
||||
if (pos.IsResize) {
|
||||
height = pos.Height ? pos.Height : 60;
|
||||
return height;
|
||||
} else {
|
||||
height = pos.Height ? pos.Height * pos.scale : 60 * pos.scale;
|
||||
return height;
|
||||
}
|
||||
} else {
|
||||
height = pos.Height ? pos.Height : 60;
|
||||
return height;
|
||||
}
|
||||
}
|
||||
};
|
||||
return (
|
||||
<>
|
||||
{isMobile && scale ? (
|
||||
@@ -817,8 +773,8 @@ function RenderPdf({
|
||||
}}
|
||||
className="placeholderBlock"
|
||||
size={{
|
||||
width: calculateWidth(pos),
|
||||
height: calculateHeight(pos)
|
||||
width: posWidth(pos),
|
||||
height: posHeight(pos)
|
||||
}}
|
||||
lockAspectRatio={pos.Width && 2.5}
|
||||
//if pos.isMobile false -- placeholder saved from mobile view then handle position in desktop view to multiply by scale
|
||||
|
||||
@@ -34,6 +34,7 @@ import Header from "./component/header";
|
||||
import RenderPdf from "./component/renderPdf";
|
||||
import CustomModal from "./component/CustomModal";
|
||||
import { modalAlign } from "../utils/Utils";
|
||||
import AlertComponent from "./component/alertComponent";
|
||||
function EmbedPdfImage() {
|
||||
const { id, contactBookId } = useParams();
|
||||
const [isSignPad, setIsSignPad] = useState(false);
|
||||
@@ -65,7 +66,6 @@ function EmbedPdfImage() {
|
||||
const [checkTourStatus, setCheckTourStatus] = useState(false);
|
||||
const [signerUserId, setSignerUserId] = useState();
|
||||
const [tourStatus, setTourStatus] = useState([]);
|
||||
const [completePdfData, setCompletePdfData] = useState([]);
|
||||
const [isExpired, setIsExpired] = useState(false);
|
||||
const [noData, setNoData] = useState(false);
|
||||
const [contractName, setContractName] = useState("");
|
||||
@@ -77,6 +77,7 @@ function EmbedPdfImage() {
|
||||
type: "load"
|
||||
});
|
||||
const [containerWH, setContainerWH] = useState({});
|
||||
const [isAlert, setIsAlert] = useState({ isShow: false, alertMessage: "" });
|
||||
const docId = id && id;
|
||||
const isMobile = window.innerWidth < 767;
|
||||
const index = xyPostion.findIndex((object) => {
|
||||
@@ -92,8 +93,7 @@ function EmbedPdfImage() {
|
||||
: `${localStorage.getItem("UserInformation")}` &&
|
||||
`${localStorage.getItem("UserInformation")}`;
|
||||
const jsonSender = JSON.parse(senderUser);
|
||||
//check isGuestSigner is present in local if yes than handle login flow header in mobile view
|
||||
const isGuestSigner = localStorage.getItem("isGuestSigner");
|
||||
|
||||
useEffect(() => {
|
||||
getDocumentDetails();
|
||||
}, []);
|
||||
@@ -202,7 +202,6 @@ function EmbedPdfImage() {
|
||||
setIsAlreadySign(alreadySign);
|
||||
setPdfUrl(documentData[0].SignedUrl);
|
||||
setSignedPdfData(documentData);
|
||||
setCompletePdfData(documentData);
|
||||
} else if (declined) {
|
||||
const currentDecline = {
|
||||
currnt: "another",
|
||||
@@ -396,8 +395,11 @@ function EmbedPdfImage() {
|
||||
}
|
||||
}
|
||||
|
||||
if (checkSignUrl && checkSignUrl.length == 0) {
|
||||
alert("Please complete your signature!");
|
||||
if (checkSignUrl && checkSignUrl.length > 0) {
|
||||
setIsAlert({
|
||||
isShow: true,
|
||||
alertMessage: "Please complete your signature!"
|
||||
});
|
||||
} else {
|
||||
const loadObj = {
|
||||
isLoad: true,
|
||||
@@ -428,9 +430,10 @@ function EmbedPdfImage() {
|
||||
await embedDocId(pdfDoc, docId, allPages);
|
||||
pdfBase64 = await pdfDoc.saveAsBase64({ useObjectStreams: false });
|
||||
}
|
||||
for (let i = 0; i < xyPostion.length; i++) {
|
||||
const imgUrlList = pngUrl[i].pos;
|
||||
const pageNo = pngUrl[i].pageNumber;
|
||||
|
||||
for (let xyData of xyPostion) {
|
||||
const imgUrlList = xyData.pos;
|
||||
const pageNo = xyData.pageNumber;
|
||||
imgUrlList.map(async (data) => {
|
||||
//cheking signUrl is defau;t signature url of custom url
|
||||
let ImgUrl = data.SignUrl;
|
||||
@@ -457,6 +460,7 @@ function EmbedPdfImage() {
|
||||
pdfOriginalWidth,
|
||||
xyPostion,
|
||||
containerWH,
|
||||
setIsAlert,
|
||||
data,
|
||||
pdfBase64,
|
||||
pageNo
|
||||
@@ -465,11 +469,17 @@ function EmbedPdfImage() {
|
||||
if (res && res.status === "success") {
|
||||
getDocumentDetails();
|
||||
} else {
|
||||
alert("something went wrong");
|
||||
setIsAlert({
|
||||
isShow: true,
|
||||
alertMessage: "something went wrong"
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
alert("something went wrong!");
|
||||
setIsAlert({
|
||||
isShow: true,
|
||||
alertMessage: "something went wrong"
|
||||
});
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
@@ -480,6 +490,7 @@ function EmbedPdfImage() {
|
||||
}
|
||||
//else if signature is more than one then embed all sign with the use of pdf-lib
|
||||
else if (xyPostion.length > 0 && xyPostion[0].pos.length > 0) {
|
||||
const flag = false;
|
||||
//embed document's object id to all pages in pdf document
|
||||
await embedDocId(pdfDoc, docId, allPages);
|
||||
//embed multi signature in pdf
|
||||
@@ -487,29 +498,35 @@ function EmbedPdfImage() {
|
||||
pngUrl,
|
||||
pdfDoc,
|
||||
pdfOriginalWidth,
|
||||
false,
|
||||
flag,
|
||||
containerWH
|
||||
);
|
||||
|
||||
//function for embed signature in pdf and get digital signature pdf
|
||||
signPdfFun(
|
||||
pdfBytes,
|
||||
docId,
|
||||
signerUserId,
|
||||
pdfOriginalWidth,
|
||||
xyPostion,
|
||||
containerWH
|
||||
)
|
||||
.then((res) => {
|
||||
if (res && res.status === "success") {
|
||||
getDocumentDetails();
|
||||
} else {
|
||||
alert("something went wrong!");
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
alert("something went wrong in query", err);
|
||||
try {
|
||||
const res = await signPdfFun(
|
||||
pdfBytes,
|
||||
docId,
|
||||
signerUserId,
|
||||
pdfOriginalWidth,
|
||||
xyPostion,
|
||||
containerWH,
|
||||
setIsAlert
|
||||
);
|
||||
if (res && res.status === "success") {
|
||||
getDocumentDetails();
|
||||
} else {
|
||||
setIsAlert({
|
||||
isShow: true,
|
||||
alertMessage: "something went wrong"
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
setIsAlert({
|
||||
isShow: true,
|
||||
alertMessage: "something went wrong"
|
||||
});
|
||||
}
|
||||
}
|
||||
setIsSignPad(false);
|
||||
setXyPostion([]);
|
||||
@@ -763,6 +780,11 @@ function EmbedPdfImage() {
|
||||
declineDoc={declineDoc}
|
||||
setIsDecline={setIsDecline}
|
||||
/>
|
||||
<AlertComponent
|
||||
isShow={isAlert.isShow}
|
||||
alertMessage={isAlert.alertMessage}
|
||||
setIsAlert={setIsAlert}
|
||||
/>
|
||||
{/* this modal is used for show expired alert */}
|
||||
<CustomModal
|
||||
containerWH={containerWH}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import axios from "axios";
|
||||
import { $ } from "select-dom";
|
||||
import { rgb } from "pdf-lib";
|
||||
|
||||
const isMobile = window.innerWidth < 767;
|
||||
|
||||
export async function getBase64FromUrl(url) {
|
||||
const data = await fetch(url);
|
||||
const blob = await data.blob();
|
||||
@@ -428,12 +430,11 @@ export const multiSignEmbed = async (
|
||||
signyourself,
|
||||
containerWH
|
||||
) => {
|
||||
for (let i = 0; i < pngUrl.length; i++) {
|
||||
const isMobile = window.innerWidth < 767;
|
||||
for (let item of pngUrl) {
|
||||
const newWidth = containerWH.width;
|
||||
const scale = isMobile ? pdfOriginalWidth / newWidth : 1;
|
||||
const pageNo = pngUrl[i].pageNumber;
|
||||
const imgUrlList = pngUrl[i].pos;
|
||||
const pageNo = item.pageNumber;
|
||||
const imgUrlList = item.pos;
|
||||
const pages = pdfDoc.getPages();
|
||||
const page = pages[pageNo - 1];
|
||||
const images = await Promise.all(
|
||||
@@ -595,9 +596,7 @@ export const handleImageResize = (
|
||||
const filterSignerPos = signerPos.filter(
|
||||
(data) => data.signerObjId === signerId
|
||||
);
|
||||
const isMobile = window.innerWidth < 767;
|
||||
const newWidth = containerWH;
|
||||
const scale = isMobile ? pdfOriginalWidth / newWidth : 1;
|
||||
|
||||
if (filterSignerPos.length > 0) {
|
||||
const getPlaceHolder = filterSignerPos[0].placeHolder;
|
||||
const getPageNumer = getPlaceHolder.filter(
|
||||
@@ -688,10 +687,6 @@ export const handleSignYourselfImageResize = (
|
||||
const updateFilter = xyPostion[index].pos.filter(
|
||||
(data) => data.key === key && data.Width && data.Height
|
||||
);
|
||||
const isMobile = window.innerWidth < 767;
|
||||
const newWidth = containerWH.width;
|
||||
|
||||
const scale = isMobile ? pdfOriginalWidth / newWidth : 1;
|
||||
|
||||
if (updateFilter.length > 0) {
|
||||
const getXYdata = xyPostion[index].pos;
|
||||
@@ -700,8 +695,6 @@ export const handleSignYourselfImageResize = (
|
||||
if (url.key === key) {
|
||||
return {
|
||||
...url,
|
||||
// Width: !url.isMobile ? scaleWidth : ref.offsetWidth,
|
||||
// Height: !url.isMobile ? scaleHeight : ref.offsetHeight,
|
||||
Width: ref.offsetWidth,
|
||||
Height: ref.offsetHeight,
|
||||
IsResize: true
|
||||
@@ -727,8 +720,6 @@ export const handleSignYourselfImageResize = (
|
||||
if (url.key === key) {
|
||||
return {
|
||||
...url,
|
||||
// Width: !url.isMobile ? ref.offsetWidth * scale : ref.offsetWidth,
|
||||
// Height: !url.isMobile ? ref.offsetHeight * scale : ref.offsetHeight
|
||||
Width: ref.offsetWidth,
|
||||
Height: ref.offsetHeight,
|
||||
IsResize: true
|
||||
@@ -755,14 +746,14 @@ export const signPdfFun = async (
|
||||
pdfOriginalWidth,
|
||||
signerData,
|
||||
containerWH,
|
||||
setIsAlert,
|
||||
xyPosData,
|
||||
pdfBase64Url,
|
||||
pageNo
|
||||
) => {
|
||||
let signgleSign;
|
||||
let singleSign;
|
||||
|
||||
const newWidth = containerWH.width;
|
||||
|
||||
const scale = isMobile ? pdfOriginalWidth / newWidth : 1;
|
||||
if (signerData && signerData.length === 1 && signerData[0].pos.length === 1) {
|
||||
const height = xyPosData.Height ? xyPosData.Height : 60;
|
||||
@@ -851,7 +842,7 @@ export const signPdfFun = async (
|
||||
};
|
||||
|
||||
const bottomY = yBottom(xyPosData);
|
||||
signgleSign = {
|
||||
singleSign = {
|
||||
pdfFile: pdfBase64Url,
|
||||
docId: documentId,
|
||||
userId: signerObjectId,
|
||||
@@ -869,7 +860,7 @@ export const signPdfFun = async (
|
||||
signerData.length > 0 &&
|
||||
signerData[0].pos.length > 0
|
||||
) {
|
||||
signgleSign = {
|
||||
singleSign = {
|
||||
pdfFile: base64Url,
|
||||
docId: documentId,
|
||||
userId: signerObjectId
|
||||
@@ -877,7 +868,7 @@ export const signPdfFun = async (
|
||||
}
|
||||
|
||||
const response = await axios
|
||||
.post(`${localStorage.getItem("baseUrl")}functions/signPdf`, signgleSign, {
|
||||
.post(`${localStorage.getItem("baseUrl")}functions/signPdf`, singleSign, {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"X-Parse-Application-Id": localStorage.getItem("parseAppId"),
|
||||
@@ -887,12 +878,13 @@ export const signPdfFun = async (
|
||||
.then((Listdata) => {
|
||||
const json = Listdata.data;
|
||||
const res = json.result;
|
||||
// console.log("res", res);
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log("axois err ", err);
|
||||
alert("something went wrong");
|
||||
setIsAlert({
|
||||
isShow: true,
|
||||
alertMessage: "something went wrong"
|
||||
});
|
||||
});
|
||||
|
||||
return response;
|
||||
|
||||
Reference in New Issue
Block a user