mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2025-02-17 00:21:20 -05:00
Use iso-31660-2 package for country data
This commit is contained in:
parent
9da2bb29a8
commit
f126a71336
3 changed files with 30 additions and 10 deletions
|
@ -48,6 +48,7 @@
|
|||
"git-bundle-sha": "0.0.2",
|
||||
"glob": "5.0.15",
|
||||
"google-libphonenumber": "1.0.21",
|
||||
"iso-3166-2": "0.4.0",
|
||||
"json-loader": "0.5.2",
|
||||
"json2po-stream": "1.0.3",
|
||||
"jsx-loader": "0.13.2",
|
||||
|
|
8
src/lib/country-data.js
Normal file
8
src/lib/country-data.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
module.exports = {};
|
||||
var countries = module.exports.data = require('iso-3166-2').data;
|
||||
|
||||
var asOptions = module.exports.asOptions = Object.keys(countries).map(function (code) {
|
||||
return {value: code.toLowerCase(), label: countries[code].name};
|
||||
}).sort(function (a, b) {
|
||||
return a.label < b.label ? -1 : 1;
|
||||
});
|
|
@ -1,5 +1,7 @@
|
|||
var React = require('react');
|
||||
|
||||
var countryOptions = require('../../lib/country-data').asOptions;
|
||||
|
||||
var Button = require('../../components/forms/button.jsx');
|
||||
var Checkbox = require('../../components/forms/checkbox.jsx');
|
||||
var CheckboxGroup = require('../../components/forms/checkbox-group.jsx');
|
||||
|
@ -11,7 +13,7 @@ var RadioGroup = require('../../components/forms/radio-group.jsx');
|
|||
var Select = require('../../components/forms/select.jsx');
|
||||
var TextArea = require('../../components/forms/textarea.jsx');
|
||||
|
||||
var COUNTRIES = require('./countries.json');
|
||||
var DEFAULT_COUNTRY = 'us';
|
||||
|
||||
module.exports = {
|
||||
UsernameStep: React.createClass({
|
||||
|
@ -66,6 +68,9 @@ module.exports = {
|
|||
}
|
||||
}),
|
||||
DemographicsStep: React.createClass({
|
||||
getDefaultProps: function () {
|
||||
return {defaultCountry: DEFAULT_COUNTRY};
|
||||
},
|
||||
getInitialState: function () {
|
||||
return {otherDisabled: true};
|
||||
},
|
||||
|
@ -73,9 +78,6 @@ module.exports = {
|
|||
this.setState({otherDisabled: gender !== 'other'});
|
||||
},
|
||||
render: function () {
|
||||
var countryOptions = Object.keys(COUNTRIES).map(function (code) {
|
||||
return {value: code, label: COUNTRIES[code]};
|
||||
});
|
||||
var monthOptions = [
|
||||
'January', 'February', 'March', 'April', 'May', 'June', 'July',
|
||||
'August', 'September', 'October', 'November', 'December'
|
||||
|
@ -109,7 +111,7 @@ module.exports = {
|
|||
<Select label="Country"
|
||||
name="user.country"
|
||||
options={countryOptions}
|
||||
value={countryOptions[0].value}
|
||||
value={this.props.defaultCountry}
|
||||
required />
|
||||
<Button type="submit">Next Step</Button>
|
||||
</Form>
|
||||
|
@ -136,6 +138,9 @@ module.exports = {
|
|||
}
|
||||
}),
|
||||
PhoneNumberStep: React.createClass({
|
||||
getDefaultProps: function () {
|
||||
return {defaultCountry: DEFAULT_COUNTRY};
|
||||
},
|
||||
render: function () {
|
||||
return (
|
||||
<FormStep title="Phone Number"
|
||||
|
@ -147,7 +152,10 @@ module.exports = {
|
|||
<Form onValidSubmit={this.props.onNextStep}>
|
||||
<PhoneInput label="Phone Number"
|
||||
name="phone"
|
||||
defaultCountry={this.props.formData.user && this.props.formData.user.country}
|
||||
defaultCountry={
|
||||
(this.props.formData.user && this.props.formData.user.country) ||
|
||||
this.props.defaultCountry
|
||||
}
|
||||
required />
|
||||
<Checkbox label={
|
||||
'Yes, I consent to lorem ipsum dolor sit amet, consectetur' +
|
||||
|
@ -206,10 +214,10 @@ module.exports = {
|
|||
}
|
||||
}),
|
||||
AddressStep: React.createClass({
|
||||
getDefaultProps: function () {
|
||||
return {defaultCountry: DEFAULT_COUNTRY};
|
||||
},
|
||||
render: function () {
|
||||
var countryOptions = Object.keys(COUNTRIES).map(function (code) {
|
||||
return {value: code, label: COUNTRIES[code]};
|
||||
});
|
||||
var stateOptions = ['every','state','in','the','world'].map(function (name) {
|
||||
return {value: name, label: name};
|
||||
});
|
||||
|
@ -226,7 +234,10 @@ module.exports = {
|
|||
<Select label="Country"
|
||||
name="address.country"
|
||||
options={countryOptions}
|
||||
value={this.props.formData.user && this.props.formData.user.country}
|
||||
value={
|
||||
(this.props.formData.user && this.props.formData.user.country) ||
|
||||
this.props.defaultCountry
|
||||
}
|
||||
required />
|
||||
<Input label="Address Line 1" type="text" name="address.line1" required />
|
||||
<Input label="Address Line 2" type="text" name="address.line2" />
|
||||
|
|
Loading…
Reference in a new issue