Merged in fix/LOY-227-password-input-validation-crash (pull request #1835)

fix(LOY-227): use new getErrorMessage for PasswordInput

* fix(LOY-227): improve error message handling in PasswordInput component


Approved-by: Christian Andolf
Approved-by: Linus Flood
This commit is contained in:
Chuma Mcphoy (We Ahead)
2025-04-22 08:13:30 +00:00
parent e62e87e306
commit 8a68a79ac4

View File

@@ -12,6 +12,8 @@ import AriaInputWithLabel from "@/components/TempDesignSystem/Form/Input/AriaInp
import Caption from "@/components/TempDesignSystem/Text/Caption" import Caption from "@/components/TempDesignSystem/Text/Caption"
import { passwordValidators } from "@/utils/zod/passwordValidator" import { passwordValidators } from "@/utils/zod/passwordValidator"
import { getErrorMessage } from "../Input/errors"
import styles from "./passwordInput.module.css" import styles from "./passwordInput.module.css"
import type { PasswordValidatorKey } from "@/types/components/form/newPassword" import type { PasswordValidatorKey } from "@/types/components/form/newPassword"
@@ -109,25 +111,21 @@ export default function PasswordInput({
) : null} ) : null}
</div> </div>
{isNewPassword && ( {isNewPassword ? (
<NewPasswordValidation value={field.value} errors={errors} /> <NewPasswordValidation value={field.value} errors={errors} />
)} ) : null}
{isNewPassword ? ( {isNewPassword ? (
!field.value && fieldState.error ? ( !field.value && fieldState.error ? (
<Caption className={styles.error} fontOnly> <Caption className={styles.error} fontOnly>
<MaterialIcon icon="info" color="Icon/Feedback/Error" /> <MaterialIcon icon="info" color="Icon/Feedback/Error" />
{fieldState.error.message} {getErrorMessage(intl, fieldState.error.message)}
</Caption> </Caption>
) : null ) : null
) : fieldState.error ? ( ) : fieldState.error ? (
<Caption className={styles.error} fontOnly> <Caption className={styles.error} fontOnly>
<MaterialIcon icon="info" color="Icon/Feedback/Error" /> <MaterialIcon icon="info" color="Icon/Feedback/Error" />
{fieldState.error && {getErrorMessage(intl, fieldState.error.message)}
intl.formatMessage({
// eslint-disable-next-line formatjs/enforce-default-message
defaultMessage: fieldState.error.message,
})}
</Caption> </Caption>
) : null} ) : null}
</TextField> </TextField>