mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-26 00:58:14 -05:00
Merge pull request #3856 from cwillisf/day1-student-country-default
default student's country to educator's during reg
This commit is contained in:
commit
1bab2bb59a
2 changed files with 11 additions and 2 deletions
|
@ -453,7 +453,7 @@ class DemographicsStep extends React.Component {
|
||||||
handleChooseGender (name, gender) {
|
handleChooseGender (name, gender) {
|
||||||
this.setState({otherDisabled: gender !== 'other'});
|
this.setState({otherDisabled: gender !== 'other'});
|
||||||
}
|
}
|
||||||
// look up country name using user's country code selection
|
// look up country name using user's country code selection ('us' -> 'United States')
|
||||||
getCountryName (values) {
|
getCountryName (values) {
|
||||||
if (values.countryCode) {
|
if (values.countryCode) {
|
||||||
const countryInfo = countryData.lookupCountryInfo(values.countryCode);
|
const countryInfo = countryData.lookupCountryInfo(values.countryCode);
|
||||||
|
@ -463,6 +463,12 @@ class DemographicsStep extends React.Component {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
// look up country code from country label ('United States' -> 'us')
|
||||||
|
// if `countryName` is not found, including if it's null or undefined, then this function will return undefined.
|
||||||
|
getCountryCode (countryName) {
|
||||||
|
const country = countryData.countryInfo.find(countryItem => countryItem.name === countryName);
|
||||||
|
return country && country.code;
|
||||||
|
}
|
||||||
handleValidSubmit (formData) {
|
handleValidSubmit (formData) {
|
||||||
const countryName = this.getCountryName(formData);
|
const countryName = this.getCountryName(formData);
|
||||||
if (countryName && formData.user) {
|
if (countryName && formData.user) {
|
||||||
|
@ -573,7 +579,7 @@ class DemographicsStep extends React.Component {
|
||||||
validations={{
|
validations={{
|
||||||
countryVal: values => this.countryValidator(values)
|
countryVal: values => this.countryValidator(values)
|
||||||
}}
|
}}
|
||||||
value={countryOptions[0].value}
|
value={this.getCountryCode(this.props.countryName) || countryOptions[0].value}
|
||||||
/>
|
/>
|
||||||
<Checkbox
|
<Checkbox
|
||||||
className="demographics-checkbox-is-robot"
|
className="demographics-checkbox-is-robot"
|
||||||
|
@ -598,6 +604,7 @@ class DemographicsStep extends React.Component {
|
||||||
DemographicsStep.propTypes = {
|
DemographicsStep.propTypes = {
|
||||||
activeStep: PropTypes.number,
|
activeStep: PropTypes.number,
|
||||||
birthOffset: PropTypes.number,
|
birthOffset: PropTypes.number,
|
||||||
|
countryName: PropTypes.string, // like 'United States', not 'US' or 'United States of America'
|
||||||
description: PropTypes.string,
|
description: PropTypes.string,
|
||||||
intl: intlShape,
|
intl: intlShape,
|
||||||
onNextStep: PropTypes.func,
|
onNextStep: PropTypes.func,
|
||||||
|
|
|
@ -132,6 +132,8 @@ class StudentRegistration extends React.Component {
|
||||||
onNextStep={this.handleAdvanceStep}
|
onNextStep={this.handleAdvanceStep}
|
||||||
/>
|
/>
|
||||||
<Steps.DemographicsStep
|
<Steps.DemographicsStep
|
||||||
|
countryName={this.state.classroom && this.state.classroom.educator &&
|
||||||
|
this.state.classroom.educator.profile && this.state.classroom.educator.profile.country}
|
||||||
description={this.props.intl.formatMessage({
|
description={this.props.intl.formatMessage({
|
||||||
id: 'registration.studentPersonalStepDescription'
|
id: 'registration.studentPersonalStepDescription'
|
||||||
})}
|
})}
|
||||||
|
|
Loading…
Reference in a new issue