diff --git a/src/components/list/DomainInput.js b/src/components/list/DomainInput.js index 946943f..060ef6e 100644 --- a/src/components/list/DomainInput.js +++ b/src/components/list/DomainInput.js @@ -27,12 +27,19 @@ class DomainInput extends Component { handleSubmit = (e) => { e.preventDefault(); - if(this.state.domain.length > 0) { - if (this.state.isValid) { - this.props.onEnter(this.state.domain); - this.setState({ domain: "" }); - } + const domain = this.state.domain; + const isValid = validate.domain(domain); + if (isValid) { + this.props.onEnter(domain); + this.setState({ domain: "" }); + this.setState({ isValid: true }); + } else { + this.props.onValidationError({ + error: true, + message: "Not valid domain format (use example.com or sub.example.com" + }); + this.setState({ isValid: false }); } }; @@ -43,7 +50,7 @@ class DomainInput extends Component {
{t("Add")} @@ -74,7 +80,7 @@ DomainInput.propTypes = { placeholder: PropTypes.string, onEnter: PropTypes.func.isRequired, onRefresh: PropTypes.func.isRequired, - onInputValidate: PropTypes.func.isRequired + onValidationError: PropTypes.func.isRequired }; DomainInput.defaultProps = { diff --git a/src/components/list/ListPage.js b/src/components/list/ListPage.js index 94c851a..34a97dc 100644 --- a/src/components/list/ListPage.js +++ b/src/components/list/ListPage.js @@ -98,10 +98,17 @@ class ListPage extends Component { .catch(ignoreCancel); }; - handleInput = err => { - this.setState({ - errorMsg: err - }); + handleValidationError = err => { + // false - validation error + if (err.error){ + this.setState({ + errorMsg: err.message + }); + } else { + this.setState({ + errorMsg: "" + }); + } }; componentDidMount() { @@ -128,7 +135,7 @@ class ListPage extends Component { placeholder={this.props.placeholder} onEnter={this.onEnter} onRefresh={this.onRefresh} - onInputValidate={this.handleInput}/> + onValidationError={this.handleValidationError}/> { this.props.note } { this.state.infoMsg