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'; import Examples from './Examples'; import { renderSelectField } from '../../../../helpers/form'; const getInputFields = (parallel_requests_selected, fastest_addr_selected) => [{ // eslint-disable-next-line react/display-name getTitle: () => , name: 'upstream_dns', type: 'text', component: 'textarea', className: 'form-control form-control--textarea font-monospace', placeholder: 'upstream_dns', }, { name: 'parallel_requests', placeholder: 'parallel_requests', component: renderSelectField, type: 'checkbox', subtitle: 'upstream_parallel', disabled: fastest_addr_selected, }, { name: 'fastest_addr', placeholder: 'fastest_addr', component: renderSelectField, type: 'checkbox', subtitle: 'fastest_addr_desc', disabled: parallel_requests_selected, }]; let Form = (props) => { const { t, handleSubmit, testUpstream, submitting, invalid, processingSetConfig, processingTestUpstream, fastest_addr, parallel_requests, upstream_dns, bootstrap_dns, } = props; const testButtonClass = classnames({ 'btn btn-primary btn-standard mr-2': true, 'btn btn-primary btn-standard mr-2 btn-loading': processingTestUpstream, }); const INPUT_FIELDS = getInputFields(parallel_requests, fastest_addr); return (
); }; Form.propTypes = { handleSubmit: PropTypes.func, testUpstream: PropTypes.func, submitting: PropTypes.bool, invalid: PropTypes.bool, initialValues: PropTypes.object, upstream_dns: PropTypes.string, bootstrap_dns: PropTypes.string, fastest_addr: PropTypes.bool, parallel_requests: PropTypes.bool, processingTestUpstream: PropTypes.bool, processingSetConfig: PropTypes.bool, t: PropTypes.func, }; const selector = formValueSelector('upstreamForm'); Form = connect((state) => { const upstream_dns = selector(state, 'upstream_dns'); const bootstrap_dns = selector(state, 'bootstrap_dns'); const fastest_addr = selector(state, 'fastest_addr'); const parallel_requests = selector(state, 'parallel_requests'); return { upstream_dns, bootstrap_dns, fastest_addr, parallel_requests, }; })(Form); export default flow([ withNamespaces(), reduxForm({ form: 'upstreamForm', }), ])(Form);