mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-30 02:56:20 -05:00
handle error when teacher country selection fails to resolve to country name
This commit is contained in:
parent
51aa38fb34
commit
564baf2ebc
2 changed files with 28 additions and 7 deletions
|
@ -408,10 +408,14 @@ class DemographicsStep extends React.Component {
|
||||||
constructor (props) {
|
constructor (props) {
|
||||||
super(props);
|
super(props);
|
||||||
bindAll(this, [
|
bindAll(this, [
|
||||||
|
'birthDateValidator',
|
||||||
|
'countryValidator',
|
||||||
|
'getCountryName',
|
||||||
'getMonthOptions',
|
'getMonthOptions',
|
||||||
'getYearOptions',
|
'getYearOptions',
|
||||||
'handleChooseGender',
|
'handleChooseGender',
|
||||||
'handleValidSubmit'
|
'handleValidSubmit',
|
||||||
|
'isValidBirthdate'
|
||||||
]);
|
]);
|
||||||
this.state = {
|
this.state = {
|
||||||
otherDisabled: true
|
otherDisabled: true
|
||||||
|
@ -435,16 +439,24 @@ class DemographicsStep extends React.Component {
|
||||||
handleChooseGender (name, gender) {
|
handleChooseGender (name, gender) {
|
||||||
this.setState({otherDisabled: gender !== 'other'});
|
this.setState({otherDisabled: gender !== 'other'});
|
||||||
}
|
}
|
||||||
handleValidSubmit (formData) {
|
|
||||||
// look up country name using user's country code selection
|
// look up country name using user's country code selection
|
||||||
if (formData.countryCode) {
|
getCountryName (values) {
|
||||||
const countryInfo = countryData.lookupCountryInfo(formData.countryCode);
|
if (values.countryCode) {
|
||||||
|
const countryInfo = countryData.lookupCountryInfo(values.countryCode);
|
||||||
if (countryInfo) {
|
if (countryInfo) {
|
||||||
formData.user.country = countryInfo.name;
|
return countryInfo.name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
handleValidSubmit (formData) {
|
||||||
|
const countryName = this.getCountryName(formData);
|
||||||
|
if (countryName && formData.user) {
|
||||||
|
formData.user.country = countryName;
|
||||||
return this.props.onNextStep(formData);
|
return this.props.onNextStep(formData);
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
isValidBirthdate (year, month) {
|
isValidBirthdate (year, month) {
|
||||||
const birthdate = new Date(
|
const birthdate = new Date(
|
||||||
year,
|
year,
|
||||||
|
@ -457,6 +469,11 @@ class DemographicsStep extends React.Component {
|
||||||
const isValid = this.isValidBirthdate(values['user.birth.year'], values['user.birth.month']);
|
const isValid = this.isValidBirthdate(values['user.birth.year'], values['user.birth.month']);
|
||||||
return isValid ? true : this.props.intl.formatMessage({id: 'teacherRegistration.validationAge'});
|
return isValid ? true : this.props.intl.formatMessage({id: 'teacherRegistration.validationAge'});
|
||||||
}
|
}
|
||||||
|
countryValidator (values) {
|
||||||
|
const countryName = this.getCountryName(values);
|
||||||
|
if (countryName) return true;
|
||||||
|
return this.props.intl.formatMessage({id: 'general.invalidSelection'});
|
||||||
|
}
|
||||||
render () {
|
render () {
|
||||||
const countryOptions = getCountryOptions(this.props.intl);
|
const countryOptions = getCountryOptions(this.props.intl);
|
||||||
return (
|
return (
|
||||||
|
@ -539,6 +556,9 @@ class DemographicsStep extends React.Component {
|
||||||
label={this.props.intl.formatMessage({id: 'general.country'})}
|
label={this.props.intl.formatMessage({id: 'general.country'})}
|
||||||
name="countryCode"
|
name="countryCode"
|
||||||
options={countryOptions}
|
options={countryOptions}
|
||||||
|
validations={{
|
||||||
|
countryVal: values => this.countryValidator(values)
|
||||||
|
}}
|
||||||
value={countryOptions[0].value}
|
value={countryOptions[0].value}
|
||||||
/>
|
/>
|
||||||
<Checkbox
|
<Checkbox
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
"general.getStarted": "Get Started",
|
"general.getStarted": "Get Started",
|
||||||
"general.gender": "Gender",
|
"general.gender": "Gender",
|
||||||
"general.guidelines": "Community Guidelines",
|
"general.guidelines": "Community Guidelines",
|
||||||
|
"general.invalidSelection": "Invalid selection",
|
||||||
"general.jobs": "Jobs",
|
"general.jobs": "Jobs",
|
||||||
"general.joinScratch": "Join Scratch",
|
"general.joinScratch": "Join Scratch",
|
||||||
"general.legal": "Legal",
|
"general.legal": "Legal",
|
||||||
|
|
Loading…
Reference in a new issue