added error on password confirm on password change (#20236)

* added error on password confirm on password change

fixes: #16577

* Update js/apps/admin-ui/src/user/user-credentials/ResetPasswordDialog.tsx

Co-authored-by: Jon Koops <jonkoops@gmail.com>

* linting

---------

Co-authored-by: Jon Koops <jonkoops@gmail.com>
This commit is contained in:
Erik Jan de Wit 2023-05-26 11:57:57 +02:00 committed by GitHub
parent b6f2f958c0
commit 9dabbe951e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -52,6 +52,8 @@ export const ResetPasswordDialog = ({
formState: { isValid, errors }, formState: { isValid, errors },
watch, watch,
handleSubmit, handleSubmit,
clearErrors,
setError,
} = useForm<CredentialsForm>({ } = useForm<CredentialsForm>({
defaultValues: credFormDefaultValues, defaultValues: credFormDefaultValues,
mode: "onChange", mode: "onChange",
@ -59,6 +61,7 @@ export const ResetPasswordDialog = ({
const [confirm, toggle] = useToggle(true); const [confirm, toggle] = useToggle(true);
const password = watch("password", ""); const password = watch("password", "");
const passwordConfirmation = watch("passwordConfirmation", "");
const { addAlert, addError } = useAlerts(); const { addAlert, addError } = useAlerts();
@ -121,6 +124,7 @@ export const ResetPasswordDialog = ({
onClose(); onClose();
}; };
const { onChange, ...rest } = register("password", { required: true });
return ( return (
<> <>
<ConfirmSaveModal /> <ConfirmSaveModal />
@ -157,7 +161,17 @@ export const ResetPasswordDialog = ({
<PasswordInput <PasswordInput
data-testid="passwordField" data-testid="passwordField"
id="password" id="password"
{...register("password", { required: true })} onChange={(e) => {
onChange(e);
if (passwordConfirmation !== e.currentTarget.value) {
setError("passwordConfirmation", {
message: t("confirmPasswordDoesNotMatch").toString(),
});
} else {
clearErrors("passwordConfirmation");
}
}}
{...rest}
/> />
</FormGroup> </FormGroup>
<FormGroup <FormGroup