fix: visibility toggle for new password disabled on edit profile

This commit is contained in:
Michael Zetterberg
2024-10-16 12:05:08 +02:00
parent 6be0510927
commit c1a3b9ae8a
3 changed files with 26 additions and 14 deletions

View File

@@ -73,7 +73,9 @@ export default function FormContent() {
</Body>
</header>
<Input label={currentPassword} name="password" type="password" />
<NewPassword />
{/* visibilityToggleable set to false as feature is done for signup first */}
{/* likely we can remove the prop altogether once signup launches */}
<NewPassword visibilityToggleable={false} />
<Input
label={retypeNewPassword}
name="retypeNewPassword"

View File

@@ -30,10 +30,11 @@ export default function NewPassword({
placeholder = "",
registerOptions = {},
label,
visibilityToggleable = true,
}: NewPasswordProps) {
const { control } = useFormContext()
const intl = useIntl()
const [isPasswordVisible, setPasswordVisible] = useState(false)
const [isPasswordVisible, setIsPasswordVisible] = useState(false)
function getErrorMessage(key: PasswordValidatorKey) {
switch (key) {
@@ -69,7 +70,9 @@ export default function NewPassword({
onChange={field.onChange}
validationBehavior="aria"
value={field.value}
type={isPasswordVisible ? "text" : "password"}
type={
visibilityToggleable && isPasswordVisible ? "text" : "password"
}
>
<div className={styles.inputWrapper}>
<AriaInputWithLabel
@@ -78,18 +81,24 @@ export default function NewPassword({
id={field.name}
label={intl.formatMessage({ id: "New password" })}
placeholder={placeholder}
type={isPasswordVisible ? "text" : "password"}
type={
visibilityToggleable && isPasswordVisible
? "text"
: "password"
}
/>
<Button
className={styles.eyeIcon}
type="button"
variant="icon"
size="small"
intent="tertiary"
onClick={() => setPasswordVisible(!isPasswordVisible)}
>
{isPasswordVisible ? <EyeHideIcon /> : <EyeShowIcon />}
</Button>
{visibilityToggleable ? (
<Button
className={styles.eyeIcon}
type="button"
variant="icon"
size="small"
intent="tertiary"
onClick={() => setIsPasswordVisible((value) => !value)}
>
{isPasswordVisible ? <EyeHideIcon /> : <EyeShowIcon />}
</Button>
) : null}
</div>
{field.value ? (
<div className={styles.errors}>

View File

@@ -4,6 +4,7 @@ export interface NewPasswordProps
extends React.InputHTMLAttributes<HTMLInputElement> {
label?: string
registerOptions?: RegisterOptions
visibilityToggleable?: boolean
}
export interface IconProps {