Skip to content

Commit f5c0694

Browse files
authored
Merge pull request #249 from OpenSignLabs/placeholder-resize
2 parents b6ce005 + dec13e8 commit f5c0694

File tree

9 files changed

+1160
-1310
lines changed

9 files changed

+1160
-1310
lines changed

microfrontends/SignDocuments/src/Component/LegaDrive/LegaDrive.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ function PdfFile() {
5151
};
5252
setIsLoading(load);
5353
const driveDetails = await getDrive();
54-
5554
if (driveDetails) {
5655
if (driveDetails.length > 0) {
5756
setPdfData(driveDetails);

microfrontends/SignDocuments/src/Component/PdfRequestFiles.js

Lines changed: 73 additions & 168 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import {
1919
urlValidator,
2020
multiSignEmbed,
2121
embedDocId,
22-
pdfNewWidthFun
22+
pdfNewWidthFun,
23+
signPdfFun
2324
} from "../utils/Utils";
2425
import Loader from "./component/loader";
2526
import HandleError from "./component/HandleError";
@@ -60,6 +61,7 @@ function PdfRequestFiles() {
6061
const [isUiLoading, setIsUiLoading] = useState(false);
6162
const [isDecline, setIsDecline] = useState({ isDeclined: false });
6263
const [currentSigner, setCurrentSigner] = useState(false);
64+
6365
const [isCompleted, setIsCompleted] = useState({
6466
isCertificate: false,
6567
isModal: false
@@ -73,6 +75,7 @@ function PdfRequestFiles() {
7375
const [alreadySign, setAlreadySign] = useState(false);
7476
const [containerWH, setContainerWH] = useState({});
7577
const divRef = useRef(null);
78+
const isMobile = window.innerWidth < 767;
7679
const rowLevel =
7780
localStorage.getItem("rowlevel") &&
7881
JSON.parse(localStorage.getItem("rowlevel"));
@@ -345,14 +348,32 @@ function PdfRequestFiles() {
345348
);
346349

347350
//function for call to embed signature in pdf and get digital signature pdf
351+
348352
signPdfFun(
349353
newImgUrl,
350354
documentId,
355+
signerObjectId,
356+
pdfOriginalWidth,
357+
pngUrl,
351358
data,
352359
pdfBase64,
353360
pageNo,
354-
pngUrl
355-
);
361+
containerWH
362+
)
363+
.then((res) => {
364+
if (res && res.status === "success") {
365+
setPdfUrl(res.data);
366+
setIsSigned(true);
367+
setSignedSigners([]);
368+
setUnSignedSigners([]);
369+
getDocumentDetails();
370+
} else {
371+
alert("something went wrong");
372+
}
373+
})
374+
.catch((err) => {
375+
alert("something went wrong");
376+
});
356377
})
357378
.catch((error) => {
358379
console.error("Error:", error);
@@ -372,7 +393,29 @@ function PdfRequestFiles() {
372393
false
373394
);
374395

375-
signPdfFun(pdfBytes, documentId, pngUrl);
396+
//function for call to embed signature in pdf and get digital signature pdf
397+
signPdfFun(
398+
pdfBytes,
399+
documentId,
400+
signerObjectId,
401+
pdfOriginalWidth,
402+
pngUrl,
403+
containerWH
404+
)
405+
.then((res) => {
406+
if (res && res.status === "success") {
407+
setPdfUrl(res.data);
408+
setIsSigned(true);
409+
setSignedSigners([]);
410+
setUnSignedSigners([]);
411+
getDocumentDetails();
412+
} else {
413+
alert("something went wrong");
414+
}
415+
})
416+
.catch((err) => {
417+
alert("something went wrong");
418+
});
376419
}
377420

378421
setIsSignPad(false);
@@ -383,147 +426,6 @@ function PdfRequestFiles() {
383426
}
384427
}
385428

386-
//function for call cloud function signPdf and generate digital signature
387-
const signPdfFun = async (
388-
base64Url,
389-
documentId,
390-
xyPosData,
391-
pdfBase64Url,
392-
pageNo,
393-
signerData
394-
) => {
395-
let signgleSign;
396-
const isMobile = window.innerWidth < 767;
397-
const newWidth = window.innerWidth;
398-
const scale = isMobile ? pdfOriginalWidth / newWidth : 1;
399-
if (
400-
signerData &&
401-
signerData.length === 1 &&
402-
signerData[0].pos.length === 1
403-
) {
404-
const height = xyPosData.Height ? xyPosData.Height : 60;
405-
406-
const xPos = (pos) => {
407-
//checking both condition mobile and desktop view
408-
if (isMobile) {
409-
//if pos.isMobile false -- placeholder saved from desktop view then handle position in mobile view divided by scale
410-
if (pos.isMobile) {
411-
const x = pos.xPosition * (pos.scale / scale);
412-
return x * scale + 50;
413-
} else {
414-
const x = pos.xPosition / scale;
415-
return x * scale;
416-
}
417-
} else {
418-
//else if pos.isMobile true -- placeholder saved from mobile or tablet view then handle position in desktop view divide by scale
419-
if (pos.isMobile) {
420-
const x = pos.xPosition * pos.scale + 50;
421-
return x;
422-
} else {
423-
return pos.xPosition;
424-
}
425-
}
426-
};
427-
428-
const yBottom = (pos) => {
429-
let yPosition;
430-
//checking both condition mobile and desktop view
431-
432-
if (isMobile) {
433-
//if pos.isMobile false -- placeholder saved from desktop view then handle position in mobile view divided by scale
434-
if (pos.isMobile) {
435-
const y = pos.yBottom * (pos.scale / scale);
436-
yPosition = pos.isDrag
437-
? y * scale - height
438-
: pos.firstYPos
439-
? y * scale - height + pos.firstYPos
440-
: y * scale - height;
441-
return yPosition;
442-
} else {
443-
const y = pos.yBottom / scale;
444-
445-
yPosition = pos.isDrag
446-
? y * scale - height
447-
: pos.firstYPos
448-
? y * scale - height + pos.firstYPos
449-
: y * scale - height;
450-
return yPosition;
451-
}
452-
} else {
453-
//else if pos.isMobile true -- placeholder saved from mobile or tablet view then handle position in desktop view divide by scale
454-
if (pos.isMobile) {
455-
const y = pos.yBottom * pos.scale;
456-
457-
yPosition = pos.isDrag
458-
? y - height
459-
: pos.firstYPos
460-
? y - height + pos.firstYPos
461-
: y - height;
462-
return yPosition;
463-
} else {
464-
yPosition = pos.isDrag
465-
? pos.yBottom - height
466-
: pos.firstYPos
467-
? pos.yBottom - height + pos.firstYPos
468-
: pos.yBottom - height;
469-
return yPosition;
470-
}
471-
}
472-
};
473-
const bottomY = yBottom(xyPosData);
474-
signgleSign = {
475-
pdfFile: pdfBase64Url,
476-
docId: documentId,
477-
userId: signerObjectId,
478-
sign: {
479-
Base64: base64Url,
480-
Left: xPos(xyPosData),
481-
Bottom: bottomY,
482-
Width: xyPosData.Width ? xyPosData.Width : 150,
483-
Height: height,
484-
Page: pageNo
485-
}
486-
};
487-
} else if (
488-
xyPosData &&
489-
xyPosData.length > 0 &&
490-
xyPosData[0].pos.length > 0
491-
) {
492-
signgleSign = {
493-
pdfFile: base64Url,
494-
docId: documentId,
495-
userId: signerObjectId
496-
};
497-
}
498-
499-
await axios
500-
.post(
501-
`${localStorage.getItem("baseUrl")}functions/signPdf`,
502-
signgleSign,
503-
{
504-
headers: {
505-
"Content-Type": "application/json",
506-
"X-Parse-Application-Id": localStorage.getItem("parseAppId"),
507-
sessionToken: localStorage.getItem("accesstoken")
508-
}
509-
}
510-
)
511-
.then((Listdata) => {
512-
const json = Listdata.data;
513-
514-
if (json.result.data) {
515-
setPdfUrl(json.result.data);
516-
setIsSigned(true);
517-
setSignedSigners([]);
518-
setUnSignedSigners([]);
519-
getDocumentDetails();
520-
}
521-
})
522-
.catch((err) => {
523-
console.log("axois err ", err);
524-
alert("something went wrong");
525-
});
526-
};
527429
//function for get pdf page details
528430
const pageDetails = async (pdf) => {
529431
const load = {
@@ -870,8 +772,8 @@ function PdfRequestFiles() {
870772
{/* pdf render view */}
871773
<div
872774
style={{
873-
marginLeft: pdfOriginalWidth > 500 && "20px",
874-
marginRight: pdfOriginalWidth > 500 && "20px"
775+
marginLeft: !isMobile && pdfOriginalWidth > 500 && "20px",
776+
marginRight: !isMobile && pdfOriginalWidth > 500 && "20px"
875777
}}
876778
>
877779
{/* this modal is used show this document is already sign */}
@@ -936,27 +838,30 @@ function PdfRequestFiles() {
936838
pdfUrl={pdfUrl}
937839
alreadySign={alreadySign}
938840
/>
939-
940-
<RenderPdf
941-
pageNumber={pageNumber}
942-
pdfOriginalWidth={pdfOriginalWidth}
943-
pdfNewWidth={pdfNewWidth}
944-
setIsSignPad={setIsSignPad}
945-
setIsStamp={setIsStamp}
946-
setSignKey={setSignKey}
947-
pdfDetails={pdfDetails}
948-
signerPos={signerPos}
949-
successEmail={false}
950-
pdfUrl={pdfUrl}
951-
numPages={numPages}
952-
pageDetails={pageDetails}
953-
pdfRequest={true}
954-
signerObjectId={signerObjectId}
955-
signedSigners={signedSigners}
956-
setCurrentSigner={setCurrentSigner}
957-
setPdfLoadFail={setPdfLoadFail}
958-
pdfLoadFail={pdfLoadFail}
959-
/>
841+
{containerWH && (
842+
<RenderPdf
843+
pageNumber={pageNumber}
844+
pdfOriginalWidth={pdfOriginalWidth}
845+
pdfNewWidth={pdfNewWidth}
846+
setIsSignPad={setIsSignPad}
847+
setIsStamp={setIsStamp}
848+
setSignKey={setSignKey}
849+
pdfDetails={pdfDetails}
850+
signerPos={signerPos}
851+
successEmail={false}
852+
pdfUrl={pdfUrl}
853+
numPages={numPages}
854+
pageDetails={pageDetails}
855+
pdfRequest={true}
856+
signerObjectId={signerObjectId}
857+
signedSigners={signedSigners}
858+
setCurrentSigner={setCurrentSigner}
859+
setPdfLoadFail={setPdfLoadFail}
860+
pdfLoadFail={pdfLoadFail}
861+
setSignerPos={setSignerPos}
862+
containerWH={containerWH}
863+
/>
864+
)}
960865
</div>
961866
<div>
962867
<div className="signerComponent">

0 commit comments

Comments
 (0)