const allCountries = require('country-telephone-data').allCountries; const classNames = require('classnames'); const ComponentMixin = require('formsy-react-components').ComponentMixin; const createReactClass = require('create-react-class'); const FormsyMixin = require('formsy-react').Mixin; const omit = require('lodash.omit'); const PropTypes = require('prop-types'); const React = require('react'); const ReactPhoneInput = require('react-telephone-input/lib/withStyles').default; const Row = require('formsy-react-components').Row; const defaultValidationHOC = require('./validations.jsx').defaultValidationHOC; const inputHOC = require('./input-hoc.jsx'); const intl = require('../../lib/intl.jsx'); const validationHOCFactory = require('./validations.jsx').validationHOCFactory; const allIso2 = allCountries.map(country => (country.iso2)); require('./row.scss'); require('./phone-input.scss'); const PhoneInput = createReactClass({ // eslint-disable-line react/prefer-es6-class displayName: 'PhoneInput', propTypes: { className: PropTypes.string, defaultCountry: PropTypes.string, disabled: PropTypes.bool, name: PropTypes.string, onChange: PropTypes.func }, mixins: [ FormsyMixin, ComponentMixin ], getDefaultProps: function () { return { validations: { isPhone: true }, flagsImagePath: '/images/flags.png', defaultCountry: 'us' }; }, handleChangeInput: function (number, country) { const value = { national_number: number, country_code: country }; this.setValue(value); this.props.onChange(this.props.name, value); }, render: function () { let defaultCountry = PhoneInput.getDefaultProps().defaultCountry; if (allIso2.indexOf(this.props.defaultCountry.toLowerCase()) !== -1) { defaultCountry = this.props.defaultCountry.toLowerCase(); } return ( {this.renderHelp()} {this.renderErrorMessage()} ); } }); const phoneValidationHOC = validationHOCFactory({ isPhone: }); module.exports = inputHOC(defaultValidationHOC(phoneValidationHOC(PhoneInput)));