0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

refactor(ui): refine password input

This commit is contained in:
Gao Sun 2023-09-07 22:42:52 +08:00
parent f71763da25
commit b68a581789
No known key found for this signature in database
GPG key ID: 13EBE123E4773688
6 changed files with 25 additions and 21 deletions

View file

@ -12,7 +12,7 @@ import * as styles from './index.module.scss';
type Props = { type Props = {
title: TFuncKey; title: TFuncKey;
description?: TFuncKey | ReactElement; description?: TFuncKey | ReactElement | '';
titleProps?: Record<string, unknown>; titleProps?: Record<string, unknown>;
descriptionProps?: Record<string, unknown>; descriptionProps?: Record<string, unknown>;
notification?: TFuncKey; notification?: TFuncKey;

View file

@ -10,6 +10,7 @@ type Props = {
onSubmit: (password: string) => void; onSubmit: (password: string) => void;
errorMessage?: string; errorMessage?: string;
clearErrorMessage?: () => void; clearErrorMessage?: () => void;
maxLength?: number;
}; };
const SetPassword = (props: Props) => { const SetPassword = (props: Props) => {

View file

@ -42,20 +42,20 @@ export const usePasswordPolicy = () => {
const requirementsDescription = useMemo( const requirementsDescription = useMemo(
() => () =>
t('description.password_requirements', { policy.length.min <= 1 && policy.characterTypes.min <= 1
items: condArray( ? undefined
// There's no need to show the length requirement if it can be satisfied by the character types : t('description.password_requirements', {
policy.length.min > policy.characterTypes.min && items: condArray(
t('description.password_requirement.length', { count: policy.length.min }), // There's no need to show the length requirement if it can be satisfied by the character types
// Show the character types requirement if: policy.length.min > policy.characterTypes.min &&
// - It's greater than 1, or; t('description.password_requirement.length', { count: policy.length.min }),
// - The length requirement is equal to or less than 1 (since the length requirement will be hidden in this case) // Show the character types requirement if it's greater than 1.
(policy.characterTypes.min > 1 || policy.length.min <= 1) && policy.characterTypes.min > 1 &&
t('description.password_requirement.character_types', { t('description.password_requirement.character_types', {
count: policy.characterTypes.min, count: policy.characterTypes.min,
}) })
), ),
}), }),
[t, policy.length.min, policy.characterTypes.min] [t, policy.length.min, policy.characterTypes.min]
); );

View file

@ -44,7 +44,7 @@ const SetPassword = () => {
const { const {
policy: { policy: {
length: { min }, length: { min, max },
characterTypes: { min: count }, characterTypes: { min: count },
}, },
requirementsDescription, requirementsDescription,
@ -53,12 +53,13 @@ const SetPassword = () => {
return ( return (
<SecondaryPageLayout <SecondaryPageLayout
title="description.set_password" title="description.set_password"
description={<span>{requirementsDescription}</span>} description={requirementsDescription && <span>{requirementsDescription}</span>}
descriptionProps={{ min, count }} descriptionProps={{ min, count }}
> >
<SetPasswordForm <SetPasswordForm
autoFocus autoFocus
errorMessage={errorMessage} errorMessage={errorMessage}
maxLength={max}
clearErrorMessage={clearErrorMessage} clearErrorMessage={clearErrorMessage}
onSubmit={action} onSubmit={action}
/> />

View file

@ -46,7 +46,7 @@ const RegisterPassword = () => {
const { const {
policy: { policy: {
length: { min }, length: { min, max },
characterTypes: { min: count }, characterTypes: { min: count },
}, },
requirementsDescription, requirementsDescription,
@ -59,12 +59,13 @@ const RegisterPassword = () => {
return ( return (
<SecondaryPageLayout <SecondaryPageLayout
title="description.new_password" title="description.new_password"
description={<span>{requirementsDescription}</span>} description={requirementsDescription && <span>{requirementsDescription}</span>}
descriptionProps={{ min, count }} descriptionProps={{ min, count }}
> >
<SetPassword <SetPassword
autoFocus autoFocus
errorMessage={errorMessage} errorMessage={errorMessage}
maxLength={max}
clearErrorMessage={clearErrorMessage} clearErrorMessage={clearErrorMessage}
onSubmit={action} onSubmit={action}
/> />

View file

@ -50,7 +50,7 @@ const ResetPassword = () => {
}); });
const { const {
policy: { policy: {
length: { min }, length: { min, max },
characterTypes: { min: count }, characterTypes: { min: count },
}, },
requirementsDescription, requirementsDescription,
@ -59,12 +59,13 @@ const ResetPassword = () => {
return ( return (
<SecondaryPageLayout <SecondaryPageLayout
title="description.new_password" title="description.new_password"
description={<span>{requirementsDescription}</span>} description={requirementsDescription && <span>{requirementsDescription}</span>}
descriptionProps={{ min, count }} descriptionProps={{ min, count }}
> >
<SetPassword <SetPassword
autoFocus autoFocus
errorMessage={errorMessage} errorMessage={errorMessage}
maxLength={max}
clearErrorMessage={clearErrorMessage} clearErrorMessage={clearErrorMessage}
onSubmit={action} onSubmit={action}
/> />