From 6cb3d85d01429fdd2b7a8a38e0a21ae29e730d43 Mon Sep 17 00:00:00 2001 From: Ildar Kamalov Date: Mon, 27 Jan 2025 13:29:07 +0300 Subject: [PATCH] fix forms --- .../components/Settings/Dns/Access/Form.tsx | 86 +++-- .../components/Settings/Dns/Cache/Form.tsx | 59 +-- .../components/Settings/Dns/Config/Form.tsx | 361 ++++++++++-------- .../components/Settings/Dns/Upstream/Form.tsx | 112 +++--- .../Settings/FiltersConfig/index.tsx | 36 +- .../components/Settings/LogsConfig/Form.tsx | 24 +- .../components/Settings/StatsConfig/Form.tsx | 20 +- client/src/components/ui/Controls/Input.tsx | 6 +- client/src/components/ui/Controls/Radio.tsx | 1 + .../src/components/ui/Controls/Textarea.tsx | 9 +- .../components/ui/Guide/MobileConfigForm.tsx | 6 +- client/src/initialState.ts | 2 +- 12 files changed, 404 insertions(+), 318 deletions(-) diff --git a/client/src/components/Settings/Dns/Access/Form.tsx b/client/src/components/Settings/Dns/Access/Form.tsx index add6ee7b..6b2cc7a1 100644 --- a/client/src/components/Settings/Dns/Access/Form.tsx +++ b/client/src/components/Settings/Dns/Access/Form.tsx @@ -1,47 +1,67 @@ -import React from 'react'; +import React, { ReactNode } from 'react'; import { Controller, useForm } from 'react-hook-form'; import { Trans, useTranslation } from 'react-i18next'; +import i18next from 'i18next'; import { CLIENT_ID_LINK } from '../../../../helpers/constants'; import { removeEmptyLines, trimMultilineString } from '../../../../helpers/helpers'; import { Textarea } from '../../../ui/Controls/Textarea'; -const fields = [ +type FormData = { + allowed_clients: string; + disallowed_clients: string; + blocked_hosts: string; +}; + +const fields: { + id: keyof FormData; + title: string; + subtitle: ReactNode; + normalizeOnBlur: (value: string) => string; +}[] = [ { id: 'allowed_clients', - title: 'access_allowed_title', - subtitle: 'access_allowed_desc', + title: i18next.t('access_allowed_title'), + subtitle: ( + , + }}> + access_allowed_desc + + ), normalizeOnBlur: removeEmptyLines, }, { id: 'disallowed_clients', - title: 'access_disallowed_title', - subtitle: 'access_disallowed_desc', + title: i18next.t('access_disallowed_title'), + subtitle: ( + , + }}> + access_disallowed_desc + + ), normalizeOnBlur: trimMultilineString, }, { id: 'blocked_hosts', - title: 'access_blocked_title', - subtitle: 'access_blocked_desc', + title: i18next.t('access_blocked_title'), + subtitle: i18next.t('access_blocked_desc'), normalizeOnBlur: removeEmptyLines, }, ]; -interface FormProps { +type FormProps = { initialValues?: { allowed_clients?: string; disallowed_clients?: string; blocked_hosts?: string; }; - onSubmit: (data: any) => void; + onSubmit: (data: FormData) => void; processingSet: boolean; -} - -interface FormData { - allowed_clients: string; - disallowed_clients: string; - blocked_hosts: string; -} +}; const Form = ({ initialValues, onSubmit, processingSet }: FormProps) => { const { t } = useTranslation(); @@ -70,7 +90,7 @@ const Form = ({ initialValues, onSubmit, processingSet }: FormProps) => { }: { id: keyof FormData; title: string; - subtitle: string; + subtitle: ReactNode; normalizeOnBlur: (value: string) => string; }) => { const disabled = allowedClients && id === 'disallowed_clients'; @@ -78,22 +98,11 @@ const Form = ({ initialValues, onSubmit, processingSet }: FormProps) => { return (
-
- , - }}> - {subtitle} - -
+
{subtitle}
{