diff --git a/components/TempDesignSystem/Form/NewPassword/index.tsx b/components/TempDesignSystem/Form/NewPassword/index.tsx index 2c0a6d31a..818f41492 100644 --- a/components/TempDesignSystem/Form/NewPassword/index.tsx +++ b/components/TempDesignSystem/Form/NewPassword/index.tsx @@ -36,21 +36,6 @@ export default function NewPassword({ const intl = useIntl() const [isPasswordVisible, setIsPasswordVisible] = useState(false) - function getErrorMessage(key: PasswordValidatorKey) { - switch (key) { - case "length": - return `10 ${intl.formatMessage({ id: "to" })} 40 ${intl.formatMessage({ id: "characters" })}` - case "hasUppercase": - return `1 ${intl.formatMessage({ id: "uppercase letter" })}` - case "hasLowercase": - return `1 ${intl.formatMessage({ id: "lowercase letter" })}` - case "hasNumber": - return `1 ${intl.formatMessage({ id: "number" })}` - case "hasSpecialChar": - return `1 ${intl.formatMessage({ id: "special character" })}` - } - } - return ( { const errors = Object.values(formState.errors[name]?.types ?? []).flat() + return ( ) : null} - {field.value ? ( -
- {Object.entries(passwordValidators).map( - ([key, { message }]) => ( - - - - {getErrorMessage(key as PasswordValidatorKey)} - - - ) - )} -
- ) : null} + + + {!field.value && fieldState.error ? ( @@ -134,3 +109,43 @@ function Icon({ errorMessage, errors }: IconProps) { ) } + +function PasswordValidation({ + value, + errors, +}: { + value: string + errors: string[] +}) { + const intl = useIntl() + + if (!value) return null + + function getErrorMessage(key: PasswordValidatorKey) { + switch (key) { + case "length": + return `10 ${intl.formatMessage({ id: "to" })} 40 ${intl.formatMessage({ id: "characters" })}` + case "hasUppercase": + return `1 ${intl.formatMessage({ id: "uppercase letter" })}` + case "hasLowercase": + return `1 ${intl.formatMessage({ id: "lowercase letter" })}` + case "hasNumber": + return `1 ${intl.formatMessage({ id: "number" })}` + case "hasSpecialChar": + return `1 ${intl.formatMessage({ id: "special character" })}` + } + } + + return ( +
+ {Object.entries(passwordValidators).map(([key, { message }]) => ( + + + + {getErrorMessage(key as PasswordValidatorKey)} + + + ))} +
+ ) +}