"use client" import { useState } from "react" import { TextField } from "react-aria-components" import { Controller, type RegisterOptions, useFormContext, } from "react-hook-form" import { useIntl } from "react-intl" import { IconButton } from "@scandic-hotels/design-system/IconButton" import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon" import { Input } from "@scandic-hotels/design-system/Input" import { Typography } from "@scandic-hotels/design-system/Typography" import { getErrorMessage } from "@/utils/getErrorMessage" import { NewPasswordValidation } from "./NewPasswordValidation" import styles from "./passwordInput.module.css" interface PasswordInputProps extends React.InputHTMLAttributes { label?: string registerOptions?: RegisterOptions visibilityToggleable?: boolean isNewPassword?: boolean } export default function PasswordInput({ name = "password", label, "aria-label": ariaLabel, disabled = false, placeholder, registerOptions = {}, visibilityToggleable = true, isNewPassword = false, className = "", }: PasswordInputProps) { const { control } = useFormContext() const intl = useIntl() const [isPasswordVisible, setIsPasswordVisible] = useState(false) return ( { const errors = isNewPassword ? Object.values(formState.errors[name]?.types ?? []).flat() : [] return (
{visibilityToggleable ? ( setIsPasswordVisible((value) => !value)} aria-label={ isPasswordVisible ? intl.formatMessage({ id: "passwordInput.hidePassword", defaultMessage: "Hide password", }) : intl.formatMessage({ id: "passwordInput.showPassword", defaultMessage: "Show password", }) } aria-controls={field.name} className={styles.toggleButton} > ) : null}
{isNewPassword ? ( ) : null} {isNewPassword ? ( !field.value && fieldState.error ? ( ) : null ) : fieldState.error ? ( ) : null}
) }} /> ) } function ErrorMessage({ errorMessage }: { errorMessage?: string }) { const intl = useIntl() return ( ) }