Check for duplicate portals

This commit is contained in:
2021-05-03 17:22:31 -05:00
parent 33145ef629
commit 8ffdd321b3
4 changed files with 22 additions and 10 deletions

View File

@@ -24,13 +24,9 @@ class AddEditHost extends Component {
TimeoutMs: 60000,
};
originalState = {};
componentDidMount() {
if (this.props.HostData) {
const state = { ...this.state, ...this.props.HostData };
this.originalState = { ...state };
this.setState(state);
this.setState({ ...this.state, ...this.props.HostData });
}
}
@@ -39,14 +35,29 @@ class AddEditHost extends Component {
this.props.notifyError('Host / IP cannot be empty');
return;
}
if (this.state.HostNameOrIp.trim().indexOf('/') >= 0) {
this.props.notifyError(`Host / IP cannot be contain '/'`);
return;
}
if (this.state.HostNameOrIp.trim().indexOf(':') >= 0) {
this.props.notifyError(`Host / IP cannot be contain ':'`);
return;
}
if (
this.props.HostList.find(
(i) =>
(i.HostNameOrIp || '').trim() === this.state.HostNameOrIp &&
i.Protocol === this.state.Protocol &&
i.ApiPort == this.state.ApiPort
)
) {
this.props.notifyError(`Portal already exists`);
return;
}
this.props.completeAddEditHost(this.state);
};
@@ -200,6 +211,7 @@ class AddEditHost extends Component {
const mapStateToProps = (state) => {
return {
HostData: state.host.HostData,
HostList: state.host.HostList,
};
};
@@ -215,6 +227,7 @@ AddEditHost.propTypes = {
Close: PropTypes.func.isRequired,
completeAddEditHost: PropTypes.func.isRequired,
HostData: PropTypes.object,
HostList: PropTypes.array.isRequired,
notifyError: PropTypes.func.isRequired,
};