diff --git a/commafeed-client/src/components/settings/ProfileSettings.tsx b/commafeed-client/src/components/settings/ProfileSettings.tsx index a8e053eb..7cfcf16c 100644 --- a/commafeed-client/src/components/settings/ProfileSettings.tsx +++ b/commafeed-client/src/components/settings/ProfileSettings.tsx @@ -13,6 +13,7 @@ import { useAppDispatch, useAppSelector } from "@/app/store" import type { ProfileModificationRequest } from "@/app/types" import { reloadProfile } from "@/app/user/thunks" import { Alert } from "@/components/Alert" +import { useValidationRules } from "@/hooks/useValidationRules" interface FormData extends ProfileModificationRequest { newPasswordConfirmation?: string @@ -23,13 +24,11 @@ export function ProfileSettings() { const serverInfos = useAppSelector(state => state.server.serverInfos) const dispatch = useAppDispatch() const { _ } = useLingui() + const validationRules = useValidationRules() const form = useForm({ validate: { - newPassword: value => - value && serverInfos && value.length < serverInfos.minimumPasswordLength - ? _(msg`Password must be at least ${serverInfos.minimumPasswordLength} characters`) - : null, + newPassword: validationRules.password, newPasswordConfirmation: (value, values) => (value !== values.newPassword ? _(msg`Passwords do not match`) : null), }, validateInputOnChange: true, diff --git a/commafeed-client/src/hooks/useValidationRules.ts b/commafeed-client/src/hooks/useValidationRules.ts new file mode 100644 index 00000000..a535320f --- /dev/null +++ b/commafeed-client/src/hooks/useValidationRules.ts @@ -0,0 +1,15 @@ +import { msg } from "@lingui/core/macro" +import { useLingui } from "@lingui/react" +import { useAppSelector } from "@/app/store" + +export function useValidationRules() { + const minimumPasswordLength = useAppSelector(state => state.server.serverInfos?.minimumPasswordLength) + const { _ } = useLingui() + + return { + password: (value: string | undefined) => + value && minimumPasswordLength && value.length < minimumPasswordLength + ? _(msg`Password must be at least ${minimumPasswordLength} characters`) + : null, + } +} diff --git a/commafeed-client/src/locales/ar/messages.po b/commafeed-client/src/locales/ar/messages.po index 12c061f5..5715637b 100644 --- a/commafeed-client/src/locales/ar/messages.po +++ b/commafeed-client/src/locales/ar/messages.po @@ -771,11 +771,8 @@ msgstr "الفئة الأصل" msgid "Password" msgstr "كلمة المرور" -#. placeholder {0}: serverInfos.minimumPasswordLength -#: src/components/settings/ProfileSettings.tsx -#: src/pages/auth/InitialSetupPage.tsx -#: src/pages/auth/RegistrationPage.tsx -msgid "Password must be at least {0} characters" +#: src/hooks/useValidationRules.ts +msgid "Password must be at least {minimumPasswordLength} characters" msgstr "" #: src/pages/auth/PasswordRecoveryPage.tsx diff --git a/commafeed-client/src/locales/ca/messages.po b/commafeed-client/src/locales/ca/messages.po index d68b3468..aac7273d 100644 --- a/commafeed-client/src/locales/ca/messages.po +++ b/commafeed-client/src/locales/ca/messages.po @@ -771,11 +771,8 @@ msgstr "Categoria pare" msgid "Password" msgstr "Contrasenya" -#. placeholder {0}: serverInfos.minimumPasswordLength -#: src/components/settings/ProfileSettings.tsx -#: src/pages/auth/InitialSetupPage.tsx -#: src/pages/auth/RegistrationPage.tsx -msgid "Password must be at least {0} characters" +#: src/hooks/useValidationRules.ts +msgid "Password must be at least {minimumPasswordLength} characters" msgstr "" #: src/pages/auth/PasswordRecoveryPage.tsx diff --git a/commafeed-client/src/locales/cs/messages.po b/commafeed-client/src/locales/cs/messages.po index f584c53b..20eee3a0 100644 --- a/commafeed-client/src/locales/cs/messages.po +++ b/commafeed-client/src/locales/cs/messages.po @@ -771,11 +771,8 @@ msgstr "Rodičovská kategorie" msgid "Password" msgstr "Heslo" -#. placeholder {0}: serverInfos.minimumPasswordLength -#: src/components/settings/ProfileSettings.tsx -#: src/pages/auth/InitialSetupPage.tsx -#: src/pages/auth/RegistrationPage.tsx -msgid "Password must be at least {0} characters" +#: src/hooks/useValidationRules.ts +msgid "Password must be at least {minimumPasswordLength} characters" msgstr "" #: src/pages/auth/PasswordRecoveryPage.tsx diff --git a/commafeed-client/src/locales/cy/messages.po b/commafeed-client/src/locales/cy/messages.po index 9bc03d42..7e08acf5 100644 --- a/commafeed-client/src/locales/cy/messages.po +++ b/commafeed-client/src/locales/cy/messages.po @@ -771,11 +771,8 @@ msgstr "Categori Rhiant" msgid "Password" msgstr "cyfrinair" -#. placeholder {0}: serverInfos.minimumPasswordLength -#: src/components/settings/ProfileSettings.tsx -#: src/pages/auth/InitialSetupPage.tsx -#: src/pages/auth/RegistrationPage.tsx -msgid "Password must be at least {0} characters" +#: src/hooks/useValidationRules.ts +msgid "Password must be at least {minimumPasswordLength} characters" msgstr "" #: src/pages/auth/PasswordRecoveryPage.tsx diff --git a/commafeed-client/src/locales/da/messages.po b/commafeed-client/src/locales/da/messages.po index 0d70cef0..c081c834 100644 --- a/commafeed-client/src/locales/da/messages.po +++ b/commafeed-client/src/locales/da/messages.po @@ -771,11 +771,8 @@ msgstr "Forældrekategori" msgid "Password" msgstr "Adgangskode" -#. placeholder {0}: serverInfos.minimumPasswordLength -#: src/components/settings/ProfileSettings.tsx -#: src/pages/auth/InitialSetupPage.tsx -#: src/pages/auth/RegistrationPage.tsx -msgid "Password must be at least {0} characters" +#: src/hooks/useValidationRules.ts +msgid "Password must be at least {minimumPasswordLength} characters" msgstr "" #: src/pages/auth/PasswordRecoveryPage.tsx diff --git a/commafeed-client/src/locales/de/messages.po b/commafeed-client/src/locales/de/messages.po index 8458cf58..979c72c7 100644 --- a/commafeed-client/src/locales/de/messages.po +++ b/commafeed-client/src/locales/de/messages.po @@ -771,11 +771,8 @@ msgstr "Übergeordnete Kategorie" msgid "Password" msgstr "Passwort" -#. placeholder {0}: serverInfos.minimumPasswordLength -#: src/components/settings/ProfileSettings.tsx -#: src/pages/auth/InitialSetupPage.tsx -#: src/pages/auth/RegistrationPage.tsx -msgid "Password must be at least {0} characters" +#: src/hooks/useValidationRules.ts +msgid "Password must be at least {minimumPasswordLength} characters" msgstr "" #: src/pages/auth/PasswordRecoveryPage.tsx diff --git a/commafeed-client/src/locales/en/messages.po b/commafeed-client/src/locales/en/messages.po index 396d08d4..d1db8de4 100644 --- a/commafeed-client/src/locales/en/messages.po +++ b/commafeed-client/src/locales/en/messages.po @@ -771,12 +771,9 @@ msgstr "Parent Category" msgid "Password" msgstr "Password" -#. placeholder {0}: serverInfos.minimumPasswordLength -#: src/components/settings/ProfileSettings.tsx -#: src/pages/auth/InitialSetupPage.tsx -#: src/pages/auth/RegistrationPage.tsx -msgid "Password must be at least {0} characters" -msgstr "Password must be at least {0} characters" +#: src/hooks/useValidationRules.ts +msgid "Password must be at least {minimumPasswordLength} characters" +msgstr "Password must be at least {minimumPasswordLength} characters" #: src/pages/auth/PasswordRecoveryPage.tsx msgid "Password Recovery" diff --git a/commafeed-client/src/locales/es/messages.po b/commafeed-client/src/locales/es/messages.po index 098146cf..c7d03801 100644 --- a/commafeed-client/src/locales/es/messages.po +++ b/commafeed-client/src/locales/es/messages.po @@ -772,11 +772,8 @@ msgstr "Categoría principal" msgid "Password" msgstr "Contraseña" -#. placeholder {0}: serverInfos.minimumPasswordLength -#: src/components/settings/ProfileSettings.tsx -#: src/pages/auth/InitialSetupPage.tsx -#: src/pages/auth/RegistrationPage.tsx -msgid "Password must be at least {0} characters" +#: src/hooks/useValidationRules.ts +msgid "Password must be at least {minimumPasswordLength} characters" msgstr "" #: src/pages/auth/PasswordRecoveryPage.tsx diff --git a/commafeed-client/src/locales/fa/messages.po b/commafeed-client/src/locales/fa/messages.po index 6147e117..1a06ada9 100644 --- a/commafeed-client/src/locales/fa/messages.po +++ b/commafeed-client/src/locales/fa/messages.po @@ -771,11 +771,8 @@ msgstr "دسته والد" msgid "Password" msgstr "رمز عبور" -#. placeholder {0}: serverInfos.minimumPasswordLength -#: src/components/settings/ProfileSettings.tsx -#: src/pages/auth/InitialSetupPage.tsx -#: src/pages/auth/RegistrationPage.tsx -msgid "Password must be at least {0} characters" +#: src/hooks/useValidationRules.ts +msgid "Password must be at least {minimumPasswordLength} characters" msgstr "" #: src/pages/auth/PasswordRecoveryPage.tsx diff --git a/commafeed-client/src/locales/fi/messages.po b/commafeed-client/src/locales/fi/messages.po index a271c837..ce7405e0 100644 --- a/commafeed-client/src/locales/fi/messages.po +++ b/commafeed-client/src/locales/fi/messages.po @@ -771,11 +771,8 @@ msgstr "Pääluokka" msgid "Password" msgstr "Salasana" -#. placeholder {0}: serverInfos.minimumPasswordLength -#: src/components/settings/ProfileSettings.tsx -#: src/pages/auth/InitialSetupPage.tsx -#: src/pages/auth/RegistrationPage.tsx -msgid "Password must be at least {0} characters" +#: src/hooks/useValidationRules.ts +msgid "Password must be at least {minimumPasswordLength} characters" msgstr "" #: src/pages/auth/PasswordRecoveryPage.tsx diff --git a/commafeed-client/src/locales/fr/messages.po b/commafeed-client/src/locales/fr/messages.po index 869d1763..ecd22f87 100644 --- a/commafeed-client/src/locales/fr/messages.po +++ b/commafeed-client/src/locales/fr/messages.po @@ -771,11 +771,8 @@ msgstr "Catégorie parente" msgid "Password" msgstr "Mot de passe" -#. placeholder {0}: serverInfos.minimumPasswordLength -#: src/components/settings/ProfileSettings.tsx -#: src/pages/auth/InitialSetupPage.tsx -#: src/pages/auth/RegistrationPage.tsx -msgid "Password must be at least {0} characters" +#: src/hooks/useValidationRules.ts +msgid "Password must be at least {minimumPasswordLength} characters" msgstr "" #: src/pages/auth/PasswordRecoveryPage.tsx diff --git a/commafeed-client/src/locales/gl/messages.po b/commafeed-client/src/locales/gl/messages.po index de7ee3f1..f456a46d 100644 --- a/commafeed-client/src/locales/gl/messages.po +++ b/commafeed-client/src/locales/gl/messages.po @@ -772,11 +772,8 @@ msgstr "Categoría superior" msgid "Password" msgstr "Contrasinal" -#. placeholder {0}: serverInfos.minimumPasswordLength -#: src/components/settings/ProfileSettings.tsx -#: src/pages/auth/InitialSetupPage.tsx -#: src/pages/auth/RegistrationPage.tsx -msgid "Password must be at least {0} characters" +#: src/hooks/useValidationRules.ts +msgid "Password must be at least {minimumPasswordLength} characters" msgstr "" #: src/pages/auth/PasswordRecoveryPage.tsx diff --git a/commafeed-client/src/locales/hu/messages.po b/commafeed-client/src/locales/hu/messages.po index 53aa0b56..4a7429ef 100644 --- a/commafeed-client/src/locales/hu/messages.po +++ b/commafeed-client/src/locales/hu/messages.po @@ -771,11 +771,8 @@ msgstr "Szülő kategória" msgid "Password" msgstr "Jelszó" -#. placeholder {0}: serverInfos.minimumPasswordLength -#: src/components/settings/ProfileSettings.tsx -#: src/pages/auth/InitialSetupPage.tsx -#: src/pages/auth/RegistrationPage.tsx -msgid "Password must be at least {0} characters" +#: src/hooks/useValidationRules.ts +msgid "Password must be at least {minimumPasswordLength} characters" msgstr "" #: src/pages/auth/PasswordRecoveryPage.tsx diff --git a/commafeed-client/src/locales/id/messages.po b/commafeed-client/src/locales/id/messages.po index bb1abd01..3aae967d 100644 --- a/commafeed-client/src/locales/id/messages.po +++ b/commafeed-client/src/locales/id/messages.po @@ -771,11 +771,8 @@ msgstr "Kategori Induk" msgid "Password" msgstr "Kata Sandi" -#. placeholder {0}: serverInfos.minimumPasswordLength -#: src/components/settings/ProfileSettings.tsx -#: src/pages/auth/InitialSetupPage.tsx -#: src/pages/auth/RegistrationPage.tsx -msgid "Password must be at least {0} characters" +#: src/hooks/useValidationRules.ts +msgid "Password must be at least {minimumPasswordLength} characters" msgstr "" #: src/pages/auth/PasswordRecoveryPage.tsx diff --git a/commafeed-client/src/locales/it/messages.po b/commafeed-client/src/locales/it/messages.po index 02fb849c..f5643d1a 100644 --- a/commafeed-client/src/locales/it/messages.po +++ b/commafeed-client/src/locales/it/messages.po @@ -771,11 +771,8 @@ msgstr "Categoria padre" msgid "Password" msgstr "" -#. placeholder {0}: serverInfos.minimumPasswordLength -#: src/components/settings/ProfileSettings.tsx -#: src/pages/auth/InitialSetupPage.tsx -#: src/pages/auth/RegistrationPage.tsx -msgid "Password must be at least {0} characters" +#: src/hooks/useValidationRules.ts +msgid "Password must be at least {minimumPasswordLength} characters" msgstr "" #: src/pages/auth/PasswordRecoveryPage.tsx diff --git a/commafeed-client/src/locales/ja/messages.po b/commafeed-client/src/locales/ja/messages.po index 1e99b3da..f28bbd31 100644 --- a/commafeed-client/src/locales/ja/messages.po +++ b/commafeed-client/src/locales/ja/messages.po @@ -771,11 +771,8 @@ msgstr "親カテゴリ" msgid "Password" msgstr "パスワード" -#. placeholder {0}: serverInfos.minimumPasswordLength -#: src/components/settings/ProfileSettings.tsx -#: src/pages/auth/InitialSetupPage.tsx -#: src/pages/auth/RegistrationPage.tsx -msgid "Password must be at least {0} characters" +#: src/hooks/useValidationRules.ts +msgid "Password must be at least {minimumPasswordLength} characters" msgstr "" #: src/pages/auth/PasswordRecoveryPage.tsx diff --git a/commafeed-client/src/locales/ko/messages.po b/commafeed-client/src/locales/ko/messages.po index 3d18e825..1f76e680 100644 --- a/commafeed-client/src/locales/ko/messages.po +++ b/commafeed-client/src/locales/ko/messages.po @@ -771,11 +771,8 @@ msgstr "부모 카테고리" msgid "Password" msgstr "비밀번호" -#. placeholder {0}: serverInfos.minimumPasswordLength -#: src/components/settings/ProfileSettings.tsx -#: src/pages/auth/InitialSetupPage.tsx -#: src/pages/auth/RegistrationPage.tsx -msgid "Password must be at least {0} characters" +#: src/hooks/useValidationRules.ts +msgid "Password must be at least {minimumPasswordLength} characters" msgstr "" #: src/pages/auth/PasswordRecoveryPage.tsx diff --git a/commafeed-client/src/locales/ms/messages.po b/commafeed-client/src/locales/ms/messages.po index 1cfd71c5..1020ac47 100644 --- a/commafeed-client/src/locales/ms/messages.po +++ b/commafeed-client/src/locales/ms/messages.po @@ -771,11 +771,8 @@ msgstr "Kategori Induk" msgid "Password" msgstr "Kata Laluan" -#. placeholder {0}: serverInfos.minimumPasswordLength -#: src/components/settings/ProfileSettings.tsx -#: src/pages/auth/InitialSetupPage.tsx -#: src/pages/auth/RegistrationPage.tsx -msgid "Password must be at least {0} characters" +#: src/hooks/useValidationRules.ts +msgid "Password must be at least {minimumPasswordLength} characters" msgstr "" #: src/pages/auth/PasswordRecoveryPage.tsx diff --git a/commafeed-client/src/locales/nb/messages.po b/commafeed-client/src/locales/nb/messages.po index b980fc45..b23be151 100644 --- a/commafeed-client/src/locales/nb/messages.po +++ b/commafeed-client/src/locales/nb/messages.po @@ -771,11 +771,8 @@ msgstr "Overordnet kategori" msgid "Password" msgstr "Passord" -#. placeholder {0}: serverInfos.minimumPasswordLength -#: src/components/settings/ProfileSettings.tsx -#: src/pages/auth/InitialSetupPage.tsx -#: src/pages/auth/RegistrationPage.tsx -msgid "Password must be at least {0} characters" +#: src/hooks/useValidationRules.ts +msgid "Password must be at least {minimumPasswordLength} characters" msgstr "" #: src/pages/auth/PasswordRecoveryPage.tsx diff --git a/commafeed-client/src/locales/nl/messages.po b/commafeed-client/src/locales/nl/messages.po index eeef53fb..e3fa3290 100644 --- a/commafeed-client/src/locales/nl/messages.po +++ b/commafeed-client/src/locales/nl/messages.po @@ -771,11 +771,8 @@ msgstr "Oudercategorie" msgid "Password" msgstr "Wachtwoord" -#. placeholder {0}: serverInfos.minimumPasswordLength -#: src/components/settings/ProfileSettings.tsx -#: src/pages/auth/InitialSetupPage.tsx -#: src/pages/auth/RegistrationPage.tsx -msgid "Password must be at least {0} characters" +#: src/hooks/useValidationRules.ts +msgid "Password must be at least {minimumPasswordLength} characters" msgstr "" #: src/pages/auth/PasswordRecoveryPage.tsx diff --git a/commafeed-client/src/locales/nn/messages.po b/commafeed-client/src/locales/nn/messages.po index cd3bd38f..fd3c06dc 100644 --- a/commafeed-client/src/locales/nn/messages.po +++ b/commafeed-client/src/locales/nn/messages.po @@ -771,11 +771,8 @@ msgstr "Overordnet kategori" msgid "Password" msgstr "Passord" -#. placeholder {0}: serverInfos.minimumPasswordLength -#: src/components/settings/ProfileSettings.tsx -#: src/pages/auth/InitialSetupPage.tsx -#: src/pages/auth/RegistrationPage.tsx -msgid "Password must be at least {0} characters" +#: src/hooks/useValidationRules.ts +msgid "Password must be at least {minimumPasswordLength} characters" msgstr "" #: src/pages/auth/PasswordRecoveryPage.tsx diff --git a/commafeed-client/src/locales/pl/messages.po b/commafeed-client/src/locales/pl/messages.po index b2016705..2d21886f 100644 --- a/commafeed-client/src/locales/pl/messages.po +++ b/commafeed-client/src/locales/pl/messages.po @@ -771,11 +771,8 @@ msgstr "Kategoria nadrzędna" msgid "Password" msgstr "Hasło" -#. placeholder {0}: serverInfos.minimumPasswordLength -#: src/components/settings/ProfileSettings.tsx -#: src/pages/auth/InitialSetupPage.tsx -#: src/pages/auth/RegistrationPage.tsx -msgid "Password must be at least {0} characters" +#: src/hooks/useValidationRules.ts +msgid "Password must be at least {minimumPasswordLength} characters" msgstr "" #: src/pages/auth/PasswordRecoveryPage.tsx diff --git a/commafeed-client/src/locales/pt/messages.po b/commafeed-client/src/locales/pt/messages.po index 75cd8014..a4100f3b 100644 --- a/commafeed-client/src/locales/pt/messages.po +++ b/commafeed-client/src/locales/pt/messages.po @@ -771,11 +771,8 @@ msgstr "Categoria Pai" msgid "Password" msgstr "Senha" -#. placeholder {0}: serverInfos.minimumPasswordLength -#: src/components/settings/ProfileSettings.tsx -#: src/pages/auth/InitialSetupPage.tsx -#: src/pages/auth/RegistrationPage.tsx -msgid "Password must be at least {0} characters" +#: src/hooks/useValidationRules.ts +msgid "Password must be at least {minimumPasswordLength} characters" msgstr "" #: src/pages/auth/PasswordRecoveryPage.tsx diff --git a/commafeed-client/src/locales/ru/messages.po b/commafeed-client/src/locales/ru/messages.po index 91a522e0..d35dca3d 100644 --- a/commafeed-client/src/locales/ru/messages.po +++ b/commafeed-client/src/locales/ru/messages.po @@ -771,11 +771,8 @@ msgstr "Родительская категория" msgid "Password" msgstr "Пароль" -#. placeholder {0}: serverInfos.minimumPasswordLength -#: src/components/settings/ProfileSettings.tsx -#: src/pages/auth/InitialSetupPage.tsx -#: src/pages/auth/RegistrationPage.tsx -msgid "Password must be at least {0} characters" +#: src/hooks/useValidationRules.ts +msgid "Password must be at least {minimumPasswordLength} characters" msgstr "" #: src/pages/auth/PasswordRecoveryPage.tsx diff --git a/commafeed-client/src/locales/sk/messages.po b/commafeed-client/src/locales/sk/messages.po index 41db68d9..3076dfb6 100644 --- a/commafeed-client/src/locales/sk/messages.po +++ b/commafeed-client/src/locales/sk/messages.po @@ -771,11 +771,8 @@ msgstr "Rodičovská kategória" msgid "Password" msgstr "Heslo" -#. placeholder {0}: serverInfos.minimumPasswordLength -#: src/components/settings/ProfileSettings.tsx -#: src/pages/auth/InitialSetupPage.tsx -#: src/pages/auth/RegistrationPage.tsx -msgid "Password must be at least {0} characters" +#: src/hooks/useValidationRules.ts +msgid "Password must be at least {minimumPasswordLength} characters" msgstr "" #: src/pages/auth/PasswordRecoveryPage.tsx diff --git a/commafeed-client/src/locales/sv/messages.po b/commafeed-client/src/locales/sv/messages.po index c3384600..a57a1d96 100644 --- a/commafeed-client/src/locales/sv/messages.po +++ b/commafeed-client/src/locales/sv/messages.po @@ -771,11 +771,8 @@ msgstr "Föräldrakategori" msgid "Password" msgstr "Lösenord" -#. placeholder {0}: serverInfos.minimumPasswordLength -#: src/components/settings/ProfileSettings.tsx -#: src/pages/auth/InitialSetupPage.tsx -#: src/pages/auth/RegistrationPage.tsx -msgid "Password must be at least {0} characters" +#: src/hooks/useValidationRules.ts +msgid "Password must be at least {minimumPasswordLength} characters" msgstr "" #: src/pages/auth/PasswordRecoveryPage.tsx diff --git a/commafeed-client/src/locales/tr/messages.po b/commafeed-client/src/locales/tr/messages.po index 8e44cb20..26eba758 100644 --- a/commafeed-client/src/locales/tr/messages.po +++ b/commafeed-client/src/locales/tr/messages.po @@ -771,11 +771,8 @@ msgstr "Üst Kategori" msgid "Password" msgstr "Şifre" -#. placeholder {0}: serverInfos.minimumPasswordLength -#: src/components/settings/ProfileSettings.tsx -#: src/pages/auth/InitialSetupPage.tsx -#: src/pages/auth/RegistrationPage.tsx -msgid "Password must be at least {0} characters" +#: src/hooks/useValidationRules.ts +msgid "Password must be at least {minimumPasswordLength} characters" msgstr "" #: src/pages/auth/PasswordRecoveryPage.tsx diff --git a/commafeed-client/src/locales/zh/messages.po b/commafeed-client/src/locales/zh/messages.po index 9e3e3891..bb03649d 100644 --- a/commafeed-client/src/locales/zh/messages.po +++ b/commafeed-client/src/locales/zh/messages.po @@ -771,11 +771,8 @@ msgstr "父类别" msgid "Password" msgstr "密码" -#. placeholder {0}: serverInfos.minimumPasswordLength -#: src/components/settings/ProfileSettings.tsx -#: src/pages/auth/InitialSetupPage.tsx -#: src/pages/auth/RegistrationPage.tsx -msgid "Password must be at least {0} characters" +#: src/hooks/useValidationRules.ts +msgid "Password must be at least {minimumPasswordLength} characters" msgstr "" #: src/pages/auth/PasswordRecoveryPage.tsx diff --git a/commafeed-client/src/pages/auth/InitialSetupPage.tsx b/commafeed-client/src/pages/auth/InitialSetupPage.tsx index c4cb779c..c9e49c0f 100644 --- a/commafeed-client/src/pages/auth/InitialSetupPage.tsx +++ b/commafeed-client/src/pages/auth/InitialSetupPage.tsx @@ -6,15 +6,16 @@ import { useForm } from "@mantine/form" import { useAsyncCallback } from "react-async-hook" import { client, errorToStrings } from "@/app/client" import { redirectToRootCategory } from "@/app/redirect/thunks" -import { useAppDispatch, useAppSelector } from "@/app/store" +import { useAppDispatch } from "@/app/store" import type { InitialSetupRequest } from "@/app/types" import { Alert } from "@/components/Alert" +import { useValidationRules } from "@/hooks/useValidationRules" import { PageTitle } from "@/pages/PageTitle" export function InitialSetupPage() { - const serverInfos = useAppSelector(state => state.server.serverInfos) const dispatch = useAppDispatch() const { _ } = useLingui() + const validationRules = useValidationRules() const form = useForm({ initialValues: { @@ -23,10 +24,7 @@ export function InitialSetupPage() { email: "", }, validate: { - password: value => - serverInfos && value.length < serverInfos.minimumPasswordLength - ? _(msg`Password must be at least ${serverInfos.minimumPasswordLength} characters`) - : null, + password: validationRules.password, }, validateInputOnChange: true, }) diff --git a/commafeed-client/src/pages/auth/RegistrationPage.tsx b/commafeed-client/src/pages/auth/RegistrationPage.tsx index d1f70e87..e529d598 100644 --- a/commafeed-client/src/pages/auth/RegistrationPage.tsx +++ b/commafeed-client/src/pages/auth/RegistrationPage.tsx @@ -10,12 +10,14 @@ import { redirectToRootCategory } from "@/app/redirect/thunks" import { useAppDispatch, useAppSelector } from "@/app/store" import type { RegistrationRequest } from "@/app/types" import { Alert } from "@/components/Alert" +import { useValidationRules } from "@/hooks/useValidationRules" import { PageTitle } from "@/pages/PageTitle" export function RegistrationPage() { const serverInfos = useAppSelector(state => state.server.serverInfos) const dispatch = useAppDispatch() const { _ } = useLingui() + const validationRules = useValidationRules() const form = useForm({ initialValues: { @@ -24,10 +26,7 @@ export function RegistrationPage() { email: "", }, validate: { - password: value => - serverInfos && value.length < serverInfos.minimumPasswordLength - ? _(msg`Password must be at least ${serverInfos.minimumPasswordLength} characters`) - : null, + password: validationRules.password, }, validateInputOnChange: true, })