Skip to content

Commit

Permalink
Add more types
Browse files Browse the repository at this point in the history
  • Loading branch information
eunjuhuss committed May 28, 2024
1 parent e6d6afb commit 85149af
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/components/Dashboard/ChangePasswordCustom.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import EduIDButton from "components/Common/EduIDButton";
import NewPasswordInput from "components/Common/NewPasswordInput";
import PasswordStrengthMeter, { PasswordStrengthData } from "components/Common/PasswordStrengthMeter";
import PasswordStrengthMeter from "components/Common/PasswordStrengthMeter";
import { emptyStringPattern } from "helperFunctions/validation/regexPatterns";
import { Field as FinalField, Form as FinalForm } from "react-final-form";
import { FormattedMessage, useIntl } from "react-intl";
Expand All @@ -24,21 +24,21 @@ export default function ChangePasswordCustomForm(props: ChangePasswordCustomForm
description: "placeholder text for repeat new password",
});

function updatePasswordData(value: PasswordStrengthData) {
function updatePasswordData() {
// This function is called when the password strength meter has calculated password strength
// on the current value in the form. We need to trigger validation of the field again at this
// point, since validation uses this calculated value (and will already have executed when we
// get here).
props.formProps.form.change("custom", props.formProps.values.custom);
}

function validateNewPassword(values: any) {
const errors: any = {};
function validateNewPassword(values: { custom?: string; repeat?: string }) {
const errors: { custom?: string; repeat?: string } = {};
if (values !== undefined) {
["custom", "repeat"].forEach((inputName) => {
if (!values[inputName] || emptyStringPattern.test(values[inputName])) {
(["custom", "repeat"] as Array<keyof typeof values>).forEach((inputName) => {
if (!values[inputName] || emptyStringPattern.test(values[inputName] as string)) {
errors[inputName] = "required";
} else if (values["custom"].replace(/\s/g, "") !== values["repeat"].replace(/\s/g, "")) {
} else if (values["custom"]?.replace(/\s/g, "") !== values["repeat"]?.replace(/\s/g, "")) {
// Remove whitespace from both passwords before comparing
errors["repeat"] = "chpass.different-repeat";
}
Expand Down

0 comments on commit 85149af

Please sign in to comment.