Merged in feat/LOY-183-Make-Other-Password-Inputs-Maskable (pull request #1569)

feat(LOY-183): Make Current & Retype Password Inputs Maskable in My Profile Edit Form

* feat(LOY-183): implement PasswordInput and PasswordToggleButton components

- Added PasswordInput component for password fields with visibility toggle.
- Introduced PasswordToggleButton for toggling password visibility.
- Updated NewPassword component to utilize the new PasswordInput.

* refactor(LOY-183): replace NewPassword component with PasswordInput


Approved-by: Christian Andolf
This commit is contained in:
Chuma Mcphoy (We Ahead)
2025-03-21 08:15:55 +00:00
parent 0666b62a4c
commit 85cd247f79
5 changed files with 53 additions and 33 deletions

View File

@@ -1,5 +1,5 @@
"use client" "use client"
// import { useFormStatus } from "react-dom"
import { useIntl } from "react-intl" import { useIntl } from "react-intl"
import { getLocalizedLanguageOptions } from "@/constants/languages" import { getLocalizedLanguageOptions } from "@/constants/languages"
@@ -8,7 +8,7 @@ import Divider from "@/components/TempDesignSystem/Divider"
import CountrySelect from "@/components/TempDesignSystem/Form/Country" import CountrySelect from "@/components/TempDesignSystem/Form/Country"
import DateSelect from "@/components/TempDesignSystem/Form/Date" import DateSelect from "@/components/TempDesignSystem/Form/Date"
import Input from "@/components/TempDesignSystem/Form/Input" import Input from "@/components/TempDesignSystem/Form/Input"
import NewPassword from "@/components/TempDesignSystem/Form/NewPassword" import PasswordInput from "@/components/TempDesignSystem/Form/PasswordInput"
import Phone from "@/components/TempDesignSystem/Form/Phone" import Phone from "@/components/TempDesignSystem/Form/Phone"
import Select from "@/components/TempDesignSystem/Form/Select" import Select from "@/components/TempDesignSystem/Form/Select"
import Body from "@/components/TempDesignSystem/Text/Body" import Body from "@/components/TempDesignSystem/Text/Body"
@@ -20,8 +20,6 @@ export default function FormContent() {
const intl = useIntl() const intl = useIntl()
const lang = useLang() const lang = useLang()
// const { pending } = useFormStatus()
const languageOptions = getLocalizedLanguageOptions(lang) const languageOptions = getLocalizedLanguageOptions(lang)
const city = intl.formatMessage({ id: "City" }) const city = intl.formatMessage({ id: "City" })
const country = intl.formatMessage({ id: "Country" }) const country = intl.formatMessage({ id: "Country" })
@@ -81,20 +79,16 @@ export default function FormContent() {
{intl.formatMessage({ id: "Password" })} {intl.formatMessage({ id: "Password" })}
</Body> </Body>
</header> </header>
<Input <PasswordInput
data-hj-suppress data-hj-suppress
label={currentPassword} label={currentPassword}
name="password" name="password"
type="password"
/> />
{/* visibilityToggleable set to false as feature is done for signup first */} <PasswordInput data-hj-suppress isNewPassword name="newPassword" />
{/* likely we can remove the prop altogether once signup launches */} <PasswordInput
<NewPassword data-hj-suppress visibilityToggleable={false} />
<Input
data-hj-suppress data-hj-suppress
label={retypeNewPassword} label={retypeNewPassword}
name="retypeNewPassword" name="retypeNewPassword"
type="password"
/> />
</section> </section>
</> </>

View File

@@ -16,7 +16,7 @@ import Checkbox from "@/components/TempDesignSystem/Form/Checkbox"
import CountrySelect from "@/components/TempDesignSystem/Form/Country" import CountrySelect from "@/components/TempDesignSystem/Form/Country"
import DateSelect from "@/components/TempDesignSystem/Form/Date" import DateSelect from "@/components/TempDesignSystem/Form/Date"
import Input from "@/components/TempDesignSystem/Form/Input" import Input from "@/components/TempDesignSystem/Form/Input"
import NewPassword from "@/components/TempDesignSystem/Form/NewPassword" import PasswordInput from "@/components/TempDesignSystem/Form/PasswordInput"
import Phone from "@/components/TempDesignSystem/Form/Phone" import Phone from "@/components/TempDesignSystem/Form/Phone"
import Link from "@/components/TempDesignSystem/Link" import Link from "@/components/TempDesignSystem/Link"
import Body from "@/components/TempDesignSystem/Text/Body" import Body from "@/components/TempDesignSystem/Text/Body"
@@ -156,9 +156,10 @@ export default function SignupForm({ title }: SignUpFormProps) {
{intl.formatMessage({ id: "Password" })} {intl.formatMessage({ id: "Password" })}
</Subtitle> </Subtitle>
</header> </header>
<NewPassword <PasswordInput
name="password" name="password"
label={intl.formatMessage({ id: "Password" })} label={intl.formatMessage({ id: "Password" })}
isNewPassword
/> />
</section> </section>
<section className={styles.terms}> <section className={styles.terms}>

View File

@@ -12,25 +12,27 @@ import {
EyeShowIcon, EyeShowIcon,
InfoCircleIcon, InfoCircleIcon,
} from "@/components/Icons" } from "@/components/Icons"
import Button from "@/components/TempDesignSystem/Button"
import AriaInputWithLabel from "@/components/TempDesignSystem/Form/Input/AriaInputWithLabel" import AriaInputWithLabel from "@/components/TempDesignSystem/Form/Input/AriaInputWithLabel"
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 Button from "../../Button" import styles from "./passwordInput.module.css"
import { type IconProps, type NewPasswordProps } from "./newPassword"
import styles from "./newPassword.module.css"
import type { PasswordValidatorKey } from "@/types/components/form/newPassword" import type { PasswordValidatorKey } from "@/types/components/form/newPassword"
import type { IconProps, PasswordInputProps } from "./passwordInput"
export default function NewPassword({ export default function PasswordInput({
name = "newPassword", name = "password",
label,
"aria-label": ariaLabel, "aria-label": ariaLabel,
disabled = false, disabled = false,
placeholder = "", placeholder = "",
registerOptions = {}, registerOptions = {},
visibilityToggleable = true, visibilityToggleable = true,
}: NewPasswordProps) { isNewPassword = false,
className = "",
}: PasswordInputProps) {
const { control } = useFormContext() const { control } = useFormContext()
const intl = useIntl() const intl = useIntl()
const [isPasswordVisible, setIsPasswordVisible] = useState(false) const [isPasswordVisible, setIsPasswordVisible] = useState(false)
@@ -42,10 +44,13 @@ export default function NewPassword({
name={name} name={name}
rules={registerOptions} rules={registerOptions}
render={({ field, fieldState, formState }) => { render={({ field, fieldState, formState }) => {
const errors = Object.values(formState.errors[name]?.types ?? []).flat() const errors = isNewPassword
? Object.values(formState.errors[name]?.types ?? []).flat()
: []
return ( return (
<TextField <TextField
className={className}
aria-label={ariaLabel} aria-label={ariaLabel}
isDisabled={field.disabled} isDisabled={field.disabled}
isInvalid={fieldState.invalid} isInvalid={fieldState.invalid}
@@ -64,7 +69,12 @@ export default function NewPassword({
{...field} {...field}
aria-labelledby={field.name} aria-labelledby={field.name}
id={field.name} id={field.name}
label={intl.formatMessage({ id: "New password" })} label={
label ||
(isNewPassword
? intl.formatMessage({ id: "New password" })
: intl.formatMessage({ id: "Password" }))
}
placeholder={placeholder} placeholder={placeholder}
type={ type={
visibilityToggleable && isPasswordVisible visibilityToggleable && isPasswordVisible
@@ -74,24 +84,38 @@ export default function NewPassword({
/> />
{visibilityToggleable ? ( {visibilityToggleable ? (
<Button <Button
className={styles.eyeIcon}
type="button" type="button"
variant="icon" variant="icon"
size="small" size="small"
intent="tertiary" intent="tertiary"
onClick={() => setIsPasswordVisible((value) => !value)} onClick={() => setIsPasswordVisible((value) => !value)}
aria-label={
isPasswordVisible ? "Hide password" : "Show password"
}
aria-controls={field.name}
className={styles.toggleButton}
> >
{isPasswordVisible ? <EyeHideIcon /> : <EyeShowIcon />} {isPasswordVisible ? <EyeHideIcon /> : <EyeShowIcon />}
</Button> </Button>
) : null} ) : null}
</div> </div>
<PasswordValidation value={field.value} errors={errors} /> {isNewPassword && (
<NewPasswordValidation value={field.value} errors={errors} />
)}
{!field.value && fieldState.error ? ( {isNewPassword ? (
!field.value && fieldState.error ? (
<Caption className={styles.error} fontOnly>
<InfoCircleIcon color="red" />
{fieldState.error.message}
</Caption>
) : null
) : fieldState.error ? (
<Caption className={styles.error} fontOnly> <Caption className={styles.error} fontOnly>
<InfoCircleIcon color="red" /> <InfoCircleIcon color="red" />
{fieldState.error.message} {fieldState.error &&
intl.formatMessage({ id: fieldState.error.message })}
</Caption> </Caption>
) : null} ) : null}
</TextField> </TextField>
@@ -109,7 +133,7 @@ function Icon({ errorMessage, errors }: IconProps) {
) )
} }
function PasswordValidation({ function NewPasswordValidation({
value, value,
errors, errors,
}: { }: {

View File

@@ -76,17 +76,17 @@
padding-top: var(--Spacing-x1); padding-top: var(--Spacing-x1);
} }
.eyeIcon { .inputWrapper {
position: relative;
}
.toggleButton {
position: absolute; position: absolute;
right: var(--Spacing-x2); right: var(--Spacing-x2);
top: 50%; top: 50%;
transform: translateY(-50%); transform: translateY(-50%);
} }
.inputWrapper {
position: relative;
}
/* Hide the built-in password reveal icon in Microsoft Edge. /* Hide the built-in password reveal icon in Microsoft Edge.
* See: https://learn.microsoft.com/en-us/microsoft-edge/web-platform/password-reveal * See: https://learn.microsoft.com/en-us/microsoft-edge/web-platform/password-reveal
*/ */

View File

@@ -1,10 +1,11 @@
import type { RegisterOptions } from "react-hook-form" import type { RegisterOptions } from "react-hook-form"
export interface NewPasswordProps export interface PasswordInputProps
extends React.InputHTMLAttributes<HTMLInputElement> { extends React.InputHTMLAttributes<HTMLInputElement> {
label?: string label?: string
registerOptions?: RegisterOptions registerOptions?: RegisterOptions
visibilityToggleable?: boolean visibilityToggleable?: boolean
isNewPassword?: boolean
} }
export interface IconProps { export interface IconProps {