1
- import React , { useState , useEffect } from "react" ;
1
+ import React , { useState , useEffect , useRef } from "react" ;
2
2
import { Navigate , useNavigate } from "react-router-dom" ;
3
3
import Parse from "parse" ;
4
4
import { SaveFileSize } from "../constant/saveFileSize" ;
@@ -28,8 +28,9 @@ function UserProfile() {
28
28
const [ isDisableDocId , setIsDisableDocId ] = useState ( false ) ;
29
29
const [ isSubscribe , setIsSubscribe ] = useState ( false ) ;
30
30
const [ publicUserName , setPublicUserName ] = useState (
31
- ( extendUser && extendUser ?. [ 0 ] ?. UserName ) || ""
31
+ extendUser && extendUser ?. [ 0 ] ?. UserName
32
32
) ;
33
+ const previousStateValueRef = useRef ( publicUserName ) ;
33
34
const [ company , setCompany ] = useState (
34
35
extendUser && extendUser ?. [ 0 ] ?. Company
35
36
) ;
@@ -81,8 +82,8 @@ function UserProfile() {
81
82
82
83
const handleCheckPublicUserName = async ( ) => {
83
84
try {
84
- const res = await Parse . Cloud . run ( "getPublicUserName " , {
85
- userName : publicUserName
85
+ const res = await Parse . Cloud . run ( "getpublicusername " , {
86
+ username : publicUserName
86
87
} ) ;
87
88
if ( res ) {
88
89
setIsLoader ( false ) ;
@@ -98,15 +99,19 @@ function UserProfile() {
98
99
} ;
99
100
const handleSubmit = async ( e ) => {
100
101
e . preventDefault ( ) ;
101
- setIsLoader ( true ) ;
102
- let phn = Phone ;
103
102
104
- const res = await handleCheckPublicUserName ( ) ;
103
+ let phn = Phone ,
104
+ res ;
105
+
106
+ if ( previousStateValueRef . current !== publicUserName ) {
107
+ res = await handleCheckPublicUserName ( ) ;
108
+ }
109
+
105
110
if ( ! res ) {
111
+ setIsLoader ( true ) ;
106
112
try {
107
- const tour = Parse . Object . extend ( "_User" ) ;
108
- const query = new Parse . Query ( tour ) ;
109
-
113
+ const userQuery = Parse . Object . extend ( "_User" ) ;
114
+ const query = new Parse . Query ( userQuery ) ;
110
115
await query . get ( UserProfile . objectId ) . then ( ( object ) => {
111
116
object . set ( "name" , name ) ;
112
117
object . set ( "ProfilePic" , Image ) ;
@@ -148,15 +153,26 @@ function UserProfile() {
148
153
const extClass = localStorage . getItem ( "extended_class" ) ;
149
154
const extData = JSON . parse ( localStorage . getItem ( "Extand_Class" ) ) ;
150
155
const ExtUserId = extData [ 0 ] . objectId ;
156
+ let body ;
157
+ if ( publicUserName ) {
158
+ body = {
159
+ Phone : obj . Phone ,
160
+ Name : obj . Name ,
161
+ HeaderDocId : isDisableDocId ,
162
+ JobTitle : jobTitle ,
163
+ Company : company ,
164
+ UserName : publicUserName
165
+ } ;
166
+ } else {
167
+ body = {
168
+ Phone : obj . Phone ,
169
+ Name : obj . Name ,
170
+ HeaderDocId : isDisableDocId ,
171
+ JobTitle : jobTitle ,
172
+ Company : company
173
+ } ;
174
+ }
151
175
152
- const body = {
153
- Phone : obj . Phone ,
154
- Name : obj . Name ,
155
- HeaderDocId : isDisableDocId ,
156
- JobTitle : jobTitle ,
157
- Company : company ,
158
- UserName : publicUserName
159
- } ;
160
176
await axios . put (
161
177
parseBaseUrl + "classes/" + extClass + "/" + ExtUserId ,
162
178
body ,
@@ -267,7 +283,15 @@ function UserProfile() {
267
283
alert ( "OTP sent on you email" ) ;
268
284
} ;
269
285
const handlePublicUrl = ( e ) => {
270
- setPublicUserName ( e . target . value ) ;
286
+ const value = e . target . value ;
287
+ if ( value . length > 6 && ! isSubscribe ) {
288
+ setUserNameError ( "Please upgrade to allow more than 6 characters." ) ;
289
+ setTimeout ( ( ) => {
290
+ setUserNameError ( "" ) ;
291
+ } , 2000 ) ;
292
+ } else {
293
+ setPublicUserName ( e . target . value ) ;
294
+ }
271
295
} ;
272
296
return (
273
297
< React . Fragment >
@@ -291,10 +315,9 @@ function UserProfile() {
291
315
</ div >
292
316
) : (
293
317
< div className = "flex justify-center items-center w-full relative" >
294
- { /* <Alert type={alertMsg.type}>{alertMsg.message}</Alert> */ }
295
318
{ userNameError && (
296
319
< div
297
- className = { `z-[1000] fixed top-20 transform border-[1px] text-sm border-[#f0a8a8] bg-[#f4bebe] text-[#c42121] rounded py-[.75rem] px-[1.25rem]` }
320
+ className = { `z-[1000] fixed top-[50%] transform border-[1px] text-sm border-[#f0a8a8] bg-[#f4bebe] text-[#c42121] rounded py-[.75rem] px-[1.25rem]` }
298
321
>
299
322
{ userNameError }
300
323
</ div >
@@ -426,20 +449,22 @@ function UserProfile() {
426
449
) }
427
450
</ span >
428
451
</ li >
429
- < li className = "flex justify-between items-center border-t-[1px] border-gray-300 py-2 break-all" >
430
- < span className = "font-semibold" > Public profile:</ span >
431
- < div className = "flex items-center" >
432
- < span > opensign.me/</ span >
452
+ { ! isEnableSubscription && (
453
+ < li className = "flex justify-between items-center border-t-[1px] border-gray-300 py-2 break-all" >
454
+ < span className = "font-semibold" > Public profile:</ span >
455
+ < div className = "flex items-center" >
456
+ < span > opensign.me/</ span >
433
457
434
- < input
435
- onChange = { handlePublicUrl }
436
- value = { publicUserName }
437
- disabled = { ! editmode }
438
- placeholder = "enter user name"
439
- className = "border-[1px] border-gray-200 rounded-[3px]"
440
- />
441
- </ div >
442
- </ li >
458
+ < input
459
+ onChange = { handlePublicUrl }
460
+ value = { publicUserName }
461
+ disabled = { ! editmode }
462
+ placeholder = "enter user name"
463
+ className = "border-[1px] border-gray-200 rounded-[3px]"
464
+ />
465
+ </ div >
466
+ </ li >
467
+ ) }
443
468
444
469
< li className = "border-y-[1px] border-gray-300 break-all" >
445
470
< div className = "flex justify-between items-center py-2" >
0 commit comments