From 85cd247f79a11ce7bbb72ed6841437799f861224 Mon Sep 17 00:00:00 2001 From: "Chuma Mcphoy (We Ahead)" Date: Fri, 21 Mar 2025 08:15:55 +0000 Subject: [PATCH] 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 --- .../Forms/Edit/Profile/FormContent/index.tsx | 16 ++---- .../components/Forms/Signup/index.tsx | 5 +- .../{NewPassword => PasswordInput}/index.tsx | 52 ++++++++++++++----- .../passwordInput.module.css} | 10 ++-- .../passwordInput.ts} | 3 +- 5 files changed, 53 insertions(+), 33 deletions(-) rename apps/scandic-web/components/TempDesignSystem/Form/{NewPassword => PasswordInput}/index.tsx (73%) rename apps/scandic-web/components/TempDesignSystem/Form/{NewPassword/newPassword.module.css => PasswordInput/passwordInput.module.css} (99%) rename apps/scandic-web/components/TempDesignSystem/Form/{NewPassword/newPassword.ts => PasswordInput/passwordInput.ts} (81%) diff --git a/apps/scandic-web/components/Forms/Edit/Profile/FormContent/index.tsx b/apps/scandic-web/components/Forms/Edit/Profile/FormContent/index.tsx index 462ba9b2c..cdf5217c5 100644 --- a/apps/scandic-web/components/Forms/Edit/Profile/FormContent/index.tsx +++ b/apps/scandic-web/components/Forms/Edit/Profile/FormContent/index.tsx @@ -1,5 +1,5 @@ "use client" -// import { useFormStatus } from "react-dom" + import { useIntl } from "react-intl" import { getLocalizedLanguageOptions } from "@/constants/languages" @@ -8,7 +8,7 @@ import Divider from "@/components/TempDesignSystem/Divider" import CountrySelect from "@/components/TempDesignSystem/Form/Country" import DateSelect from "@/components/TempDesignSystem/Form/Date" 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 Select from "@/components/TempDesignSystem/Form/Select" import Body from "@/components/TempDesignSystem/Text/Body" @@ -20,8 +20,6 @@ export default function FormContent() { const intl = useIntl() const lang = useLang() - // const { pending } = useFormStatus() - const languageOptions = getLocalizedLanguageOptions(lang) const city = intl.formatMessage({ id: "City" }) const country = intl.formatMessage({ id: "Country" }) @@ -81,20 +79,16 @@ export default function FormContent() { {intl.formatMessage({ id: "Password" })} - - {/* visibilityToggleable set to false as feature is done for signup first */} - {/* likely we can remove the prop altogether once signup launches */} - - + diff --git a/apps/scandic-web/components/Forms/Signup/index.tsx b/apps/scandic-web/components/Forms/Signup/index.tsx index bd5ede0bc..180fb2354 100644 --- a/apps/scandic-web/components/Forms/Signup/index.tsx +++ b/apps/scandic-web/components/Forms/Signup/index.tsx @@ -16,7 +16,7 @@ import Checkbox from "@/components/TempDesignSystem/Form/Checkbox" import CountrySelect from "@/components/TempDesignSystem/Form/Country" import DateSelect from "@/components/TempDesignSystem/Form/Date" 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 Link from "@/components/TempDesignSystem/Link" import Body from "@/components/TempDesignSystem/Text/Body" @@ -156,9 +156,10 @@ export default function SignupForm({ title }: SignUpFormProps) { {intl.formatMessage({ id: "Password" })} -
diff --git a/apps/scandic-web/components/TempDesignSystem/Form/NewPassword/index.tsx b/apps/scandic-web/components/TempDesignSystem/Form/PasswordInput/index.tsx similarity index 73% rename from apps/scandic-web/components/TempDesignSystem/Form/NewPassword/index.tsx rename to apps/scandic-web/components/TempDesignSystem/Form/PasswordInput/index.tsx index 95708cdef..ca8288268 100644 --- a/apps/scandic-web/components/TempDesignSystem/Form/NewPassword/index.tsx +++ b/apps/scandic-web/components/TempDesignSystem/Form/PasswordInput/index.tsx @@ -12,25 +12,27 @@ import { EyeShowIcon, InfoCircleIcon, } from "@/components/Icons" +import Button from "@/components/TempDesignSystem/Button" import AriaInputWithLabel from "@/components/TempDesignSystem/Form/Input/AriaInputWithLabel" import Caption from "@/components/TempDesignSystem/Text/Caption" import { passwordValidators } from "@/utils/zod/passwordValidator" -import Button from "../../Button" -import { type IconProps, type NewPasswordProps } from "./newPassword" - -import styles from "./newPassword.module.css" +import styles from "./passwordInput.module.css" import type { PasswordValidatorKey } from "@/types/components/form/newPassword" +import type { IconProps, PasswordInputProps } from "./passwordInput" -export default function NewPassword({ - name = "newPassword", +export default function PasswordInput({ + name = "password", + label, "aria-label": ariaLabel, disabled = false, placeholder = "", registerOptions = {}, visibilityToggleable = true, -}: NewPasswordProps) { + isNewPassword = false, + className = "", +}: PasswordInputProps) { const { control } = useFormContext() const intl = useIntl() const [isPasswordVisible, setIsPasswordVisible] = useState(false) @@ -42,10 +44,13 @@ export default function NewPassword({ name={name} rules={registerOptions} render={({ field, fieldState, formState }) => { - const errors = Object.values(formState.errors[name]?.types ?? []).flat() + const errors = isNewPassword + ? Object.values(formState.errors[name]?.types ?? []).flat() + : [] return ( {visibilityToggleable ? ( ) : null} - + {isNewPassword && ( + + )} - {!field.value && fieldState.error ? ( + {isNewPassword ? ( + !field.value && fieldState.error ? ( + + + {fieldState.error.message} + + ) : null + ) : fieldState.error ? ( - {fieldState.error.message} + {fieldState.error && + intl.formatMessage({ id: fieldState.error.message })} ) : null} @@ -109,7 +133,7 @@ function Icon({ errorMessage, errors }: IconProps) { ) } -function PasswordValidation({ +function NewPasswordValidation({ value, errors, }: { diff --git a/apps/scandic-web/components/TempDesignSystem/Form/NewPassword/newPassword.module.css b/apps/scandic-web/components/TempDesignSystem/Form/PasswordInput/passwordInput.module.css similarity index 99% rename from apps/scandic-web/components/TempDesignSystem/Form/NewPassword/newPassword.module.css rename to apps/scandic-web/components/TempDesignSystem/Form/PasswordInput/passwordInput.module.css index 51097075a..5ebc1e7e2 100644 --- a/apps/scandic-web/components/TempDesignSystem/Form/NewPassword/newPassword.module.css +++ b/apps/scandic-web/components/TempDesignSystem/Form/PasswordInput/passwordInput.module.css @@ -76,17 +76,17 @@ padding-top: var(--Spacing-x1); } -.eyeIcon { +.inputWrapper { + position: relative; +} + +.toggleButton { position: absolute; right: var(--Spacing-x2); top: 50%; transform: translateY(-50%); } -.inputWrapper { - position: relative; -} - /* Hide the built-in password reveal icon in Microsoft Edge. * See: https://learn.microsoft.com/en-us/microsoft-edge/web-platform/password-reveal */ diff --git a/apps/scandic-web/components/TempDesignSystem/Form/NewPassword/newPassword.ts b/apps/scandic-web/components/TempDesignSystem/Form/PasswordInput/passwordInput.ts similarity index 81% rename from apps/scandic-web/components/TempDesignSystem/Form/NewPassword/newPassword.ts rename to apps/scandic-web/components/TempDesignSystem/Form/PasswordInput/passwordInput.ts index 8486a44ad..21c08a51e 100644 --- a/apps/scandic-web/components/TempDesignSystem/Form/NewPassword/newPassword.ts +++ b/apps/scandic-web/components/TempDesignSystem/Form/PasswordInput/passwordInput.ts @@ -1,10 +1,11 @@ import type { RegisterOptions } from "react-hook-form" -export interface NewPasswordProps +export interface PasswordInputProps extends React.InputHTMLAttributes { label?: string registerOptions?: RegisterOptions visibilityToggleable?: boolean + isNewPassword?: boolean } export interface IconProps {