make password match rule reusable

This commit is contained in:
Athou
2026-01-20 08:54:23 +01:00
parent afe957ba59
commit 3c8ac35a46
31 changed files with 32 additions and 59 deletions

View File

@@ -1,4 +1,3 @@
import { msg } from "@lingui/core/macro"
import { useLingui } from "@lingui/react"
import { Trans } from "@lingui/react/macro"
import { Anchor, Box, Button, Checkbox, Divider, Group, Input, PasswordInput, Stack, Text, TextInput } from "@mantine/core"
@@ -29,7 +28,7 @@ export function ProfileSettings() {
const form = useForm<FormData>({
validate: {
newPassword: validationRules.password,
newPasswordConfirmation: (value, values) => (value !== values.newPassword ? _(msg`Passwords do not match`) : null),
newPasswordConfirmation: (value, values) => validationRules.passwordConfirmation(value, values.newPassword),
},
validateInputOnChange: true,
})

View File

@@ -11,5 +11,7 @@ export function useValidationRules() {
value && minimumPasswordLength && value.length < minimumPasswordLength
? _(msg`Password must be at least ${minimumPasswordLength} characters`)
: null,
passwordConfirmation: (newPasswordConfirmation: string | undefined, newPassword: string | undefined) =>
newPasswordConfirmation && newPasswordConfirmation !== newPassword ? _(msg`Passwords do not match`) : null,
}
}

View File

@@ -794,8 +794,7 @@ msgstr ""
msgid "Password Recovery"
msgstr "استعادة كلمة المرور"
#: src/components/settings/ProfileSettings.tsx
#: src/pages/auth/PasswordResetPage.tsx
#: src/hooks/useValidationRules.ts
msgid "Passwords do not match"
msgstr "كلمات المرور غير متطابقة"

View File

@@ -794,8 +794,7 @@ msgstr ""
msgid "Password Recovery"
msgstr "Recuperació de contrasenya"
#: src/components/settings/ProfileSettings.tsx
#: src/pages/auth/PasswordResetPage.tsx
#: src/hooks/useValidationRules.ts
msgid "Passwords do not match"
msgstr "Les contrasenyes no coincideixen"

View File

@@ -794,8 +794,7 @@ msgstr ""
msgid "Password Recovery"
msgstr "Obnovení hesla"
#: src/components/settings/ProfileSettings.tsx
#: src/pages/auth/PasswordResetPage.tsx
#: src/hooks/useValidationRules.ts
msgid "Passwords do not match"
msgstr "Hesla se neshodují"

View File

@@ -794,8 +794,7 @@ msgstr ""
msgid "Password Recovery"
msgstr "Adfer Cyfrinair"
#: src/components/settings/ProfileSettings.tsx
#: src/pages/auth/PasswordResetPage.tsx
#: src/hooks/useValidationRules.ts
msgid "Passwords do not match"
msgstr "Nid yw cyfrineiriau yn cyfateb"

View File

@@ -794,8 +794,7 @@ msgstr ""
msgid "Password Recovery"
msgstr "Gendannelse af adgangskode"
#: src/components/settings/ProfileSettings.tsx
#: src/pages/auth/PasswordResetPage.tsx
#: src/hooks/useValidationRules.ts
msgid "Passwords do not match"
msgstr "Adgangskoder stemmer ikke overens"

View File

@@ -794,8 +794,7 @@ msgstr ""
msgid "Password Recovery"
msgstr "Passwortwiederherstellung"
#: src/components/settings/ProfileSettings.tsx
#: src/pages/auth/PasswordResetPage.tsx
#: src/hooks/useValidationRules.ts
msgid "Passwords do not match"
msgstr "Passwörter stimmen nicht überein"

View File

@@ -794,8 +794,7 @@ msgstr "Password must be at least {minimumPasswordLength} characters"
msgid "Password Recovery"
msgstr "Password Recovery"
#: src/components/settings/ProfileSettings.tsx
#: src/pages/auth/PasswordResetPage.tsx
#: src/hooks/useValidationRules.ts
msgid "Passwords do not match"
msgstr "Passwords do not match"

View File

@@ -795,8 +795,7 @@ msgstr ""
msgid "Password Recovery"
msgstr "Recuperación de contraseña"
#: src/components/settings/ProfileSettings.tsx
#: src/pages/auth/PasswordResetPage.tsx
#: src/hooks/useValidationRules.ts
msgid "Passwords do not match"
msgstr "Las contraseñas no coinciden"

View File

@@ -794,8 +794,7 @@ msgstr ""
msgid "Password Recovery"
msgstr "بازیابی رمز عبور"
#: src/components/settings/ProfileSettings.tsx
#: src/pages/auth/PasswordResetPage.tsx
#: src/hooks/useValidationRules.ts
msgid "Passwords do not match"
msgstr "گذرواژه ها مطابقت ندارند"

View File

@@ -794,8 +794,7 @@ msgstr ""
msgid "Password Recovery"
msgstr "Salasanan palautus"
#: src/components/settings/ProfileSettings.tsx
#: src/pages/auth/PasswordResetPage.tsx
#: src/hooks/useValidationRules.ts
msgid "Passwords do not match"
msgstr "Salasanat eivät täsmää"

View File

@@ -794,8 +794,7 @@ msgstr ""
msgid "Password Recovery"
msgstr "Récupération de mot de passe"
#: src/components/settings/ProfileSettings.tsx
#: src/pages/auth/PasswordResetPage.tsx
#: src/hooks/useValidationRules.ts
msgid "Passwords do not match"
msgstr "Les mots de passe ne correspondent pas"

View File

@@ -795,8 +795,7 @@ msgstr ""
msgid "Password Recovery"
msgstr "Recuperación do contrasinal"
#: src/components/settings/ProfileSettings.tsx
#: src/pages/auth/PasswordResetPage.tsx
#: src/hooks/useValidationRules.ts
msgid "Passwords do not match"
msgstr "Os contrasinais non coinciden"

View File

@@ -794,8 +794,7 @@ msgstr ""
msgid "Password Recovery"
msgstr "Jelszó helyreállítás"
#: src/components/settings/ProfileSettings.tsx
#: src/pages/auth/PasswordResetPage.tsx
#: src/hooks/useValidationRules.ts
msgid "Passwords do not match"
msgstr "A jelszavak nem egyeznek"

View File

@@ -794,8 +794,7 @@ msgstr ""
msgid "Password Recovery"
msgstr "Pemulihan Kata Sandi"
#: src/components/settings/ProfileSettings.tsx
#: src/pages/auth/PasswordResetPage.tsx
#: src/hooks/useValidationRules.ts
msgid "Passwords do not match"
msgstr "Kata sandi tidak cocok"

View File

@@ -794,8 +794,7 @@ msgstr ""
msgid "Password Recovery"
msgstr "Recupero password"
#: src/components/settings/ProfileSettings.tsx
#: src/pages/auth/PasswordResetPage.tsx
#: src/hooks/useValidationRules.ts
msgid "Passwords do not match"
msgstr "Le password non corrispondono"

View File

@@ -794,8 +794,7 @@ msgstr ""
msgid "Password Recovery"
msgstr "パスワード回復"
#: src/components/settings/ProfileSettings.tsx
#: src/pages/auth/PasswordResetPage.tsx
#: src/hooks/useValidationRules.ts
msgid "Passwords do not match"
msgstr "パスワードが一致しません"

View File

@@ -794,8 +794,7 @@ msgstr ""
msgid "Password Recovery"
msgstr "비밀번호 복구"
#: src/components/settings/ProfileSettings.tsx
#: src/pages/auth/PasswordResetPage.tsx
#: src/hooks/useValidationRules.ts
msgid "Passwords do not match"
msgstr "비밀번호가 일치하지 않습니다"

View File

@@ -794,8 +794,7 @@ msgstr ""
msgid "Password Recovery"
msgstr "Pemulihan Kata Laluan"
#: src/components/settings/ProfileSettings.tsx
#: src/pages/auth/PasswordResetPage.tsx
#: src/hooks/useValidationRules.ts
msgid "Passwords do not match"
msgstr "Kata laluan tidak sepadan"

View File

@@ -794,8 +794,7 @@ msgstr ""
msgid "Password Recovery"
msgstr "Passordgjenoppretting"
#: src/components/settings/ProfileSettings.tsx
#: src/pages/auth/PasswordResetPage.tsx
#: src/hooks/useValidationRules.ts
msgid "Passwords do not match"
msgstr "Passordene samsvarer ikke"

View File

@@ -794,8 +794,7 @@ msgstr ""
msgid "Password Recovery"
msgstr "Wachtwoordherstel"
#: src/components/settings/ProfileSettings.tsx
#: src/pages/auth/PasswordResetPage.tsx
#: src/hooks/useValidationRules.ts
msgid "Passwords do not match"
msgstr "Wachtwoorden komen niet overeen"

View File

@@ -794,8 +794,7 @@ msgstr ""
msgid "Password Recovery"
msgstr "Passordgjenoppretting"
#: src/components/settings/ProfileSettings.tsx
#: src/pages/auth/PasswordResetPage.tsx
#: src/hooks/useValidationRules.ts
msgid "Passwords do not match"
msgstr "Passordene samsvarer ikke"

View File

@@ -794,8 +794,7 @@ msgstr ""
msgid "Password Recovery"
msgstr "Odzyskiwanie hasła"
#: src/components/settings/ProfileSettings.tsx
#: src/pages/auth/PasswordResetPage.tsx
#: src/hooks/useValidationRules.ts
msgid "Passwords do not match"
msgstr "Hasła nie pasują"

View File

@@ -794,8 +794,7 @@ msgstr ""
msgid "Password Recovery"
msgstr "Recuperação de Senha"
#: src/components/settings/ProfileSettings.tsx
#: src/pages/auth/PasswordResetPage.tsx
#: src/hooks/useValidationRules.ts
msgid "Passwords do not match"
msgstr "Senhas não coincidem"

View File

@@ -794,8 +794,7 @@ msgstr ""
msgid "Password Recovery"
msgstr "Восстановление пароля"
#: src/components/settings/ProfileSettings.tsx
#: src/pages/auth/PasswordResetPage.tsx
#: src/hooks/useValidationRules.ts
msgid "Passwords do not match"
msgstr "Пароли не совпадают"

View File

@@ -794,8 +794,7 @@ msgstr ""
msgid "Password Recovery"
msgstr "Obnovenie hesla"
#: src/components/settings/ProfileSettings.tsx
#: src/pages/auth/PasswordResetPage.tsx
#: src/hooks/useValidationRules.ts
msgid "Passwords do not match"
msgstr "Heslá sa nezhodujú"

View File

@@ -794,8 +794,7 @@ msgstr ""
msgid "Password Recovery"
msgstr "Lösenordsåterställning"
#: src/components/settings/ProfileSettings.tsx
#: src/pages/auth/PasswordResetPage.tsx
#: src/hooks/useValidationRules.ts
msgid "Passwords do not match"
msgstr "Lösenorden matchar inte"

View File

@@ -794,8 +794,7 @@ msgstr ""
msgid "Password Recovery"
msgstr "Parola Kurtarma"
#: src/components/settings/ProfileSettings.tsx
#: src/pages/auth/PasswordResetPage.tsx
#: src/hooks/useValidationRules.ts
msgid "Passwords do not match"
msgstr "Parolalar eşleşmiyor"

View File

@@ -794,8 +794,7 @@ msgstr "密码最少需要 {minimumPasswordLength} 个字符"
msgid "Password Recovery"
msgstr "密码恢复"
#: src/components/settings/ProfileSettings.tsx
#: src/pages/auth/PasswordResetPage.tsx
#: src/hooks/useValidationRules.ts
msgid "Passwords do not match"
msgstr "密码不匹配"

View File

@@ -32,7 +32,7 @@ export function PasswordResetPage() {
},
validate: {
password: validationRules.password,
passwordConfirmation: (value, values) => (value === values.password ? null : _(msg`Passwords do not match`)),
passwordConfirmation: (value, values) => validationRules.passwordConfirmation(value, values.password),
},
validateInputOnChange: true,
})