Check for duplicate remote hosts
This commit is contained in:
@@ -9,6 +9,12 @@ import Text from '../../components/UI/Text/Text';
|
|||||||
import {notifyError} from '../../redux/actions/error_actions';
|
import {notifyError} from '../../redux/actions/error_actions';
|
||||||
import {addRemoteMount} from '../../redux/actions/mount_actions';
|
import {addRemoteMount} from '../../redux/actions/mount_actions';
|
||||||
|
|
||||||
|
const mapStateToProps = state => {
|
||||||
|
return {
|
||||||
|
RemoteMounts: state.mounts.RemoteMounts,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
const mapDispatchToProps = dispatch => {
|
const mapDispatchToProps = dispatch => {
|
||||||
return {
|
return {
|
||||||
addRemoteMount: (hostNameOrIp, port, token) => dispatch(addRemoteMount(hostNameOrIp, port, token)),
|
addRemoteMount: (hostNameOrIp, port, token) => dispatch(addRemoteMount(hostNameOrIp, port, token)),
|
||||||
@@ -16,7 +22,7 @@ const mapDispatchToProps = dispatch => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default connect(null, mapDispatchToProps)(class extends Component {
|
export default connect(mapStateToProps, mapDispatchToProps)(class extends Component {
|
||||||
state = {
|
state = {
|
||||||
Display: false,
|
Display: false,
|
||||||
HostNameOrIp: '',
|
HostNameOrIp: '',
|
||||||
@@ -28,16 +34,21 @@ export default connect(null, mapDispatchToProps)(class extends Component {
|
|||||||
if (this.state.HostNameOrIp.length === 0) {
|
if (this.state.HostNameOrIp.length === 0) {
|
||||||
this.props.notifyError('Hostname or IP cannot be empty.');
|
this.props.notifyError('Hostname or IP cannot be empty.');
|
||||||
} else {
|
} else {
|
||||||
this.setState({
|
const provider = 'Remote' + this.state.HostNameOrIp + ':' + this.state.Port;
|
||||||
Display: false
|
if (this.props.RemoteMounts.includes(provider)) {
|
||||||
}, () => {
|
this.props.notifyError('Remote host already exists');
|
||||||
this.props.addRemoteMount(this.state.HostNameOrIp, this.state.Port, this.state.Token);
|
} else {
|
||||||
this.setState({
|
this.setState({
|
||||||
HostNameOrIp: '',
|
Display: false
|
||||||
Port: 20000,
|
}, () => {
|
||||||
Token: '',
|
this.props.addRemoteMount(this.state.HostNameOrIp, this.state.Port, this.state.Token);
|
||||||
|
this.setState({
|
||||||
|
HostNameOrIp: '',
|
||||||
|
Port: 20000,
|
||||||
|
Token: '',
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user