diff --git a/web/src/i18n/en/index.ts b/web/src/i18n/en/index.ts index 8c5dce5212..960b92475b 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', @@ -1133,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 469c2befb5..47721301af 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: { /** @@ -2724,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 @@ -6456,6 +6464,10 @@ export type TranslationFunctions = { */ ldap_group_obj_class: () => LocalizedString } + /** + * Delete configuration + */ + 'delete': () => LocalizedString } test: { /** @@ -6894,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 f893af5e5a..1d6a739a37 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ń konfigurację', }, test: { title: 'Test połączenia LDAP', @@ -1119,6 +1120,7 @@ Uwaga, podane tutaj konfiguracje nie posiadają klucza prywatnego. Musisz uzupe submit: 'Zapisz zmiany', }, }, + delete: 'Usuń konfigurację', testForm: { title: 'Wyślij testowy e-mail', fields: { 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; + } + } +} 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%;