Move countryOptions to the global scope

thanks @rschamp!
This commit is contained in:
Matthew Taylor 2016-07-28 08:30:29 -04:00
parent cf4a057278
commit 2650e6e148

View file

@ -27,6 +27,17 @@ var Tooltip = require('../../components/tooltip/tooltip.jsx');
require('./steps.scss'); require('./steps.scss');
var DEFAULT_COUNTRY = 'us'; var DEFAULT_COUNTRY = 'us';
var COUNTRY_OPTIONS = countryData.countryOptions.concat({
label: <intl.FormattedMessage id="teacherRegistration.selectCountry" />,
disabled: true,
selected: true
}).sort(function (a, b) {
if (a.disabled) return -1;
if (b.disabled) return 1;
if (a.value === DEFAULT_COUNTRY) return -1;
if (b.value === DEFAULT_COUNTRY) return 1;
return 0;
}.bind(this));
var NextStepButton = React.createClass({ var NextStepButton = React.createClass({
getDefaultProps: function () { getDefaultProps: function () {
@ -253,7 +264,6 @@ module.exports = {
DemographicsStep: intl.injectIntl(React.createClass({ DemographicsStep: intl.injectIntl(React.createClass({
getDefaultProps: function () { getDefaultProps: function () {
return { return {
defaultCountry: DEFAULT_COUNTRY,
waiting: false, waiting: false,
description: null description: null
}; };
@ -282,17 +292,6 @@ module.exports = {
}, },
render: function () { render: function () {
var formatMessage = this.props.intl.formatMessage; var formatMessage = this.props.intl.formatMessage;
var countryOptions = countryData.countryOptions.concat({
label: formatMessage({id: 'teacherRegistration.selectCountry'}),
disabled: true,
selected: true
}).sort(function (a, b) {
if (a.disabled) return -1;
if (b.disabled) return 1;
if (a.value === this.props.defaultCountry) return -1;
if (b.value === this.props.defaultCountry) return 1;
return 0;
}.bind(this));
return ( return (
<Slide className="registration-step demographics-step"> <Slide className="registration-step demographics-step">
<h2> <h2>
@ -334,7 +333,7 @@ module.exports = {
</div> </div>
<Select label={formatMessage({id: 'general.country'})} <Select label={formatMessage({id: 'general.country'})}
name="user.country" name="user.country"
options={countryOptions} options={COUNTRY_OPTIONS}
required /> required />
<Checkbox className="demographics-checkbox-is-robot" <Checkbox className="demographics-checkbox-is-robot"
label="I'm a robot!" label="I'm a robot!"
@ -585,17 +584,6 @@ module.exports = {
var formatMessage = this.props.intl.formatMessage; var formatMessage = this.props.intl.formatMessage;
var stateOptions = countryData.subdivisionOptions[this.state.countryChoice]; var stateOptions = countryData.subdivisionOptions[this.state.countryChoice];
stateOptions = [{}].concat(stateOptions); stateOptions = [{}].concat(stateOptions);
var countryOptions = countryData.countryOptions.concat({
label: formatMessage({id: 'teacherRegistration.selectCountry'}),
disabled: true,
selected: true
}).sort(function (a, b) {
if (a.disabled) return -1;
if (b.disabled) return 1;
if (a.value === this.props.defaultCountry) return -1;
if (b.value === this.props.defaultCountry) return 1;
return 0;
}.bind(this));
return ( return (
<Slide className="registration-step address-step"> <Slide className="registration-step address-step">
<h2> <h2>
@ -610,7 +598,7 @@ module.exports = {
<Form onValidSubmit={this.onValidSubmit}> <Form onValidSubmit={this.onValidSubmit}>
<Select label={formatMessage({id: 'general.country'})} <Select label={formatMessage({id: 'general.country'})}
name="address.country" name="address.country"
options={countryOptions} options={COUNTRY_OPTIONS}
onChange={this.onChangeCountry} onChange={this.onChangeCountry}
required /> required />
<Input label={formatMessage({id: 'teacherRegistration.addressLine1'})} <Input label={formatMessage({id: 'teacherRegistration.addressLine1'})}