From 8c71952a8597d5aadf8eb2191c2696d7173a828e Mon Sep 17 00:00:00 2001 From: cpprian Date: Fri, 30 Aug 2024 13:09:55 +0200 Subject: [PATCH 1/4] del ldap button --- web/src/i18n/en/index.ts | 1 + web/src/i18n/i18n-types.ts | 8 +++ web/src/i18n/pl/index.ts | 1 + .../components/LdapSettingsForm.tsx | 60 +++++++++++++++---- .../components/LdapSettings/style.scss | 14 +++++ 5 files changed, 73 insertions(+), 11 deletions(-) diff --git a/web/src/i18n/en/index.ts b/web/src/i18n/en/index.ts index eea0f96b9f..813420ca08 100644 --- a/web/src/i18n/en/index.ts +++ b/web/src/i18n/en/index.ts @@ -920,6 +920,7 @@ const en: BaseTranslation = { ldap_group_member_attr: 'Group Member Attribute', ldap_group_obj_class: 'Group Object Class', }, + delete: 'Delete configuration', }, test: { title: 'Test LDAP Connection', diff --git a/web/src/i18n/i18n-types.ts b/web/src/i18n/i18n-types.ts index 9e2b916eec..0e07d6be4e 100644 --- a/web/src/i18n/i18n-types.ts +++ b/web/src/i18n/i18n-types.ts @@ -2283,6 +2283,10 @@ type RootTranslation = { */ ldap_group_obj_class: string } + /** + * D​e​l​e​t​e​ ​c​o​n​f​i​g​u​r​a​t​i​o​n + */ + 'delete': string } test: { /** @@ -6456,6 +6460,10 @@ export type TranslationFunctions = { */ ldap_group_obj_class: () => LocalizedString } + /** + * Delete configuration + */ + 'delete': () => LocalizedString } test: { /** diff --git a/web/src/i18n/pl/index.ts b/web/src/i18n/pl/index.ts index 59ca5502d4..f0015bc191 100644 --- a/web/src/i18n/pl/index.ts +++ b/web/src/i18n/pl/index.ts @@ -907,6 +907,7 @@ Uwaga, podane tutaj konfiguracje nie posiadają klucza prywatnego. Musisz uzupe ldap_group_member_attr: 'Group Member Attribute', ldap_group_obj_class: 'Group Object Class', }, + delete: 'Usuń konfiguracje', }, test: { title: 'Test połączenia LDAP', diff --git a/web/src/pages/settings/components/LdapSettings/components/LdapSettingsForm.tsx b/web/src/pages/settings/components/LdapSettings/components/LdapSettingsForm.tsx index 2aa79affe0..c378f86ee6 100644 --- a/web/src/pages/settings/components/LdapSettings/components/LdapSettingsForm.tsx +++ b/web/src/pages/settings/components/LdapSettings/components/LdapSettingsForm.tsx @@ -1,6 +1,6 @@ import { zodResolver } from '@hookform/resolvers/zod'; import { useMutation, useQueryClient } from '@tanstack/react-query'; -import { useMemo, useRef } from 'react'; +import { useCallback, useMemo, useRef } from 'react'; import { SubmitHandler, useForm } from 'react-hook-form'; import { z } from 'zod'; @@ -39,6 +39,10 @@ export const LdapSettingsForm = () => { queryClient.invalidateQueries([QueryKeys.FETCH_SETTINGS]); toaster.success(LL.settingsPage.messages.editSuccess()); }, + onError: (error) => { + toaster.error(LL.messages.error()); + console.error(error); + }, }); const schema = useMemo( @@ -79,7 +83,24 @@ export const LdapSettingsForm = () => { [settings], ); - const { handleSubmit, control } = useForm({ + const emptyValues: SettingsLDAP = useMemo( + () => ({ + ldap_group_search_base: '', + ldap_group_member_attr: '', + ldap_group_obj_class: '', + ldap_username_attr: '', + ldap_user_search_base: '', + ldap_user_obj_class: '', + ldap_url: '', + ldap_member_attr: '', + ldap_groupname_attr: '', + ldap_bind_password: '', + ldap_bind_username: '', + }), + [], + ); + + const { handleSubmit, reset, control } = useForm({ resolver: zodResolver(schema), defaultValues, mode: 'all', @@ -88,19 +109,36 @@ export const LdapSettingsForm = () => { const handleValidSubmit: SubmitHandler = (data) => { mutate(data); }; + + const handleDeleteSubmit = useCallback(() => { + mutate(emptyValues); + reset(emptyValues); + }, [mutate, emptyValues, reset]); + return (

{localLL.title()}

-
header { + & > .btn { + margin-left: 100px; + } + + & > .controls { + display: flex; + gap: 10px; + } + } +} From 044cfa543131d30b36ba1d5f933c207a038e9e58 Mon Sep 17 00:00:00 2001 From: cpprian Date: Fri, 30 Aug 2024 13:30:08 +0200 Subject: [PATCH 2/4] add del button for smtp --- web/src/i18n/en/index.ts | 1 + web/src/i18n/i18n-types.ts | 8 ++ web/src/i18n/pl/index.ts | 1 + .../SmtpSettingsForm/SmtpSettingsForm.tsx | 80 +++++++++++++------ .../components/SmtpSettingsForm/style.scss | 5 ++ 5 files changed, 69 insertions(+), 26 deletions(-) diff --git a/web/src/i18n/en/index.ts b/web/src/i18n/en/index.ts index 813420ca08..479e22eada 100644 --- a/web/src/i18n/en/index.ts +++ b/web/src/i18n/en/index.ts @@ -1134,6 +1134,7 @@ const en: BaseTranslation = { submit: 'Save changes', }, }, + delete: 'Delete configuration', testForm: { title: 'Send test email', fields: { diff --git a/web/src/i18n/i18n-types.ts b/web/src/i18n/i18n-types.ts index 0e07d6be4e..e2d405022a 100644 --- a/web/src/i18n/i18n-types.ts +++ b/web/src/i18n/i18n-types.ts @@ -2728,6 +2728,10 @@ type RootTranslation = { submit: string } } + /** + * D​e​l​e​t​e​ ​c​o​n​f​i​g​u​r​a​t​i​o​n + */ + 'delete': string testForm: { /** * S​e​n​d​ ​t​e​s​t​ ​e​m​a​i​l @@ -6902,6 +6906,10 @@ export type TranslationFunctions = { submit: () => LocalizedString } } + /** + * Delete configuration + */ + 'delete': () => LocalizedString testForm: { /** * Send test email diff --git a/web/src/i18n/pl/index.ts b/web/src/i18n/pl/index.ts index f0015bc191..69b23a7424 100644 --- a/web/src/i18n/pl/index.ts +++ b/web/src/i18n/pl/index.ts @@ -1120,6 +1120,7 @@ Uwaga, podane tutaj konfiguracje nie posiadają klucza prywatnego. Musisz uzupe submit: 'Zapisz zmiany', }, }, + delete: 'Usuń konfiguracje', testForm: { title: 'Wyślij testowy e-mail', fields: { diff --git a/web/src/pages/settings/components/SmtpSettings/components/SmtpSettingsForm/SmtpSettingsForm.tsx b/web/src/pages/settings/components/SmtpSettings/components/SmtpSettingsForm/SmtpSettingsForm.tsx index df1964e62d..13bf87296b 100644 --- a/web/src/pages/settings/components/SmtpSettings/components/SmtpSettingsForm/SmtpSettingsForm.tsx +++ b/web/src/pages/settings/components/SmtpSettings/components/SmtpSettingsForm/SmtpSettingsForm.tsx @@ -25,6 +25,7 @@ import useApi from '../../../../../../shared/hooks/useApi'; import { useToaster } from '../../../../../../shared/hooks/useToaster'; import { patternValidEmail } from '../../../../../../shared/patterns'; import { QueryKeys } from '../../../../../../shared/queries'; +import { SettingsSMTP } from '../../../../../../shared/types'; import { validateIpOrDomain } from '../../../../../../shared/validators'; import { useSettingsPage } from '../../../../hooks/useSettingsPage'; @@ -39,6 +40,7 @@ type FormFields = { export const SmtpSettingsForm = () => { const { LL } = useI18nContext(); + const localLL = LL.settingsPage.smtp; const settings = useSettingsPage((state) => state.settings); @@ -133,7 +135,19 @@ export const SmtpSettingsForm = () => { return res; }, [settings, encryptionOptions]); - const { control, handleSubmit } = useForm({ + const emptyValues: SettingsSMTP = useMemo( + () => ({ + smtp_server: '', + smtp_port: 587, + smtp_password: '', + smtp_sender: '', + smtp_user: '', + smtp_encryption: encryptionOptions[1].value, + }), + [encryptionOptions], + ); + + const { control, reset, handleSubmit } = useForm({ defaultValues, mode: 'all', resolver: zodResolver(zodSchema), @@ -143,62 +157,76 @@ export const SmtpSettingsForm = () => { mutate(data); }; + const handleDeleteSubmit = useCallback(() => { + mutate(emptyValues); + reset(emptyValues); + }, [mutate, emptyValues, reset]); + if (!settings) return null; return (
-

{LL.settingsPage.smtp.form.title()}

- {parse(LL.settingsPage.smtp.helper())} -
{parse(LL.settingsPage.smtp.form.fields.sender.helper())} - } - label={LL.settingsPage.smtp.form.fields.sender.label()} + labelExtras={{parse(localLL.form.fields.sender.helper())}} + label={localLL.form.fields.sender.label()} controller={{ control, name: 'smtp_sender' }} - placeholder={LL.settingsPage.smtp.form.fields.sender.placeholder()} + placeholder={localLL.form.fields.sender.placeholder()} required /> .btn { margin-left: auto; } + + & > .controls { + display: flex; + gap: 10px; + } } form { width: 100%; From 59582092c138613f35bdf16bae32ca334440e02e Mon Sep 17 00:00:00 2001 From: Cyprian <46838495+cpprian@users.noreply.github.com> Date: Fri, 30 Aug 2024 15:10:03 +0200 Subject: [PATCH 3/4] Update web/src/i18n/pl/index.ts Co-authored-by: Adam --- web/src/i18n/pl/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/src/i18n/pl/index.ts b/web/src/i18n/pl/index.ts index 69b23a7424..60ff49c75b 100644 --- a/web/src/i18n/pl/index.ts +++ b/web/src/i18n/pl/index.ts @@ -1120,7 +1120,7 @@ Uwaga, podane tutaj konfiguracje nie posiadają klucza prywatnego. Musisz uzupe submit: 'Zapisz zmiany', }, }, - delete: 'Usuń konfiguracje', + delete: 'Usuń konfigurację', testForm: { title: 'Wyślij testowy e-mail', fields: { From af79c165545c60dbcc4105adf74817337be4d8a5 Mon Sep 17 00:00:00 2001 From: Cyprian <46838495+cpprian@users.noreply.github.com> Date: Fri, 30 Aug 2024 15:10:15 +0200 Subject: [PATCH 4/4] Update web/src/i18n/pl/index.ts Co-authored-by: Adam --- web/src/i18n/pl/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/src/i18n/pl/index.ts b/web/src/i18n/pl/index.ts index 60ff49c75b..b306a80ce2 100644 --- a/web/src/i18n/pl/index.ts +++ b/web/src/i18n/pl/index.ts @@ -907,7 +907,7 @@ Uwaga, podane tutaj konfiguracje nie posiadają klucza prywatnego. Musisz uzupe ldap_group_member_attr: 'Group Member Attribute', ldap_group_obj_class: 'Group Object Class', }, - delete: 'Usuń konfiguracje', + delete: 'Usuń konfigurację', }, test: { title: 'Test połączenia LDAP',