default student's country to educator's during reg

Ideally the classroom info would include the country code, not just the
country name. Since it doesn't, this change includes a new function to
look up a country code by the country's name (not label).
This commit is contained in:
Christopher Willis-Ford 2020-05-02 00:44:20 -07:00
parent 7a17ed0789
commit 1408b540e1
2 changed files with 10 additions and 2 deletions

View file

@ -453,7 +453,7 @@ class DemographicsStep extends React.Component {
handleChooseGender (name, gender) {
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) {
if (values.countryCode) {
const countryInfo = countryData.lookupCountryInfo(values.countryCode);
@ -463,6 +463,12 @@ class DemographicsStep extends React.Component {
}
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) {
const countryName = this.getCountryName(formData);
if (countryName && formData.user) {
@ -573,7 +579,7 @@ class DemographicsStep extends React.Component {
validations={{
countryVal: values => this.countryValidator(values)
}}
value={countryOptions[0].value}
value={this.getCountryCode(this.props.countryName) || countryOptions[0].value}
/>
<Checkbox
className="demographics-checkbox-is-robot"
@ -598,6 +604,7 @@ class DemographicsStep extends React.Component {
DemographicsStep.propTypes = {
activeStep: PropTypes.number,
birthOffset: PropTypes.number,
countryName: PropTypes.string, // like 'United States', not 'US' or 'United States of America'
description: PropTypes.string,
intl: intlShape,
onNextStep: PropTypes.func,

View file

@ -132,6 +132,7 @@ class StudentRegistration extends React.Component {
onNextStep={this.handleAdvanceStep}
/>
<Steps.DemographicsStep
countryName={this.state.classroom && this.state.classroom.educator.profile.country}
description={this.props.intl.formatMessage({
id: 'registration.studentPersonalStepDescription'
})}