@@ -46,6 +46,7 @@ import { getTraits, scrollToTop, isProfileFormDataEmpty } from "utils/";
46
46
import moment from "moment" ;
47
47
import _ from "lodash" ;
48
48
import { createTraits , updateTraits } from "services/traits" ;
49
+ import { updateMemberData } from "services/memberData" ;
49
50
50
51
const formatDate = ( date ) => {
51
52
let ret = new Date (
@@ -59,12 +60,13 @@ const BuildMyProfile = () => {
59
60
const authUser = useSelector ( ( state ) => state . authUser ) ;
60
61
const [ isLoading , setIsLoading ] = useState ( false ) ;
61
62
const [ myProfileData , setMyProfileData ] = useState ( { } ) ;
63
+ const [ bio , setBio ] = useState ( "" ) ;
64
+
62
65
// form states
63
66
const [ formData , setFormData ] = useState ( {
64
67
title : "" ,
65
- bio : "" ,
66
68
} ) ;
67
- const { title, bio } = formData ;
69
+ const { title } = formData ;
68
70
// get an empty job item
69
71
const emptyJob = ( ) => ( {
70
72
company : "" ,
@@ -190,6 +192,7 @@ const BuildMyProfile = () => {
190
192
getAuthUserProfile ( )
191
193
. then ( ( result ) => {
192
194
setMyProfileData ( result ) ;
195
+ setBio ( result . description ) ;
193
196
} )
194
197
. catch ( ( e ) => {
195
198
// eslint-disable-next-line no-console
@@ -218,11 +221,10 @@ const BuildMyProfile = () => {
218
221
// fill title and bio to state
219
222
if ( basicInfoValue ) {
220
223
// Using shortBio as title has to do with v3 using this mapping
221
- const { description , shortBio : title } = basicInfoValue ;
224
+ const { shortBio : title } = basicInfoValue ;
222
225
setFormData ( ( formData ) => ( {
223
226
...formData ,
224
227
title : title || "" ,
225
- bio : description || "" ,
226
228
} ) ) ;
227
229
}
228
230
if ( workExpValue ) {
@@ -273,16 +275,15 @@ const BuildMyProfile = () => {
273
275
scrollToTop ( ) ;
274
276
} , [ ] ) ;
275
277
276
- // save title / bio
277
- const getTitleAndBioData = ( basicInfo ) => {
278
- const { title, bio } = formData ;
278
+ // save title
279
+ const getTitle = ( basicInfo ) => {
280
+ const { title } = formData ;
279
281
// mapped data
280
282
let data = {
281
283
shortBio : title ,
282
- description : bio ,
283
284
} ;
284
285
// check if basic info already exists. if so, update(put data). otherwise, post data.
285
- if ( basicInfo == null && isProfileFormDataEmpty ( "bio " , data ) ) {
286
+ if ( basicInfo == null && isProfileFormDataEmpty ( "title " , data ) ) {
286
287
return {
287
288
action : "create" ,
288
289
data : {
@@ -293,10 +294,8 @@ const BuildMyProfile = () => {
293
294
} ,
294
295
} ,
295
296
} ;
296
- // return addMyTitleAndBio(authUser.handle, data);
297
297
} else {
298
298
if ( isProfileFormDataEmpty ( "bio" , data ) ) {
299
- // return updateMyTitleAndBio(authUser.handle, basicInfo, data);
300
299
return {
301
300
action : "update" ,
302
301
data : {
@@ -451,8 +450,6 @@ const BuildMyProfile = () => {
451
450
) ;
452
451
} ;
453
452
454
- // reach router, navigate programmatically
455
- const navigate = useNavigate ( ) ;
456
453
// on submit, save form and then navigate
457
454
const handleSubmit = async ( e ) => {
458
455
if ( ! canSubmit ( ) ) {
@@ -481,7 +478,7 @@ const BuildMyProfile = () => {
481
478
const functions = [
482
479
{
483
480
val : basicInfoTraits ,
484
- func : getTitleAndBioData ,
481
+ func : getTitle ,
485
482
} ,
486
483
{
487
484
val : workExperience ,
@@ -533,6 +530,10 @@ const BuildMyProfile = () => {
533
530
}
534
531
}
535
532
533
+ if ( myProfileData . description != bio && bio != null && bio . trim ( ) . length ) {
534
+ await updateMemberData ( authUser . handle , { description : bio } ) ;
535
+ }
536
+
536
537
setIsLoading ( false ) ;
537
538
window . location . href = config . TOPCODER_COMMUNITY_WEBSITE_URL + "/home" ;
538
539
} ;
@@ -598,9 +599,7 @@ const BuildMyProfile = () => {
598
599
placeholder = { "Enter your bio" }
599
600
value = { bio }
600
601
name = "bio"
601
- onChange = { ( e ) =>
602
- handleInputChange ( e . target . name , e . target . value )
603
- }
602
+ onChange = { ( e ) => setBio ( e . target . value ) }
604
603
/>
605
604
</ FormField >
606
605
</ div >
0 commit comments