@@ -32,6 +32,7 @@ class ProfileSettings extends ConsentComponent {
32
32
this . onUpdateCountry = this . onUpdateCountry . bind ( this ) ;
33
33
this . onUpdateInput = this . onUpdateInput . bind ( this ) ;
34
34
this . onUpdateDate = this . onUpdateDate . bind ( this ) ;
35
+ this . onSaveProfile = this . onSaveProfile . bind ( this ) ;
35
36
this . onHandleSaveBasicInfo = this . onHandleSaveBasicInfo . bind ( this ) ;
36
37
this . onSaveBasicInfo = this . onSaveBasicInfo . bind ( this ) ;
37
38
this . onChange = this . onChange . bind ( this ) ;
@@ -80,6 +81,7 @@ class ProfileSettings extends ConsentComponent {
80
81
graduated : false ,
81
82
} ,
82
83
isSubmit : false ,
84
+ educationInputChanged : false ,
83
85
isMobileView : false ,
84
86
screenSM : 767 ,
85
87
isEdit : false ,
@@ -113,6 +115,7 @@ class ProfileSettings extends ConsentComponent {
113
115
isSubmitHobby : false ,
114
116
indexNoHobby : null ,
115
117
isHobbyEdit : false ,
118
+ hobbyInputChanged : false ,
116
119
newHobby : {
117
120
hobby : '' ,
118
121
description : '' ,
@@ -240,38 +243,19 @@ class ProfileSettings extends ConsentComponent {
240
243
onHandleSaveBasicInfo ( e ) {
241
244
if ( e ) e . preventDefault ( ) ;
242
245
const { setIsSaving } = this . props ;
243
- this . setState ( { inputChange : true , isSubmit : true , isSubmitHobby : true } ) ;
246
+ this . setState ( { inputChange : true } ) ;
244
247
setIsSaving ( true ) ;
245
248
const {
246
- newBasicInfo, newProfileInfo, newEducation , newHobby ,
249
+ newBasicInfo, newProfileInfo,
247
250
} = this . state ;
248
-
249
- if ( ! _ . isEmpty ( newEducation . timePeriodFrom )
250
- && ! _ . isEmpty ( newEducation . timePeriodTo )
251
- && _ . trim ( newEducation . schoolCollegeName ) . length
252
- ) {
253
- this . setState ( { isSubmit : true } ) ;
254
- if ( this . onCheckEducationFormValue ( newEducation ) ) {
255
- setIsSaving ( false ) ;
256
- return ;
257
- }
258
- }
259
-
260
- if ( ! this . onCheckEducationFormValue ( newEducation ) ) {
261
- this . showConsent ( this . onAddEducation . bind ( this ) ) ;
262
- }
263
-
264
- if ( ! this . onCheckFormValueHobby ( newHobby ) ) {
265
- this . showConsent ( this . onAddHobby . bind ( this ) ) ;
266
- }
267
-
268
- if ( ! this . onCheckFormValue ( newBasicInfo , newProfileInfo ) ) {
269
- this . showConsent ( this . onSaveBasicInfo . bind ( this ) ) ;
270
- } else {
251
+ if ( this . onCheckFormValue ( newBasicInfo , newProfileInfo ) ) {
271
252
setIsSaving ( false ) ;
253
+ return ;
272
254
}
255
+ this . showConsent ( this . onSaveBasicInfo . bind ( this ) ) ;
273
256
}
274
257
258
+
275
259
/**
276
260
* Save Basic Info
277
261
* @param answer user consent answer value
@@ -354,6 +338,49 @@ class ProfileSettings extends ConsentComponent {
354
338
this . props . setIsSaving ( false ) ;
355
339
}
356
340
341
+ /**
342
+ * Save Changes
343
+ */
344
+ onSaveProfile ( ) {
345
+ const { isSaving, setIsSaving } = this . props ;
346
+ const {
347
+ inputChanged,
348
+ educationInputChanged,
349
+ hobbyInputChanged,
350
+ newBasicInfo,
351
+ newProfileInfo,
352
+ newEducation,
353
+ newHobby,
354
+ } = this . state ;
355
+
356
+ if ( isSaving ) {
357
+ return ;
358
+ }
359
+
360
+ let valid = true ;
361
+ let dirty ;
362
+
363
+ if ( inputChanged ) {
364
+ dirty = true ;
365
+ valid = valid && ! this . onCheckFormValue ( newBasicInfo , newProfileInfo ) ;
366
+ this . onHandleSaveBasicInfo ( ) ;
367
+ }
368
+
369
+ if ( educationInputChanged ) {
370
+ dirty = true ;
371
+ valid = valid && ! this . onCheckEducationFormValue ( newEducation ) ;
372
+ this . onHandleAddEducation ( ) ;
373
+ }
374
+
375
+ if ( hobbyInputChanged ) {
376
+ dirty = true ;
377
+ valid = valid && ! this . onCheckFormValueHobby ( newHobby ) ;
378
+ this . onHandleAddHobby ( ) ;
379
+ }
380
+
381
+ if ( valid && dirty ) setIsSaving ( true ) ;
382
+ }
383
+
357
384
onUpdateInput ( e ) {
358
385
const { newBasicInfo : oldBasicInfo , newProfileInfo : oldProfileInfo } = this . state ;
359
386
const newBasicInfo = { ...oldBasicInfo } ;
@@ -582,7 +609,7 @@ class ProfileSettings extends ConsentComponent {
582
609
const { newEducation : oldEducation } = this . state ;
583
610
const newEducation = { ...oldEducation } ;
584
611
newEducation [ timePeriod ] = date || '' ;
585
- this . setState ( { newEducation, isSubmit : false } ) ;
612
+ this . setState ( { newEducation, isSubmit : false , educationInputChanged : true } ) ;
586
613
}
587
614
588
615
/**
@@ -705,6 +732,7 @@ class ProfileSettings extends ConsentComponent {
705
732
newEducation : empty ,
706
733
isEdit : false ,
707
734
indexNo : null ,
735
+ educationInputChanged : false ,
708
736
isSubmit : false ,
709
737
} ) ;
710
738
// save personalization
@@ -740,7 +768,7 @@ class ProfileSettings extends ConsentComponent {
740
768
}
741
769
}
742
770
743
- this . setState ( { newEducation, isSubmit : false } ) ;
771
+ this . setState ( { newEducation, isSubmit : false , educationInputChanged : true } ) ;
744
772
}
745
773
746
774
/**
@@ -800,7 +828,7 @@ class ProfileSettings extends ConsentComponent {
800
828
* @param e event
801
829
*/
802
830
onHandleAddHobby ( e ) {
803
- e . preventDefault ( ) ;
831
+ if ( e ) e . preventDefault ( ) ;
804
832
const { newHobby } = this . state ;
805
833
this . setState ( { isSubmitHobby : true } ) ;
806
834
if ( this . onCheckFormValueHobby ( newHobby ) ) {
@@ -905,7 +933,7 @@ class ProfileSettings extends ConsentComponent {
905
933
newHobby : empty ,
906
934
isHobbyEdit : false ,
907
935
indexNoHobby : null ,
908
- inputChanged : false ,
936
+ hobbyInputChanged : false ,
909
937
} ) ;
910
938
911
939
// save personalization
@@ -929,7 +957,7 @@ class ProfileSettings extends ConsentComponent {
929
957
const { newHobby : oldHobby } = this . state ;
930
958
const newHobby = { ...oldHobby } ;
931
959
newHobby [ e . target . name ] = e . target . value ;
932
- this . setState ( { newHobby, isSubmitHobby : false } ) ;
960
+ this . setState ( { newHobby, isSubmitHobby : false , hobbyInputChanged : true } ) ;
933
961
}
934
962
935
963
/**
@@ -1146,7 +1174,7 @@ class ProfileSettings extends ConsentComponent {
1146
1174
< div styleName = "footer" >
1147
1175
< PrimaryButton
1148
1176
disabled = { ! canModifyTrait }
1149
- onClick = { this . onHandleSaveBasicInfo }
1177
+ onClick = { this . onSaveProfile }
1150
1178
theme = { {
1151
1179
button : style [ 'save-changes-btn' ] ,
1152
1180
} }
0 commit comments