@@ -19,7 +19,8 @@ import {
19
19
urlValidator ,
20
20
multiSignEmbed ,
21
21
embedDocId ,
22
- pdfNewWidthFun
22
+ pdfNewWidthFun ,
23
+ signPdfFun
23
24
} from "../utils/Utils" ;
24
25
import Loader from "./component/loader" ;
25
26
import HandleError from "./component/HandleError" ;
@@ -60,6 +61,7 @@ function PdfRequestFiles() {
60
61
const [ isUiLoading , setIsUiLoading ] = useState ( false ) ;
61
62
const [ isDecline , setIsDecline ] = useState ( { isDeclined : false } ) ;
62
63
const [ currentSigner , setCurrentSigner ] = useState ( false ) ;
64
+
63
65
const [ isCompleted , setIsCompleted ] = useState ( {
64
66
isCertificate : false ,
65
67
isModal : false
@@ -73,6 +75,7 @@ function PdfRequestFiles() {
73
75
const [ alreadySign , setAlreadySign ] = useState ( false ) ;
74
76
const [ containerWH , setContainerWH ] = useState ( { } ) ;
75
77
const divRef = useRef ( null ) ;
78
+ const isMobile = window . innerWidth < 767 ;
76
79
const rowLevel =
77
80
localStorage . getItem ( "rowlevel" ) &&
78
81
JSON . parse ( localStorage . getItem ( "rowlevel" ) ) ;
@@ -345,14 +348,32 @@ function PdfRequestFiles() {
345
348
) ;
346
349
347
350
//function for call to embed signature in pdf and get digital signature pdf
351
+
348
352
signPdfFun (
349
353
newImgUrl ,
350
354
documentId ,
355
+ signerObjectId ,
356
+ pdfOriginalWidth ,
357
+ pngUrl ,
351
358
data ,
352
359
pdfBase64 ,
353
360
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
+ } ) ;
356
377
} )
357
378
. catch ( ( error ) => {
358
379
console . error ( "Error:" , error ) ;
@@ -372,7 +393,29 @@ function PdfRequestFiles() {
372
393
false
373
394
) ;
374
395
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
+ } ) ;
376
419
}
377
420
378
421
setIsSignPad ( false ) ;
@@ -383,147 +426,6 @@ function PdfRequestFiles() {
383
426
}
384
427
}
385
428
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
- } ;
527
429
//function for get pdf page details
528
430
const pageDetails = async ( pdf ) => {
529
431
const load = {
@@ -870,8 +772,8 @@ function PdfRequestFiles() {
870
772
{ /* pdf render view */ }
871
773
< div
872
774
style = { {
873
- marginLeft : pdfOriginalWidth > 500 && "20px" ,
874
- marginRight : pdfOriginalWidth > 500 && "20px"
775
+ marginLeft : ! isMobile && pdfOriginalWidth > 500 && "20px" ,
776
+ marginRight : ! isMobile && pdfOriginalWidth > 500 && "20px"
875
777
} }
876
778
>
877
779
{ /* this modal is used show this document is already sign */ }
@@ -936,27 +838,30 @@ function PdfRequestFiles() {
936
838
pdfUrl = { pdfUrl }
937
839
alreadySign = { alreadySign }
938
840
/>
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
+ ) }
960
865
</ div >
961
866
< div >
962
867
< div className = "signerComponent" >
0 commit comments