@@ -20,7 +20,9 @@ function SignPad({
20
20
isInitial,
21
21
setIsInitial,
22
22
setIsStamp,
23
- widgetType
23
+ widgetType,
24
+ currWidgetsDetails,
25
+ setCurrWidgetsDetails
24
26
} ) {
25
27
const [ penColor , setPenColor ] = useState ( "blue" ) ;
26
28
const allColor = [ "blue" , "red" , "black" ] ;
@@ -31,6 +33,7 @@ function SignPad({
31
33
const [ signValue , setSignValue ] = useState ( "" ) ;
32
34
const [ textWidth , setTextWidth ] = useState ( null ) ;
33
35
const [ textHeight , setTextHeight ] = useState ( null ) ;
36
+ const [ signatureType , setSignatureType ] = useState ( "draw" ) ;
34
37
const fontOptions = [
35
38
{ value : "Fasthand" } ,
36
39
{ value : "Dancing Script" } ,
@@ -48,19 +51,11 @@ function SignPad({
48
51
`Parse/${ localStorage . getItem ( "parseAppId" ) } /currentUser`
49
52
) ;
50
53
const jsonSender = JSON . parse ( senderUser ) ;
51
-
52
54
const currentUserName = jsonSender && jsonSender . name ;
53
55
54
- useEffect ( ( ) => {
55
- const trimmedName = currentUserName . trim ( ) ;
56
- const firstCharacter = trimmedName . charAt ( 0 ) ;
57
- const userName = isInitial ? firstCharacter : currentUserName ;
58
- setSignValue ( userName ) ;
59
- setFontSelect ( "Fasthand" ) ;
60
- // eslint-disable-next-line react-hooks/exhaustive-deps
61
- } , [ ] ) ;
62
56
//function for clear signature image
63
57
const handleClear = ( ) => {
58
+ setCurrWidgetsDetails ( { } ) ;
64
59
if ( isTab === "draw" ) {
65
60
if ( canvasRef . current ) {
66
61
canvasRef . current . clear ( ) ;
@@ -72,7 +67,7 @@ function SignPad({
72
67
} else if ( isTab === "uploadImage" ) {
73
68
setImage ( "" ) ;
74
69
}
75
- setIsInitial ( false ) ;
70
+ // setIsInitial(false);
76
71
} ;
77
72
//function for set signature url
78
73
const handleSignatureChange = ( ) => {
@@ -100,27 +95,28 @@ function SignPad({
100
95
101
96
< button
102
97
onClick = { ( ) => {
98
+ setCurrWidgetsDetails ( { } ) ;
103
99
if ( ! image ) {
104
100
if ( isTab === "mysignature" ) {
105
101
setIsSignImg ( "" ) ;
106
102
if ( isInitial ) {
107
- onSaveSign ( "initials" ) ;
103
+ onSaveSign ( signatureType , "initials" ) ;
108
104
} else {
109
- onSaveSign ( "default" ) ;
105
+ onSaveSign ( null , "default" ) ;
110
106
}
111
107
} else {
112
108
if ( isTab === "type" ) {
113
109
setIsSignImg ( "" ) ;
114
- onSaveSign ( false , textWidth , textHeight ) ;
110
+ onSaveSign ( null , false , textWidth , textHeight ) ;
115
111
} else {
116
- onSaveSign ( ) ;
112
+ onSaveSign ( signatureType ) ;
117
113
}
118
114
}
119
115
120
116
setPenColor ( "blue" ) ;
121
117
} else {
122
118
setIsSignImg ( "" ) ;
123
- onSaveImage ( ) ;
119
+ onSaveImage ( signatureType ) ;
124
120
}
125
121
setIsSignPad ( false ) ;
126
122
setIsInitial ( false ) ;
@@ -150,11 +146,27 @@ function SignPad({
150
146
</ div >
151
147
) ;
152
148
} ;
153
-
149
+ //useEffect for set already draw or save signature url/text url of signature text type and draw type for initial type and signature type widgets
154
150
useEffect ( ( ) => {
155
- if ( canvasRef . current && isSignImg ) {
156
- canvasRef . current . fromDataURL ( isSignImg ) ;
151
+ if ( currWidgetsDetails && canvasRef . current ) {
152
+ const isWidgetType = currWidgetsDetails ?. type ;
153
+ const signatureType = currWidgetsDetails ?. signatureType ;
154
+ const url = currWidgetsDetails ?. SignUrl ;
155
+
156
+ //checking widget type and draw type signature url
157
+ if ( isInitial ) {
158
+ if ( isWidgetType === "initials" && signatureType === "draw" && url ) {
159
+ canvasRef . current . fromDataURL ( url ) ;
160
+ }
161
+ } else if (
162
+ isWidgetType === "signature" &&
163
+ signatureType === "draw" &&
164
+ url
165
+ ) {
166
+ canvasRef . current . fromDataURL ( url ) ;
167
+ }
157
168
}
169
+
158
170
const trimmedName = currentUserName . trim ( ) ;
159
171
const firstCharacter = trimmedName . charAt ( 0 ) ;
160
172
const userName = isInitial ? firstCharacter : currentUserName ;
@@ -349,6 +361,7 @@ function SignPad({
349
361
setIsDefaultSign ( false ) ;
350
362
setIsImageSelect ( true ) ;
351
363
setIsTab ( "uploadImage" ) ;
364
+ setSignatureType ( "" ) ;
352
365
} }
353
366
style = { {
354
367
color :
@@ -373,6 +386,7 @@ function SignPad({
373
386
setIsDefaultSign ( false ) ;
374
387
setIsImageSelect ( false ) ;
375
388
setIsTab ( "type" ) ;
389
+ setSignatureType ( "" ) ;
376
390
setImage ( ) ;
377
391
} }
378
392
style = { {
@@ -400,6 +414,7 @@ function SignPad({
400
414
setIsDefaultSign ( true ) ;
401
415
setIsImageSelect ( true ) ;
402
416
setIsTab ( "mysignature" ) ;
417
+ setSignatureType ( "" ) ;
403
418
setImage ( ) ;
404
419
} }
405
420
style = { {
@@ -430,6 +445,7 @@ function SignPad({
430
445
setIsDefaultSign ( true ) ;
431
446
setIsImageSelect ( true ) ;
432
447
setIsTab ( "mysignature" ) ;
448
+ setSignatureType ( "" ) ;
433
449
setImage ( ) ;
434
450
} }
435
451
style = { {
@@ -469,6 +485,7 @@ function SignPad({
469
485
setIsDefaultSign ( false ) ;
470
486
setImage ( ) ;
471
487
setIsTab ( "draw" ) ;
488
+ setSignatureType ( "draw" ) ;
472
489
setSignValue ( "" ) ;
473
490
setIsStamp ( false ) ;
474
491
} }
0 commit comments