From 1408b540e188e30750963c44e8439362c0cb3016 Mon Sep 17 00:00:00 2001
From: Christopher Willis-Ford <7019101+cwillisf@users.noreply.github.com>
Date: Sat, 2 May 2020 00:44:20 -0700
Subject: [PATCH 1/2] 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).
---
src/components/registration/steps.jsx | 11 +++++++++--
src/views/studentregistration/studentregistration.jsx | 1 +
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/src/components/registration/steps.jsx b/src/components/registration/steps.jsx
index 42bdb2db4..113777ef9 100644
--- a/src/components/registration/steps.jsx
+++ b/src/components/registration/steps.jsx
@@ -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}
/>
Date: Wed, 13 May 2020 13:20:36 -0400
Subject: [PATCH 2/2] safer referencing of teacher country
---
src/views/studentregistration/studentregistration.jsx | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/views/studentregistration/studentregistration.jsx b/src/views/studentregistration/studentregistration.jsx
index 3129e6e71..1fb77d87e 100644
--- a/src/views/studentregistration/studentregistration.jsx
+++ b/src/views/studentregistration/studentregistration.jsx
@@ -132,7 +132,8 @@ class StudentRegistration extends React.Component {
onNextStep={this.handleAdvanceStep}
/>