diff --git a/client/src/components/Filters/Check/index.tsx b/client/src/components/Filters/Check/index.tsx index 4b8ac018..a82c10b6 100644 --- a/client/src/components/Filters/Check/index.tsx +++ b/client/src/components/Filters/Check/index.tsx @@ -1,12 +1,14 @@ import React from 'react'; import { useTranslation } from 'react-i18next'; import { useSelector } from 'react-redux'; -import { useForm } from 'react-hook-form'; +import { Controller, useForm } from 'react-hook-form'; import Card from '../../ui/Card'; import Info from './Info'; import { RootState } from '../../../initialState'; +import { validateRequiredValue } from '../../../helpers/validators'; +import { Input } from '../../ui/Controls/Input'; interface FormValues { name: string; @@ -14,7 +16,7 @@ interface FormValues { type Props = { onSubmit?: (data: FormValues) => void; -} +}; const Check = ({ onSubmit }: Props) => { const { t } = useTranslation(); @@ -23,7 +25,7 @@ const Check = ({ onSubmit }: Props) => { const hostname = useSelector((state: RootState) => state.filtering.check.hostname); const { - register, + control, handleSubmit, formState: { isDirty, isValid }, } = useForm({ @@ -38,24 +40,29 @@ const Check = ({ onSubmit }: Props) => {
-
- - - - -
+ ( + + + + } + /> + )} + /> {hostname && ( <> diff --git a/client/src/components/Filters/Form.tsx b/client/src/components/Filters/Form.tsx index d9a8858f..82a61df9 100644 --- a/client/src/components/Filters/Form.tsx +++ b/client/src/components/Filters/Form.tsx @@ -6,6 +6,7 @@ import { validatePath, validateRequiredValue } from '../../helpers/validators'; import { MODAL_OPEN_TIMEOUT, MODAL_TYPE } from '../../helpers/constants'; import filtersCatalog from '../../helpers/filters/filters'; import { FiltersList } from './FiltersList'; +import { Input } from '../ui/Controls/Input'; type FormValues = { enabled: boolean; @@ -15,7 +16,7 @@ type FormValues = { type Props = { closeModal: (...args: unknown[]) => void; - onSubmit: (...args: unknown[]) => void; + onSubmit: (values: FormValues) => void; processingAddFilter: boolean; processingConfigFilter: boolean; whitelist?: boolean; @@ -81,13 +82,7 @@ export const Form = ({ name="name" control={control} render={({ field }) => ( - field.onChange(e.target.value.trim())} - /> + )} />
@@ -98,12 +93,11 @@ export const Form = ({ control={control} rules={{ validate: { validateRequiredValue, validatePath } }} render={({ field }) => ( - field.onChange(e.target.value.trim())} + trimOnBlur /> )} /> diff --git a/client/src/components/Filters/Rewrites/Form.tsx b/client/src/components/Filters/Rewrites/Form.tsx index f64b7836..5cbc78dc 100644 --- a/client/src/components/Filters/Rewrites/Form.tsx +++ b/client/src/components/Filters/Rewrites/Form.tsx @@ -1,8 +1,9 @@ import React from 'react'; -import { useForm } from 'react-hook-form'; +import { Controller, useForm } from 'react-hook-form'; import { Trans, useTranslation } from 'react-i18next'; -import { validateAnswer, validateDomain } from '../../../helpers/validators'; +import { validateAnswer, validateDomain, validateRequiredValue } from '../../../helpers/validators'; +import { Input } from '../../ui/Controls/Input'; interface FormValues { domain: string; @@ -11,21 +12,21 @@ interface FormValues { type Props = { processingAdd: boolean; - currentRewrite?: { answer: string, domain: string; }; + currentRewrite?: { answer: string; domain: string }; toggleRewritesModal: () => void; onSubmit?: (data: FormValues) => Promise | void; -} +}; const Form = ({ processingAdd, currentRewrite, toggleRewritesModal, onSubmit }: Props) => { const { t } = useTranslation(); const { - register, handleSubmit, reset, - formState: { isDirty, isSubmitting, errors }, + control, + formState: { isDirty, isSubmitting }, } = useForm({ - mode: 'onChange', + mode: 'onChange', defaultValues: { domain: currentRewrite?.domain || '', answer: currentRewrite?.answer || '', @@ -45,21 +46,24 @@ const Form = ({ processingAdd, currentRewrite, toggleRewritesModal, onSubmit }: domain_desc
- ( + + )} /> - {errors.domain && ( -
- {errors.domain.message} -
- )}
examples_title:
    @@ -74,21 +78,24 @@ const Form = ({ processingAdd, currentRewrite, toggleRewritesModal, onSubmit }:
- ( + + )} /> - {errors.answer && ( -
- {errors.answer.message} -
- )}
@@ -109,16 +116,14 @@ const Form = ({ processingAdd, currentRewrite, toggleRewritesModal, onSubmit }: onClick={() => { reset(); toggleRewritesModal(); - }} - > + }}> cancel_btn diff --git a/client/src/components/Filters/Services/Form.tsx b/client/src/components/Filters/Services/Form.tsx index e37b8953..f478dea4 100644 --- a/client/src/components/Filters/Services/Form.tsx +++ b/client/src/components/Filters/Services/Form.tsx @@ -19,7 +19,7 @@ type FormValues = { interface FormProps { initialValues: Record; blockedServices: BlockedService[]; - onSubmit: (...args: unknown[]) => void; + onSubmit: (values: FormValues) => void; processing: boolean; processingSet: boolean; } diff --git a/client/src/components/Filters/Services/ServiceField.tsx b/client/src/components/Filters/Services/ServiceField.tsx index e9a3d4be..1c09f5fe 100644 --- a/client/src/components/Filters/Services/ServiceField.tsx +++ b/client/src/components/Filters/Services/ServiceField.tsx @@ -2,52 +2,40 @@ import React from 'react'; import cn from 'classnames'; import { FieldValues, ControllerRenderProps } from 'react-hook-form'; -interface ServiceFieldProps extends ControllerRenderProps { +type Props = ControllerRenderProps & { placeholder: string; disabled?: boolean; className?: string; icon?: string; error?: string; -} +}; -export const ServiceField = React.forwardRef(({ - name, - value, - onChange, - onBlur, - placeholder, - disabled, - className, - icon, - error, -}, ref) => ( - <> -