import React from 'react'; import { shallowEqual, useSelector } from 'react-redux'; import { Field, reduxForm } from 'redux-form'; import { Trans, useTranslation } from 'react-i18next'; import { renderInputField, renderRadioField, renderTextareaField, CheckboxField, toNumber, } from '../../../../helpers/form'; import { validateIpv4, validateIpv6, validateRequiredValue, validateIp, validateIPv4Subnet, validateIPv6Subnet, } from '../../../../helpers/validators'; import { removeEmptyLines } from '../../../../helpers/helpers'; import { BLOCKING_MODES, FORM_NAME, UINT32_RANGE } from '../../../../helpers/constants'; import { RootState } from '../../../../initialState'; const checkboxes = [ { name: 'dnssec_enabled', placeholder: 'dnssec_enable', subtitle: 'dnssec_enable_desc', }, { name: 'disable_ipv6', placeholder: 'disable_ipv6', subtitle: 'disable_ipv6_desc', }, ]; const customIps = [ { description: 'blocking_ipv4_desc', name: 'blocking_ipv4', validateIp: validateIpv4, }, { description: 'blocking_ipv6_desc', name: 'blocking_ipv6', validateIp: validateIpv6, }, ]; const getFields = (processing: any, t: any) => Object.values(BLOCKING_MODES) .map((mode: any) => ( )); interface ConfigFormProps { handleSubmit: (...args: unknown[]) => string; submitting: boolean; invalid: boolean; processing?: boolean; } const Form = ({ handleSubmit, submitting, invalid, processing }: ConfigFormProps) => { const { t } = useTranslation(); const { blocking_mode, edns_cs_enabled, edns_cs_use_custom } = useSelector( (state: RootState) => state.form[FORM_NAME.BLOCKING_MODE].values ?? {}, shallowEqual, ); return (
rate_limit_desc
rate_limit_subnet_len_ipv4_desc
rate_limit_subnet_len_ipv6_desc
rate_limit_whitelist_desc
{edns_cs_use_custom && ( )}
{checkboxes.map(({ name, placeholder, subtitle }) => (
))}
{Object.values(BLOCKING_MODES) .map((mode: any) => (
  • {`blocking_mode_${mode}`}
  • ))}
    {getFields(processing, t)}
    {blocking_mode === BLOCKING_MODES.custom_ip && ( <> {customIps.map(({ description, name, validateIp }) => (
    {description}
    ))} )}
    blocked_response_ttl_desc
    ); }; export default reduxForm, Omit>({ form: FORM_NAME.BLOCKING_MODE, })(Form);