fix: address PR review feedback on password suggestions
Remove redundant tests, rename requirement translations to suggestion for clearer i18n, simplify password input state and requirement display.
This commit is contained in:
41 files changed
+50
-94
No files matched your search
@@ -20,16 +20,15 @@ export const CustomPasswordInput = ({ withPasswordRequirements, ...props }: Cust
|
||||
};
|
||||
|
||||
const WithPasswordRequirements = (props: PasswordInputProps) => {
|
||||
const [internalValue, setInternalValue] = useState("");
|
||||
const password = props.value ?? internalValue;
|
||||
const [password, setPassword] = useState("");
|
||||
|
||||
const onChange = (event: ChangeEvent<HTMLInputElement>) => {
|
||||
setInternalValue(event.currentTarget.value);
|
||||
setPassword(event.currentTarget.value);
|
||||
props.onChange?.(event);
|
||||
};
|
||||
|
||||
return (
|
||||
<PasswordRequirementsPopover password={String(password)}>
|
||||
<PasswordRequirementsPopover password={password}>
|
||||
<PasswordInput {...props} onChange={onChange} />
|
||||
</PasswordRequirementsPopover>
|
||||
);
|
||||
|
||||
@@ -1,18 +1,14 @@
|
||||
import { rem, Text } from "@mantine/core";
|
||||
import { IconCheck, IconPoint } from "@tabler/icons-react";
|
||||
|
||||
const requirementDisplay = {
|
||||
met: { color: "teal", Icon: IconCheck },
|
||||
unmet: { color: "dimmed", Icon: IconPoint },
|
||||
} as const;
|
||||
|
||||
const displayKey = {
|
||||
true: "met",
|
||||
false: "unmet",
|
||||
} as const;
|
||||
const getRequirementDisplay = (meets: boolean) =>
|
||||
({
|
||||
true: { color: "teal", Icon: IconCheck },
|
||||
false: { color: "dimmed", Icon: IconPoint },
|
||||
})[String(meets) as "true" | "false"];
|
||||
|
||||
export function PasswordRequirement({ meets, label }: { meets: boolean; label: string }) {
|
||||
const display = requirementDisplay[displayKey[String(meets) as "true" | "false"]];
|
||||
const display = getRequirementDisplay(meets);
|
||||
const Icon = display.Icon;
|
||||
|
||||
return (
|
||||
|
||||
@@ -46,7 +46,7 @@ export const PasswordRequirementsPopover = ({ password, children }: PropsWithChi
|
||||
};
|
||||
|
||||
const useRequirements = () => {
|
||||
const t = useScopedI18n("user.field.password.requirement");
|
||||
const t = useScopedI18n("user.field.password.suggestion");
|
||||
|
||||
return passwordRequirements.map(({ check, value }) => ({ check, label: t(value) }));
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user