@@ -165,7 +165,7 @@ function SignYourSelf() {
165
165
} )
166
166
} ) ;
167
167
168
- const index = xyPostion . findIndex ( ( object ) => {
168
+ const index = xyPostion ? .findIndex ( ( object ) => {
169
169
return object . pageNumber === pageNumber ;
170
170
} ) ;
171
171
// rowlevel={JSON.parse(localStorage.getItem("rowlevel"))}
@@ -211,7 +211,6 @@ function SignYourSelf() {
211
211
212
212
// Use setTimeout to wait for the transition to complete
213
213
const timer = setTimeout ( updateSize , 100 ) ; // match the transition duration
214
-
215
214
return ( ) => clearTimeout ( timer ) ;
216
215
// eslint-disable-next-line react-hooks/exhaustive-deps
217
216
} , [ divRef . current , isHeader ] ) ;
@@ -226,6 +225,11 @@ function SignYourSelf() {
226
225
if ( documentData && documentData . length > 0 ) {
227
226
setPdfDetails ( documentData ) ;
228
227
setExtUserId ( documentData [ 0 ] ?. ExtUserPtr ?. objectId ) ;
228
+ const placeholders =
229
+ documentData [ 0 ] ?. Placeholders ?. length > 0
230
+ ? documentData [ 0 ] ?. Placeholders
231
+ : [ ] ;
232
+ setXyPostion ( placeholders ) ;
229
233
const url = documentData [ 0 ] && documentData [ 0 ] ?. URL ;
230
234
if ( url ) {
231
235
//convert document url in array buffer format to use embed widgets in pdf using pdf-lib
@@ -238,21 +242,17 @@ function SignYourSelf() {
238
242
} else {
239
243
setHandleError ( t ( "something-went-wrong-mssg" ) ) ;
240
244
}
241
- isCompleted =
242
- documentData [ 0 ] . IsCompleted && documentData [ 0 ] . IsCompleted ;
245
+ isCompleted = documentData ?. [ 0 ] ?. IsCompleted ;
243
246
if ( isCompleted ) {
244
247
setIsCelebration ( true ) ;
245
- setTimeout ( ( ) => {
246
- setIsCelebration ( false ) ;
247
- } , 5000 ) ;
248
+ setTimeout ( ( ) => setIsCelebration ( false ) , 5000 ) ;
248
249
setIsCompleted ( true ) ;
249
250
setPdfUrl ( documentData [ 0 ] . SignedUrl ) ;
250
- const alreadySign = {
251
- status : true ,
252
- mssg : t ( "document-signed-alert" )
253
- } ;
254
251
if ( showComplete ) {
255
- setShowAlreadySignDoc ( alreadySign ) ;
252
+ setShowAlreadySignDoc ( {
253
+ status : true ,
254
+ mssg : t ( "document-signed-alert" )
255
+ } ) ;
256
256
} else {
257
257
setIsUiLoading ( false ) ;
258
258
setIsSignPad ( false ) ;
@@ -265,17 +265,11 @@ function SignYourSelf() {
265
265
documentData === "Error: Something went wrong!" ||
266
266
( documentData . result && documentData . result . error )
267
267
) {
268
- const loadObj = {
269
- isLoad : false
270
- } ;
271
268
setHandleError ( t ( "something-went-wrong-mssg" ) ) ;
272
- setIsLoading ( loadObj ) ;
269
+ setIsLoading ( { isLoad : false } ) ;
273
270
} else {
274
271
setHandleError ( t ( "no-data-avaliable" ) ) ;
275
- const loadObj = {
276
- isLoad : false
277
- } ;
278
- setIsLoading ( loadObj ) ;
272
+ setIsLoading ( { isLoad : false } ) ;
279
273
}
280
274
//function to get default signatur eof current user from `contracts_Signature` class
281
275
const defaultSignRes = await getDefaultSignature ( jsonSender . objectId ) ;
@@ -284,17 +278,12 @@ function SignYourSelf() {
284
278
setMyInitial ( defaultSignRes ?. res ?. defaultInitial ) ;
285
279
} else if ( defaultSignRes ?. status === "error" ) {
286
280
setHandleError ( "Error: Something went wrong!" ) ;
287
- setIsLoading ( {
288
- isLoad : false
289
- } ) ;
281
+ setIsLoading ( { isLoad : false } ) ;
290
282
}
291
283
const contractUsersRes = await contractUsers ( ) ;
292
284
if ( contractUsersRes === "Error: Something went wrong!" ) {
293
- const loadObj = {
294
- isLoad : false
295
- } ;
296
285
setHandleError ( t ( "something-went-wrong-mssg" ) ) ;
297
- setIsLoading ( loadObj ) ;
286
+ setIsLoading ( { isLoad : false } ) ;
298
287
} else if ( contractUsersRes [ 0 ] && contractUsersRes . length > 0 ) {
299
288
setActiveMailAdapter ( contractUsersRes [ 0 ] ?. active_mail_adapter ) ;
300
289
setContractName ( "_Users" ) ;
@@ -374,51 +363,32 @@ function SignYourSelf() {
374
363
const addWidgetOptions = ( type ) => {
375
364
switch ( type ) {
376
365
case "signature" :
377
- return {
378
- name : "signature"
379
- } ;
366
+ return { name : "signature" } ;
380
367
case "stamp" :
381
- return {
382
- name : "stamp"
383
- } ;
368
+ return { name : "stamp" } ;
384
369
case "checkbox" :
385
- return {
386
- name : "checkbox"
387
- } ;
370
+ return { name : "checkbox" } ;
388
371
case textWidget :
389
- return {
390
- name : "text"
391
- } ;
372
+ return { name : "text" } ;
392
373
case "initials" :
393
- return {
394
- name : "initials"
395
- } ;
374
+ return { name : "initials" } ;
396
375
case "name" :
397
376
return {
398
377
name : "name" ,
399
378
defaultValue : getWidgetValue ( type ) ,
400
- validation : {
401
- type : "text" ,
402
- pattern : ""
403
- }
379
+ validation : { type : "text" , pattern : "" }
404
380
} ;
405
381
case "company" :
406
382
return {
407
383
name : "company" ,
408
384
defaultValue : getWidgetValue ( type ) ,
409
- validation : {
410
- type : "text" ,
411
- pattern : ""
412
- }
385
+ validation : { type : "text" , pattern : "" }
413
386
} ;
414
387
case "job title" :
415
388
return {
416
389
name : "job title" ,
417
390
defaultValue : getWidgetValue ( type ) ,
418
- validation : {
419
- type : "text" ,
420
- pattern : ""
421
- }
391
+ validation : { type : "text" , pattern : "" }
422
392
} ;
423
393
case "date" :
424
394
return {
@@ -427,17 +397,12 @@ function SignYourSelf() {
427
397
validation : { format : "MM/dd/yyyy" , type : "date-format" }
428
398
} ;
429
399
case "image" :
430
- return {
431
- name : "image"
432
- } ;
400
+ return { name : "image" } ;
433
401
case "email" :
434
402
return {
435
403
name : "email" ,
436
404
defaultValue : getWidgetValue ( type ) ,
437
- validation : {
438
- type : "email" ,
439
- pattern : ""
440
- }
405
+ validation : { type : "email" , pattern : "" }
441
406
} ;
442
407
default :
443
408
return { } ;
@@ -449,7 +414,7 @@ function SignYourSelf() {
449
414
const key = randomId ( ) ;
450
415
let dropData = [ ] ;
451
416
let dropObj = { } ;
452
- let filterDropPos = xyPostion . filter (
417
+ let filterDropPos = xyPostion ? .filter (
453
418
( data ) => data . pageNumber === pageNumber
454
419
) ;
455
420
const dragTypeValue = item ?. text ? item . text : monitor . type ;
@@ -486,7 +451,6 @@ function SignYourSelf() {
486
451
Height : getHeight / ( containerScale * scale ) ,
487
452
options : addWidgetOptions ( dragTypeValue )
488
453
} ;
489
-
490
454
dropData . push ( dropObj ) ;
491
455
} else {
492
456
//This method returns the offset of the current pointer (mouse) position relative to the client viewport.
@@ -519,25 +483,18 @@ function SignYourSelf() {
519
483
options : addWidgetOptions ( dragTypeValue ) ,
520
484
scale : containerScale
521
485
} ;
522
-
523
486
dropData . push ( dropObj ) ;
524
487
}
525
- if ( filterDropPos . length > 0 ) {
526
- const index = xyPostion . findIndex ( ( object ) => {
488
+ if ( filterDropPos ? .length > 0 ) {
489
+ const index = xyPostion ? .findIndex ( ( object ) => {
527
490
return object . pageNumber === pageNumber ;
528
491
} ) ;
529
- const updateData = filterDropPos [ 0 ] . pos ;
492
+ const updateData = filterDropPos ?. [ 0 ] . pos ;
530
493
const newSignPos = updateData . concat ( dropData ) ;
531
- let xyPos = {
532
- pageNumber : pageNumber ,
533
- pos : newSignPos
534
- } ;
535
- xyPostion . splice ( index , 1 , xyPos ) ;
494
+ let xyPos = { pageNumber : pageNumber , pos : newSignPos } ;
495
+ xyPostion ?. splice ( index , 1 , xyPos ) ;
536
496
} else {
537
- const xyPos = {
538
- pageNumber : pageNumber ,
539
- pos : dropData
540
- } ;
497
+ const xyPos = { pageNumber : pageNumber , pos : dropData } ;
541
498
setXyPostion ( ( prev ) => [ ...prev , xyPos ] ) ;
542
499
}
543
500
@@ -549,7 +506,6 @@ function SignYourSelf() {
549
506
) {
550
507
setIsSignPad ( true ) ;
551
508
}
552
-
553
509
if ( dragTypeValue === "stamp" || dragTypeValue === "image" ) {
554
510
setIsStamp ( true ) ;
555
511
} else if ( dragTypeValue === "initials" ) {
@@ -612,6 +568,30 @@ function SignYourSelf() {
612
568
setIsVerifyModal ( true ) ;
613
569
await handleSendOTP ( Parse . User . current ( ) . getEmail ( ) ) ;
614
570
} ;
571
+ useEffect ( ( ) => {
572
+ const timer = setTimeout ( ( ) => {
573
+ if ( xyPostion ?. length > 0 ) {
574
+ autosavedetails ( ) ;
575
+ }
576
+ } , 2000 ) ;
577
+ return ( ) => clearTimeout ( timer ) ;
578
+ // eslint-disable-next-line react-hooks/exhaustive-deps
579
+ } , [ xyPostion ] ) ;
580
+
581
+ // `autosavedetails` is used to save doc details after every 2 sec when changes are happern in placeholder like drag-drop widgets, remove signers
582
+ const autosavedetails = async ( ) => {
583
+ try {
584
+ const docCls = new Parse . Object ( "contracts_Document" ) ;
585
+ docCls . id = documentId ;
586
+ docCls . set ( "Placeholders" , xyPostion ) ;
587
+ docCls . set ( "IsSignyourself" , true ) ;
588
+ const res = await docCls . save ( ) ;
589
+ console . log ( "Res" , res ) ;
590
+ } catch ( e ) {
591
+ console . log ( "error" , e ) ;
592
+ alert ( t ( "something-went-wrong-mssg" ) ) ;
593
+ }
594
+ } ;
615
595
//function for send placeholder's co-ordinate(x,y) position embed signature url or stamp url
616
596
async function embedWidgetsData ( ) {
617
597
//check current user email is verified or not
@@ -791,7 +771,6 @@ function SignYourSelf() {
791
771
const getNewse64 = await changeImageWH ( base64Sign ) ;
792
772
//remove suffiix of base64
793
773
const suffixbase64 = getNewse64 && getNewse64 . split ( "," ) . pop ( ) ;
794
-
795
774
const params = {
796
775
pdfFile : base64Url ,
797
776
docId : documentId ,
@@ -825,10 +804,10 @@ function SignYourSelf() {
825
804
containerWH
826
805
) ;
827
806
if ( dragKey >= 0 ) {
828
- const filterDropPos = xyPostion . filter (
807
+ const filterDropPos = xyPostion ? .filter (
829
808
( data ) => data . pageNumber === pageNumber
830
809
) ;
831
- if ( filterDropPos . length > 0 ) {
810
+ if ( filterDropPos ? .length > 0 ) {
832
811
const getXYdata = xyPostion [ index ] . pos ;
833
812
const getPosData = getXYdata ;
834
813
const addSign = getPosData . map ( ( url ) => {
@@ -899,15 +878,11 @@ function SignYourSelf() {
899
878
setIsSignPad ( false ) ;
900
879
setIsImageSelect ( false ) ;
901
880
setImage ( ) ;
902
-
903
881
if ( isDefaultSign ) {
904
882
const img = new Image ( ) ;
905
883
img . src = defaultSignImg ;
906
884
if ( img . complete ) {
907
- imgWH = {
908
- width : img . width ,
909
- height : img . height
910
- } ;
885
+ imgWH = { width : img . width , height : img . height } ;
911
886
}
912
887
}
913
888
const getUpdatePosition = onSaveSign (
@@ -932,19 +907,11 @@ function SignYourSelf() {
932
907
const touch = e . touches [ 0 ] ; // Get the first touch point
933
908
mouseX = touch . clientX - divRect . left ;
934
909
mouseY = touch . clientY - divRect . top ;
935
- setSignBtnPosition ( [
936
- {
937
- xPos : mouseX ,
938
- yPos : mouseY
939
- }
940
- ] ) ;
910
+ setSignBtnPosition ( [ { xPos : mouseX , yPos : mouseY } ] ) ;
941
911
} else {
942
912
mouseX = e . clientX - divRect . left ;
943
913
mouseY = e . clientY - divRect . top ;
944
- const xyPosition = {
945
- xPos : mouseX ,
946
- yPos : mouseY
947
- } ;
914
+ const xyPosition = { xPos : mouseX , yPos : mouseY } ;
948
915
setXYSignature ( xyPosition ) ;
949
916
}
950
917
} ;
@@ -962,9 +929,7 @@ function SignYourSelf() {
962
929
const handleDeleteSign = ( key ) => {
963
930
setCurrWidgetsDetails ( { } ) ;
964
931
const updateResizeData = [ ] ;
965
-
966
932
let filterData = xyPostion [ index ] . pos . filter ( ( data ) => data . key !== key ) ;
967
-
968
933
//delete and update block position
969
934
if ( filterData . length > 0 ) {
970
935
updateResizeData . push ( filterData ) ;
@@ -1243,7 +1208,6 @@ function SignYourSelf() {
1243
1208
< Confetti width = { window . innerWidth } height = { window . innerHeight } />
1244
1209
</ div >
1245
1210
) }
1246
-
1247
1211
< div className = "relative op-card overflow-hidden flex flex-col md:flex-row justify-between bg-base-300" >
1248
1212
{ ! isEmailVerified && (
1249
1213
< VerifyEmail
0 commit comments