Made the changes, now to fix the broken tests

Signed-off-by: Slava Bezgachev <bezgachev@gmail.com>
This commit is contained in:
Slava Bezgachev
2018-10-18 22:09:48 +06:00
parent 858bc5bec9
commit 4dbdbfb357
2 changed files with 26 additions and 13 deletions
+14 -8
View File
@@ -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 {
<form className="form-group input-group" onSubmit={this.handleSubmit}>
<input
type="text"
className={`form-control ${(this.state.isValid) ? "is-valid" : "is-invalid"}`}
className={`form-control ${this.state.isValid ? "is-valid" : "is-invalid"}`}
placeholder={this.props.placeholder}
value={this.state.domain}
onChange={this.handleChange}
@@ -55,7 +62,6 @@ class DomainInput extends Component {
<button
className="btn border-secondary"
type="submit"
disabled={!this.state.isValid}
>
{t("Add")}
</button>
@@ -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 = {
+12 -5
View File
@@ -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