import React from 'react'; import { useDispatch, useSelector } from 'react-redux'; import PropTypes from 'prop-types'; import { Field, reduxForm } from 'redux-form'; import { Trans, useTranslation } from 'react-i18next'; import classnames from 'classnames'; import Examples from './Examples'; import { renderRadioField, renderTextareaField } from '../../../../helpers/form'; import { DNS_REQUEST_OPTIONS, FORM_NAME } from '../../../../helpers/constants'; import { testUpstream } from '../../../../actions'; import { removeEmptyLines } from '../../../../helpers/helpers'; const getInputFields = () => [{ // eslint-disable-next-line react/display-name getTitle: () => , name: 'upstream_dns', type: 'text', component: renderTextareaField, className: 'form-control form-control--textarea font-monospace', placeholder: 'upstream_dns', normalizeOnBlur: removeEmptyLines, }, { name: 'upstream_mode', type: 'radio', value: DNS_REQUEST_OPTIONS.LOAD_BALANCING, component: renderRadioField, subtitle: 'load_balancing_desc', placeholder: 'load_balancing', }, { name: 'upstream_mode', type: 'radio', value: DNS_REQUEST_OPTIONS.PARALLEL, component: renderRadioField, subtitle: 'upstream_parallel', placeholder: 'parallel_requests', }, { name: 'upstream_mode', type: 'radio', value: DNS_REQUEST_OPTIONS.FASTEST_ADDR, component: renderRadioField, subtitle: 'fastest_addr_desc', placeholder: 'fastest_addr', }]; const Form = ({ submitting, invalid, processingSetConfig, processingTestUpstream, handleSubmit, }) => { const dispatch = useDispatch(); const { t } = useTranslation(); const upstream_dns = useSelector((store) => store.form[FORM_NAME.UPSTREAM].values.upstream_dns); const bootstrap_dns = useSelector( (store) => store.form[FORM_NAME.UPSTREAM].values.bootstrap_dns, ); const handleUpstreamTest = () => dispatch(testUpstream({ upstream_dns, bootstrap_dns, })); const testButtonClass = classnames('btn btn-primary btn-standard mr-2', { 'btn-loading': processingTestUpstream, }); const INPUT_FIELDS = getInputFields(); return
{INPUT_FIELDS.map(({ name, component, type, className, placeholder, getTitle, subtitle, disabled, value, normalizeOnBlur, }) =>
{typeof getTitle === 'function' && getTitle()}
)}

bootstrap_dns_desc
; }; Form.propTypes = { handleSubmit: PropTypes.func, submitting: PropTypes.bool, invalid: PropTypes.bool, initialValues: PropTypes.object, upstream_dns: PropTypes.string, bootstrap_dns: PropTypes.string, processingTestUpstream: PropTypes.bool, processingSetConfig: PropTypes.bool, }; export default reduxForm({ form: FORM_NAME.UPSTREAM })(Form);