<commit_before>const bindAll = require('lodash.bindall');
const classNames = require('classnames');
const formsyComponent = require('formsy-react-components/release/hoc/component').default;
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;

require('./row.scss');
require('./phone-input.scss');

class PhoneInput extends React.Component {
    constructor (props) {
        super(props);
        bindAll(this, [
            'handleChange',
            'handleBlur'
        ]);
        this.state = {value: props.value};
    }
    componentWillReceiveProps (nextProps) {
        if (nextProps.value !== this.state.value) {
            this.setState({value: nextProps.value});
            this.props.onSetValue(nextProps.value);
        }
    }
    handleChange (number) {
        if (this.props.updateOnChange) {
            this.props.onSetValue(number);
        }
    }
    handleBlur (number) {
        if (this.props.updateOnBlur) {
            this.props.onSetValue(number);
        }
    }
    
    render () {
        return (
            <Row
                {...this.props}
                htmlFor={this.props.id}
                rowClassName={classNames('phone-input', this.props.className)}
            >
                <div className="input-group">
                    <ReactPhoneInput
                        className="form-control"
                        defaultCountry={this.props.defaultCountry}
                        flagsImagePath="/images/flags.png"
                        label={null}
                        onBlur={this.handleBlur}
                        onChange={this.handleChange}
                        {...omit(this.props, ['className', 'onChange', 'onBlur'])}
                    />
                </div>
            </Row>
        );
    }
}

PhoneInput.defaultProps = {
    type: 'tel',
    value: '',
    updateOnChange: true
};

PhoneInput.propTypes = {
    className: PropTypes.string,
    defaultCountry: PropTypes.string,
    disabled: PropTypes.bool,
    id: PropTypes.string,
    name: PropTypes.string,
    onChange: PropTypes.func,
    onSetValue: PropTypes.func,
    updateOnBlur: PropTypes.bool,
    updateOnChange: PropTypes.bool,
    value: PropTypes.string
};

const phoneValidationHOC = validationHOCFactory({
    isPhone: <intl.FormattedMessage id="teacherRegistration.validationPhoneNumber" />
});

module.exports = inputHOC(phoneValidationHOC(defaultValidationHOC(formsyComponent(PhoneInput))));<commit_msg>Resurrect phone input validation<commit_after>const bindAll = require('lodash.bindall');
const classNames = require('classnames');
const formsyComponent = require('formsy-react-components/release/hoc/component').default;
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 Help = require('formsy-react-components/release/components/help').default;
const ErrorMessages = require('formsy-react-components/release/components/error-messages').default;

const defaultValidationHOC = require('./validations.jsx').defaultValidationHOC;
const inputHOC = require('./input-hoc.jsx');
const intl = require('../../lib/intl.jsx');
const validationHOCFactory = require('./validations.jsx').validationHOCFactory;

require('./row.scss');
require('./phone-input.scss');

class PhoneInput extends React.Component {
    constructor (props) {
        super(props);
        bindAll(this, [
            'handleBlur',
            'handleChange',
            'handleUpdate'
        ]);
    }
    handleUpdate (number, country) {
        const value = {
            national_number: number,
            country_code: country
        };
        this.props.onSetValue(value);
    }
    handleChange (number, country) {
        if (this.props.updateOnChange) {
            this.handleUpdate(number, country);
        }
    }
    handleBlur (number, country) {
        if (this.props.updateOnBlur) {
            this.handleUpdate(number, country);
        }
    }
    
    render () {
        return (
            <Row
                {...this.props}
                htmlFor={this.props.id}
                rowClassName={classNames('phone-input', this.props.className)}
            >
                <div className="input-group">
                    <ReactPhoneInput
                        className="form-control"
                        defaultCountry={this.props.defaultCountry}
                        flagsImagePath="/images/flags.png"
                        label={null}
                        onBlur={this.handleBlur}
                        onChange={this.handleChange}
                        {...omit(this.props, ['className', 'isValid', 'onChange', 'onBlur', 'value'])}
                    />
                </div>
                {this.props.help ? <Help help={this.props.help} /> : null}
                {this.props.showErrors ? (
                    <ErrorMessages messages={this.props.errorMessages} />
                ) : null}
            </Row>
        );
    }
}

PhoneInput.defaultProps = {
    type: 'tel',
    updateOnChange: true
};

PhoneInput.propTypes = {
    className: PropTypes.string,
    defaultCountry: PropTypes.string,
    disabled: PropTypes.bool,
    id: PropTypes.string,
    name: PropTypes.string,
    onChange: PropTypes.func,
    onSetValue: PropTypes.func,
    updateOnBlur: PropTypes.bool,
    updateOnChange: PropTypes.bool
};

const phoneValidationHOC = validationHOCFactory({
    isPhone: <intl.FormattedMessage id="teacherRegistration.validationPhoneNumber" />
});

const ValidatedPhoneInput = inputHOC(defaultValidationHOC(phoneValidationHOC(formsyComponent(PhoneInput))));

ValidatedPhoneInput.defaultProps = {
    validations: {
        isPhone: true
    }
};

ValidatedPhoneInput.propTypes = {
    validations: PropTypes.objectOf(PropTypes.bool)
};

module.exports = ValidatedPhoneInput;
{'fraction_non_alphanumeric': 0.12813717848791895, 'fraction_numerical': 0.0, 'mean_word_length': 2.3468961919666147, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1992969', 'n_tokens_mistral': 1764, 'n_tokens_neox': 1746, 'n_words': 281}