2019-03-06 11:45:21 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { Field, reduxForm, formValueSelector } from 'redux-form';
|
|
|
|
import { Trans, withNamespaces } from 'react-i18next';
|
|
|
|
import flow from 'lodash/flow';
|
|
|
|
import classnames from 'classnames';
|
|
|
|
|
2019-06-03 12:41:45 +00:00
|
|
|
import { renderSelectField } from '../../../../helpers/form';
|
2019-03-20 11:24:33 +00:00
|
|
|
import Examples from './Examples';
|
2019-03-06 11:45:21 +00:00
|
|
|
|
|
|
|
let Form = (props) => {
|
|
|
|
const {
|
|
|
|
t,
|
|
|
|
handleSubmit,
|
|
|
|
testUpstream,
|
|
|
|
upstreamDns,
|
2019-03-06 13:35:21 +00:00
|
|
|
bootstrapDns,
|
|
|
|
allServers,
|
2019-03-06 11:45:21 +00:00
|
|
|
submitting,
|
|
|
|
invalid,
|
|
|
|
processingSetUpstream,
|
|
|
|
processingTestUpstream,
|
|
|
|
} = props;
|
|
|
|
|
|
|
|
const testButtonClass = classnames({
|
|
|
|
'btn btn-primary btn-standard mr-2': true,
|
|
|
|
'btn btn-primary btn-standard mr-2 btn-loading': processingTestUpstream,
|
|
|
|
});
|
|
|
|
|
|
|
|
return (
|
|
|
|
<form onSubmit={handleSubmit}>
|
|
|
|
<div className="row">
|
|
|
|
<div className="col-12">
|
|
|
|
<div className="form__group form__group--settings">
|
2019-03-06 13:35:21 +00:00
|
|
|
<label className="form__label" htmlFor="upstream_dns">
|
|
|
|
<Trans>upstream_dns</Trans>
|
|
|
|
</label>
|
2019-03-06 11:45:21 +00:00
|
|
|
<Field
|
|
|
|
id="upstream_dns"
|
|
|
|
name="upstream_dns"
|
|
|
|
component="textarea"
|
|
|
|
type="text"
|
|
|
|
className="form-control form-control--textarea"
|
|
|
|
placeholder={t('upstream_dns')}
|
2019-09-17 09:22:15 +00:00
|
|
|
disabled={processingSetUpstream || processingTestUpstream}
|
2019-03-06 11:45:21 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="col-12">
|
|
|
|
<div className="form__group form__group--settings">
|
|
|
|
<Field
|
|
|
|
name="all_servers"
|
|
|
|
type="checkbox"
|
|
|
|
component={renderSelectField}
|
|
|
|
placeholder={t('upstream_parallel')}
|
2019-09-17 09:22:15 +00:00
|
|
|
disabled={processingSetUpstream}
|
2019-03-06 11:45:21 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
2019-03-20 11:24:33 +00:00
|
|
|
<div className="col-12">
|
|
|
|
<Examples />
|
2019-06-03 12:41:45 +00:00
|
|
|
<hr />
|
2019-03-20 11:24:33 +00:00
|
|
|
</div>
|
2019-03-06 11:45:21 +00:00
|
|
|
<div className="col-12">
|
|
|
|
<div className="form__group">
|
2019-09-17 09:22:15 +00:00
|
|
|
<label
|
|
|
|
className="form__label form__label--with-desc"
|
|
|
|
htmlFor="bootstrap_dns"
|
|
|
|
>
|
2019-03-06 13:35:21 +00:00
|
|
|
<Trans>bootstrap_dns</Trans>
|
|
|
|
</label>
|
|
|
|
<div className="form__desc form__desc--top">
|
|
|
|
<Trans>bootstrap_dns_desc</Trans>
|
|
|
|
</div>
|
2019-03-06 11:45:21 +00:00
|
|
|
<Field
|
|
|
|
id="bootstrap_dns"
|
|
|
|
name="bootstrap_dns"
|
|
|
|
component="textarea"
|
|
|
|
type="text"
|
2019-09-17 09:22:15 +00:00
|
|
|
className="form-control form-control--textarea form-control--textarea-small"
|
2019-03-06 13:35:21 +00:00
|
|
|
placeholder={t('bootstrap_dns')}
|
2019-09-17 09:22:15 +00:00
|
|
|
disabled={processingSetUpstream}
|
2019-03-06 11:45:21 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="card-actions">
|
|
|
|
<div className="btn-list">
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
className={testButtonClass}
|
2019-06-03 12:41:45 +00:00
|
|
|
onClick={() =>
|
|
|
|
testUpstream({
|
|
|
|
upstream_dns: upstreamDns,
|
|
|
|
bootstrap_dns: bootstrapDns,
|
|
|
|
all_servers: allServers,
|
|
|
|
})
|
|
|
|
}
|
2019-03-06 11:45:21 +00:00
|
|
|
disabled={!upstreamDns || processingTestUpstream}
|
|
|
|
>
|
|
|
|
<Trans>test_upstream_btn</Trans>
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
type="submit"
|
|
|
|
className="btn btn-success btn-standard"
|
|
|
|
disabled={
|
2019-06-03 12:41:45 +00:00
|
|
|
submitting || invalid || processingSetUpstream || processingTestUpstream
|
2019-03-06 11:45:21 +00:00
|
|
|
}
|
|
|
|
>
|
|
|
|
<Trans>apply_btn</Trans>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
Form.propTypes = {
|
|
|
|
handleSubmit: PropTypes.func,
|
|
|
|
testUpstream: PropTypes.func,
|
|
|
|
submitting: PropTypes.bool,
|
|
|
|
invalid: PropTypes.bool,
|
|
|
|
initialValues: PropTypes.object,
|
|
|
|
upstreamDns: PropTypes.string,
|
2019-03-06 13:35:21 +00:00
|
|
|
bootstrapDns: PropTypes.string,
|
|
|
|
allServers: PropTypes.bool,
|
2019-03-06 11:45:21 +00:00
|
|
|
processingTestUpstream: PropTypes.bool,
|
|
|
|
processingSetUpstream: PropTypes.bool,
|
|
|
|
t: PropTypes.func,
|
|
|
|
};
|
|
|
|
|
|
|
|
const selector = formValueSelector('upstreamForm');
|
|
|
|
|
|
|
|
Form = connect((state) => {
|
|
|
|
const upstreamDns = selector(state, 'upstream_dns');
|
2019-03-06 13:35:21 +00:00
|
|
|
const bootstrapDns = selector(state, 'bootstrap_dns');
|
|
|
|
const allServers = selector(state, 'all_servers');
|
2019-03-06 11:45:21 +00:00
|
|
|
return {
|
|
|
|
upstreamDns,
|
2019-03-06 13:35:21 +00:00
|
|
|
bootstrapDns,
|
|
|
|
allServers,
|
2019-03-06 11:45:21 +00:00
|
|
|
};
|
|
|
|
})(Form);
|
|
|
|
|
|
|
|
export default flow([
|
|
|
|
withNamespaces(),
|
2019-06-03 12:41:45 +00:00
|
|
|
reduxForm({
|
|
|
|
form: 'upstreamForm',
|
|
|
|
}),
|
2019-03-06 11:45:21 +00:00
|
|
|
])(Form);
|