mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2025-02-17 08:31:23 -05:00
Base phone and address country on user country
This commit is contained in:
parent
3ea1c64184
commit
9da2bb29a8
2 changed files with 16 additions and 3 deletions
|
@ -2,11 +2,14 @@ var classNames = require('classnames');
|
|||
var React = require('react');
|
||||
var FormsyMixin = require('formsy-react').Mixin;
|
||||
var ReactPhoneInput = require('react-telephone-input/lib/withStyles');
|
||||
var allCountries = require('react-telephone-input/lib/country_data').allCountries;
|
||||
var defaultValidationHOC = require('./validations.jsx').defaultValidationHOC;
|
||||
var validationHOCFactory = require('./validations.jsx').validationHOCFactory;
|
||||
var Row = require('formsy-react-components').Row;
|
||||
var ComponentMixin = require('formsy-react-components').ComponentMixin;
|
||||
|
||||
var allIso2 = allCountries.map(function (country) {return country.iso2});
|
||||
|
||||
var PhoneInput = React.createClass({
|
||||
displayName: 'PhoneInput',
|
||||
mixins: [
|
||||
|
@ -18,7 +21,8 @@ var PhoneInput = React.createClass({
|
|||
validations: {
|
||||
isPhone: true
|
||||
},
|
||||
flagsImagePath: '/images/flags.png'
|
||||
flagsImagePath: '/images/flags.png',
|
||||
defaultCountry: 'us'
|
||||
};
|
||||
},
|
||||
onChangeInput: function (number, country) {
|
||||
|
@ -27,6 +31,10 @@ var PhoneInput = React.createClass({
|
|||
this.props.onChange(this.props.name, value);
|
||||
},
|
||||
render: function () {
|
||||
var defaultCountry = PhoneInput.getDefaultProps().defaultCountry;
|
||||
if (allIso2.indexOf(this.props.defaultCountry.toLowerCase()) !== -1) {
|
||||
defaultCountry = this.props.defaultCountry.toLowerCase();
|
||||
}
|
||||
return (
|
||||
<Row {... this.getRowProperties()}
|
||||
htmlFor={this.getId()}
|
||||
|
@ -35,6 +43,7 @@ var PhoneInput = React.createClass({
|
|||
<div className="input-group">
|
||||
<ReactPhoneInput className="form-control"
|
||||
{... this.props}
|
||||
defaultCountry={defaultCountry}
|
||||
onChange={this.onChangeInput}
|
||||
id={this.getId()}
|
||||
label={null}
|
||||
|
|
|
@ -147,7 +147,7 @@ module.exports = {
|
|||
<Form onValidSubmit={this.props.onNextStep}>
|
||||
<PhoneInput label="Phone Number"
|
||||
name="phone"
|
||||
defaultCountry="us"
|
||||
defaultCountry={this.props.formData.user && this.props.formData.user.country}
|
||||
required />
|
||||
<Checkbox label={
|
||||
'Yes, I consent to lorem ipsum dolor sit amet, consectetur' +
|
||||
|
@ -223,7 +223,11 @@ module.exports = {
|
|||
Why do we ask for this information <a onClick={this.handle}>?</a>
|
||||
</p>}>
|
||||
<Form onValidSubmit={this.props.onNextStep}>
|
||||
<Select label="Country" name="address.country" options={countryOptions} required />
|
||||
<Select label="Country"
|
||||
name="address.country"
|
||||
options={countryOptions}
|
||||
value={this.props.formData.user && this.props.formData.user.country}
|
||||
required />
|
||||
<Input label="Address Line 1" type="text" name="address.line1" required />
|
||||
<Input label="Address Line 2" type="text" name="address.line2" />
|
||||
<Input label="City" type="text" name="address.city" required />
|
||||
|
|
Loading…
Reference in a new issue