@@ -15,12 +15,14 @@ import { PrimaryButton } from 'topcoder-react-ui-kit';
15
15
import ConsentComponent from 'components/Settings/ConsentComponent' ;
16
16
import Select from 'components/Select' ;
17
17
import DatePicker from 'components/challenge-listing/Filters/DatePicker' ;
18
+ import ErrorMessage from 'components/Settings/ErrorMessage' ;
18
19
import ImageInput from '../ImageInput' ;
19
20
import Track from './Track' ;
20
21
import DefaultImageInput from './ImageInput' ;
21
22
import dropdowns from './dropdowns.json' ;
22
23
import tracks from './tracks' ;
23
24
25
+
24
26
import './styles.scss' ;
25
27
26
28
export default class BasicInfo extends ConsentComponent {
@@ -41,7 +43,6 @@ export default class BasicInfo extends ConsentComponent {
41
43
this . state = {
42
44
inputChanged : false ,
43
45
formInvalid : false ,
44
- errorMessage : '' ,
45
46
basicInfoTrait : this . loadBasicInfoTraits ( userTraits ) ,
46
47
personalizationTrait : this . loadPersonalizationTrait ( userTraits ) ,
47
48
newBasicInfo : {
@@ -98,46 +99,26 @@ export default class BasicInfo extends ConsentComponent {
98
99
99
100
onCheckFormValue ( newBasicInfo ) {
100
101
let invalid = false ;
101
- let errorMessage = '' ;
102
- let dateError = '' ;
103
- let birthDateInvalid = false ;
104
- const invalidFields = [ ] ;
105
102
106
103
if ( ! _ . trim ( newBasicInfo . firstName ) . length ) {
107
- invalidFields . push ( 'First Name' ) ;
108
104
invalid = true ;
109
105
}
110
106
111
107
if ( ! _ . trim ( newBasicInfo . lastName ) . length ) {
112
- invalidFields . push ( 'Last Name' ) ;
113
108
invalid = true ;
114
109
}
115
110
116
111
if ( ! _ . trim ( newBasicInfo . country ) . length ) {
117
- invalidFields . push ( 'Country' ) ;
118
112
invalid = true ;
119
113
}
120
114
121
- if ( invalidFields . length > 0 ) {
122
- errorMessage += invalidFields . join ( ', ' ) ;
123
- errorMessage += ' cannot be empty' ;
124
- }
125
-
126
115
if ( _ . trim ( newBasicInfo . birthDate ) . length > 0 ) {
127
116
if ( ! moment ( ) . isAfter ( newBasicInfo . birthDate ) ) {
128
- dateError = 'You must enter a valid date for Birth Date' ;
129
- birthDateInvalid = true ;
117
+ invalid = true ;
130
118
}
131
119
}
132
120
133
- if ( errorMessage . length > 0 ) {
134
- errorMessage = `${ errorMessage } . ${ dateError } ` ;
135
- } else if ( dateError . length > 0 ) {
136
- errorMessage = dateError ;
137
- invalid = birthDateInvalid ;
138
- }
139
-
140
- this . setState ( { errorMessage, formInvalid : invalid } ) ;
121
+ this . setState ( { formInvalid : invalid } ) ;
141
122
return invalid ;
142
123
}
143
124
@@ -170,7 +151,7 @@ export default class BasicInfo extends ConsentComponent {
170
151
*/
171
152
onHandleSaveBasicInfo ( e ) {
172
153
e . preventDefault ( ) ;
173
- this . setState ( { isSaving : true } ) ;
154
+ this . setState ( { isSaving : true , inputChange : true } ) ;
174
155
const { newBasicInfo } = this . state ;
175
156
if ( this . onCheckFormValue ( newBasicInfo ) ) {
176
157
this . setState ( { isSaving : false } ) ;
@@ -465,8 +446,7 @@ export default class BasicInfo extends ConsentComponent {
465
446
render ( ) {
466
447
const {
467
448
newBasicInfo,
468
- formInvalid,
469
- errorMessage,
449
+ inputChanged,
470
450
} = this . state ;
471
451
472
452
const canModifyTrait = ! this . props . traitRequestCount ;
@@ -507,6 +487,7 @@ export default class BasicInfo extends ConsentComponent {
507
487
< div styleName = "field col-2" >
508
488
< span styleName = "text-required" > * Required</ span >
509
489
< input disabled = { ! canModifyTrait } id = "firstName" name = "firstName" type = "text" placeholder = "First Name" onChange = { this . onUpdateInput } value = { newBasicInfo . firstName } maxLength = "64" required />
490
+ < ErrorMessage invalid = { _ . isEmpty ( newBasicInfo . firstName ) && inputChanged } message = "First Name cannot be empty" />
510
491
</ div >
511
492
</ div >
512
493
< div styleName = "row" >
@@ -519,6 +500,7 @@ export default class BasicInfo extends ConsentComponent {
519
500
< div styleName = "field col-2" >
520
501
< span styleName = "text-required" > * Required</ span >
521
502
< input disabled = { ! canModifyTrait } id = "lastName" name = "lastName" type = "text" placeholder = "Last Name" onChange = { this . onUpdateInput } value = { newBasicInfo . lastName } maxLength = "64" required />
503
+ < ErrorMessage invalid = { _ . isEmpty ( newBasicInfo . lastName ) && inputChanged } message = "Last Name cannot be empty" />
522
504
</ div >
523
505
</ div >
524
506
< div styleName = "row" >
@@ -619,6 +601,7 @@ export default class BasicInfo extends ConsentComponent {
619
601
disabled = { ! canModifyTrait }
620
602
clearable = { false }
621
603
/>
604
+ < ErrorMessage invalid = { _ . isEmpty ( newBasicInfo . country ) && inputChanged } message = "Country cannot be empty" addMargin />
622
605
</ div >
623
606
</ div >
624
607
</ form >
@@ -745,6 +728,7 @@ export default class BasicInfo extends ConsentComponent {
745
728
</ label >
746
729
747
730
< input disabled = { ! canModifyTrait } id = "firstNameId" name = "firstName" type = "text" placeholder = "First Name" onChange = { this . onUpdateInput } value = { newBasicInfo . firstName } maxLength = "64" required />
731
+ < ErrorMessage invalid = { _ . isEmpty ( newBasicInfo . firstName ) && inputChanged } addMargin message = "First Name cannot be empty" />
748
732
</ div >
749
733
< div styleName = "field" >
750
734
< label htmlFor = "lastNameId" >
@@ -753,6 +737,7 @@ export default class BasicInfo extends ConsentComponent {
753
737
< input type = "hidden" />
754
738
</ label >
755
739
< input disabled = { ! canModifyTrait } id = "lastNameId" name = "lastName" type = "text" placeholder = "Last Name" onChange = { this . onUpdateInput } value = { newBasicInfo . lastName } maxLength = "64" required />
740
+ < ErrorMessage invalid = { _ . isEmpty ( newBasicInfo . lastName ) && inputChanged } addMargin message = "Last Name cannot be empty" />
756
741
</ div >
757
742
</ div >
758
743
</ div >
@@ -826,6 +811,7 @@ export default class BasicInfo extends ConsentComponent {
826
811
clearable = { false }
827
812
disabled = { ! canModifyTrait }
828
813
/>
814
+ < ErrorMessage invalid = { _ . isEmpty ( newBasicInfo . country ) && inputChanged } message = "Country cannot be empty" />
829
815
</ div >
830
816
</ div >
831
817
< div styleName = "row" >
@@ -931,9 +917,6 @@ export default class BasicInfo extends ConsentComponent {
931
917
}
932
918
</ div >
933
919
</ div >
934
- < div styleName = { `error-message ${ formInvalid ? 'active' : '' } ` } >
935
- { errorMessage }
936
- </ div >
937
920
< div styleName = "button-save" >
938
921
< PrimaryButton
939
922
styleName = "white-label"
0 commit comments