var React = require('react'); var api = require('../../lib/api'); var countryData = require('../../lib/country-data'); var intl = require('../../lib/intl.jsx'); var log = require('../../lib/log'); var smartyStreets = require('../../lib/smarty-streets'); var urlParams = require('../../lib/url-params'); var Button = require('../../components/forms/button.jsx'); var Card = require('../../components/card/card.jsx'); var Checkbox = require('../../components/forms/checkbox.jsx'); var CheckboxGroup = require('../../components/forms/checkbox-group.jsx'); var Form = require('../../components/forms/form.jsx'); var Input = require('../../components/forms/input.jsx'); var PhoneInput = require('../../components/forms/phone-input.jsx'); var RadioGroup = require('../../components/forms/radio-group.jsx'); var Select = require('../../components/forms/select.jsx'); var Slide = require('../../components/slide/slide.jsx'); var Spinner = require('../../components/spinner/spinner.jsx'); var StepNavigation = require('../../components/stepnavigation/stepnavigation.jsx'); var TextArea = require('../../components/forms/textarea.jsx'); var DEFAULT_COUNTRY = 'us'; var NextStepButton = React.createClass({ getDefaultProps: function () { return { waiting: false, text: 'Next Step' }; }, render: function () { return ( {this.props.waiting ? : this.props.text } ); } }); module.exports = { UsernameStep: intl.injectIntl(React.createClass({ getDefaultProps: function () { return { waiting: false }; }, getInitialState: function () { return { showPassword: false, waiting: false }; }, onChangeShowPassword: function (field, value) { this.setState({showPassword: value}); }, onValidSubmit: function (formData, reset, invalidate) { this.setState({waiting: true}); api({ host: '', uri: '/accounts/check_username/' + formData.user.username + '/' }, function (err, res) { var formatMessage = this.props.intl.formatMessage; this.setState({waiting: false}); if (err) return invalidate({all: err}); res = res[0]; switch (res.msg) { case 'valid username': return this.props.onNextStep(formData); case 'username exists': return invalidate({ 'user.username': formatMessage({id: 'general.validationUsernameExists'}) }); case 'bad username': return invalidate({ 'user.username': formatMessage({id: 'general.validationUsernameVulgar'}) }); case 'invalid username': default: return invalidate({ 'user.username': formatMessage({id: 'general.validationUsernameInvalid'}) }); } }.bind(this)); }, render: function () { var formatMessage = this.props.intl.formatMessage; return ( } /> ); } })), DemographicsStep: intl.injectIntl(React.createClass({ getDefaultProps: function () { return { defaultCountry: DEFAULT_COUNTRY, waiting: false }; }, getInitialState: function () { return {otherDisabled: true}; }, getMonthOptions: function () { return [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ].map(function (label, id) { return { value: id+1, label: this.props.intl.formatMessage({id: 'general.month' + label})}; }.bind(this)); }, getYearOptions: function () { return Array.apply(null, Array(100)).map(function (v, id) { var year = 2016 - id; return {value: year, label: year}; }); }, onChooseGender: function (name, gender) { this.setState({otherDisabled: gender !== 'other'}); }, render: function () { var formatMessage = this.props.intl.formatMessage; return ( } /> ); } })), NameStep: intl.injectIntl(React.createClass({ getDefaultProps: function () { return { waiting: false }; }, render: function () { var formatMessage = this.props.intl.formatMessage; return ( } /> ); } })), PhoneNumberStep: intl.injectIntl(React.createClass({ getDefaultProps: function () { return { defaultCountry: DEFAULT_COUNTRY, waiting: false }; }, render: function () { var formatMessage = this.props.intl.formatMessage; return ( } /> ); } })), OrganizationStep: intl.injectIntl(React.createClass({ getInitialState: function () { return { otherDisabled: true }; }, getDefaultProps: function () { return { waiting: false }; }, organizationL10nStems: [ 'orgChoiceElementarySchool', 'orgChoiceMiddleSchool', 'orgChoiceHighSchool', 'orgChoiceUniversity', 'orgChoiceAfterschool', 'orgChoiceMuseum', 'orgChoiceLibrary', 'orgChoiceCamp', 'orgChoiceOther' ], getOrganizationOptions: function () { return this.organizationL10nStems.map(function (choice, id) { return { value: id, label: this.props.intl.formatMessage({ id: 'teacherRegistration.' + choice }) }; }.bind(this)); }, onChooseOrganization: function (name, values) { this.setState({otherDisabled: values.indexOf(this.organizationL10nStems.indexOf('orgChoiceOther')) === -1}); }, render: function () { var formatMessage = this.props.intl.formatMessage; return ( } /> ); } })), AddressStep: intl.injectIntl(React.createClass({ getDefaultProps: function () { return { defaultCountry: DEFAULT_COUNTRY, waiting: false }; }, getInitialState: function () { return { countryChoice: ( (this.props.formData.user && this.props.formData.user.country) || this.props.defaultCountry ), waiting: false }; }, onChangeCountry: function (field, choice) { this.setState({countryChoice: choice}); }, onValidSubmit: function (formData, reset, invalidate) { if (formData.address.country !== 'us') { return this.props.onNextStep(formData); } this.setState({waiting: true}); var address = { street: formData.address.line1, secondary: formData.address.line2 || '', city: formData.address.city, state: formData.address.state, zipcode: formData.address.zip }; smartyStreets(address, function (err, res) { this.setState({waiting: false}); if (err) { // We don't want to prevent registration because // address validation isn't working. Log it and // move on. log.error(err); return this.props.onNextStep(formData); } if (res && res.length > 0) { return this.props.onNextStep(formData); } else { return invalidate({ 'all': }); } }.bind(this)); }, render: function () { var formatMessage = this.props.intl.formatMessage; var stateOptions = countryData.subdivisionOptions[this.state.countryChoice]; 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 ( {stateOptions.length > 2 ? : [] } } /> ); } })), UseScratchStep: intl.injectIntl(React.createClass({ getDefaultProps: function () { return { waiting: false }; }, render: function () { var formatMessage = this.props.intl.formatMessage; return ( } /> ); } })), EmailStep: intl.injectIntl(React.createClass({ getDefaultProps: function () { return { waiting: false }; }, getInitialState: function () { return { waiting: false }; }, onValidSubmit: function (formData, reset, invalidate) { this.setState({waiting: true}); api({ host: '', uri: '/accounts/check_email/', params: {email: formData.user.email} }, function (err, res) { this.setState({waiting: false}); if (err) return invalidate({all: err}); res = res[0]; switch (res.msg) { case 'valid email': return this.props.onNextStep(formData); default: return invalidate({'user.email': res.msg}); } }.bind(this)); }, render: function () { var formatMessage = this.props.intl.formatMessage; return ( } /> ); } })), LastStep: intl.injectIntl(React.createClass({ render: function () { return ( {this.props.formData.user && this.props.formData.user.email} ); } })), RegistrationError: intl.injectIntl(React.createClass({ render: function () { return ( Something went wrong There was an error while processing your registration {this.props.registrationError} ); } })) };
{this.props.formData.user && this.props.formData.user.email}
{this.props.registrationError}