diff --git a/src/components/list/DomainInput.js b/src/components/list/DomainInput.js
index 4b357fe..0cc47ee 100644
--- a/src/components/list/DomainInput.js
+++ b/src/components/list/DomainInput.js
@@ -11,21 +11,34 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { translate } from 'react-i18next';
-import { api } from "../../utils";
+import { api, validate } from "../../utils";
class DomainInput extends Component {
state = {
- domain: ""
+ domain: "",
+ isValid: true
+ };
+
+ handleChange = (e) => {
+ const domain = e.target.value;
+ this.setState({ domain });
+ const isValid = validate.domain(domain);
+ this.setState({ domain, isValid });
+ if (isValid){
+ this.props.onInputValidate(null);
+ } else {
+ this.props.onInputValidate("Not valid domain format (use example.com or sub.example.com")
+ }
};
- handleChange = (e) =>
- this.setState({ domain: e.target.value });
onAdd = () => {
if(this.state.domain.length > 0) {
- this.props.onEnter(this.state.domain);
+ if (this.state.isValid) {
+ this.props.onEnter(this.state.domain);
- this.setState({ domain: "" });
+ this.setState({ domain: "" });
+ }
}
};
@@ -35,7 +48,7 @@ class DomainInput extends Component {
return (
e.key === 'Enter' ? this.onAdd() : null}
onChange={this.handleChange}
@@ -44,7 +57,12 @@ class DomainInput extends Component {
{
api.loggedIn ?
-