@@ -28,6 +28,8 @@ class ProfileSettingsForm extends Component {
2828 dirty : false ,
2929 businessPhoneValid : true ,
3030 countrySelected : null ,
31+ businessPhoneDirty : false ,
32+ countrySelectionDirty : false
3133 }
3234 this . onSubmit = this . onSubmit . bind ( this )
3335 this . onValid = this . onValid . bind ( this )
@@ -42,11 +44,12 @@ class ProfileSettingsForm extends Component {
4244 if ( country && country . value && this . state . countrySelected !== country . value ) {
4345 this . setState ( {
4446 countrySelected : country . value ,
47+ countrySelectionDirty : true
4548 } )
4649 }
4750 }
4851
49- onBusinessPhoneCountryChange ( { country } ) {
52+ onBusinessPhoneCountryChange ( { country, externalChange } ) {
5053 const { businessPhoneValid } = this . state
5154
5255 if ( country && country . code ) {
@@ -68,6 +71,15 @@ class ProfileSettingsForm extends Component {
6871 businessPhoneValid : false
6972 } )
7073 }
74+
75+ // external change means, the user didn't change the phone number field.
76+ // But it was automatically changed due to country selection change. In such case, we should show
77+ // the alert under country selection only.
78+ if ( ! externalChange ) {
79+ this . setState ( {
80+ businessPhoneDirty : true
81+ } )
82+ }
7183 }
7284
7385 getField ( label , name , isRequired = false ) {
@@ -108,6 +120,11 @@ class ProfileSettingsForm extends Component {
108120 ...data ,
109121 }
110122 this . props . saveSettings ( updatedData )
123+
124+ this . setState ( {
125+ businessPhoneDirty : false ,
126+ countrySelectionDirty : false
127+ } )
111128 }
112129
113130 onValid ( ) {
@@ -167,7 +184,10 @@ class ProfileSettingsForm extends Component {
167184 value = { this . props . values . settings . businessPhone }
168185 onChangeCountry = { this . onBusinessPhoneCountryChange }
169186 />
170- < div styleName = "warningText" > Note: Changing the country code also updates your country selection</ div >
187+ {
188+ this . state . businessPhoneDirty &&
189+ < div styleName = "warningText" > Note: Changing the country code also updates your country selection</ div >
190+ }
171191 </ div >
172192 </ div >
173193 { this . getField ( 'Company name' , 'companyName' , true ) }
@@ -219,7 +239,10 @@ class ProfileSettingsForm extends Component {
219239 showDropdownIndicator
220240 setValueOnly
221241 />
222- < div styleName = "warningText" > Note: Changing the country also updates the country code of business phone.</ div >
242+ {
243+ this . state . countrySelectionDirty &&
244+ < div styleName = "warningText" > Note: Changing the country also updates the country code of business phone.</ div >
245+ }
223246 </ div >
224247 </ div >
225248 < div className = "controls" >
0 commit comments