Check upstream length in component

This commit is contained in:
Ildar Kamalov 2018-09-21 18:50:06 +03:00
parent f727f999f9
commit c2a2b3ea6a
3 changed files with 18 additions and 18 deletions

View File

@ -428,7 +428,6 @@ export const testUpstreamSuccess = createAction('TEST_UPSTREAM_SUCCESS');
export const testUpstream = servers => async (dispatch) => { export const testUpstream = servers => async (dispatch) => {
dispatch(testUpstreamRequest()); dispatch(testUpstreamRequest());
try { try {
if (servers.length > 0) {
const upstreamResponse = await apiClient.testUpstream(servers); const upstreamResponse = await apiClient.testUpstream(servers);
const testMessages = Object.keys(upstreamResponse).map((key) => { const testMessages = Object.keys(upstreamResponse).map((key) => {
@ -444,10 +443,6 @@ export const testUpstream = servers => async (dispatch) => {
} }
dispatch(testUpstreamSuccess()); dispatch(testUpstreamSuccess());
} else {
dispatch(addErrorToast({ error: 'No servers specified' }));
dispatch(testUpstreamFailure());
}
} catch (error) { } catch (error) {
dispatch(addErrorToast({ error })); dispatch(addErrorToast({ error }));
dispatch(testUpstreamFailure()); dispatch(testUpstreamFailure());

View File

@ -44,7 +44,11 @@ export default class Settings extends Component {
}; };
handleUpstreamTest = () => { handleUpstreamTest = () => {
if (this.props.settings.upstream.length > 0) {
this.props.testUpstream(this.props.settings.upstream); this.props.testUpstream(this.props.settings.upstream);
} else {
this.props.addErrorToast({ error: 'No servers specified' });
}
}; };
renderSettings = (settings) => { renderSettings = (settings) => {

View File

@ -1,5 +1,5 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { initSettings, toggleSetting, handleUpstreamChange, setUpstream, testUpstream } from '../actions'; import { initSettings, toggleSetting, handleUpstreamChange, setUpstream, testUpstream, addErrorToast } from '../actions';
import Settings from '../components/Settings'; import Settings from '../components/Settings';
const mapStateToProps = (state) => { const mapStateToProps = (state) => {
@ -14,6 +14,7 @@ const mapDispatchToProps = {
handleUpstreamChange, handleUpstreamChange,
setUpstream, setUpstream,
testUpstream, testUpstream,
addErrorToast,
}; };
export default connect( export default connect(