Skip to content
This repository has been archived by the owner on Sep 10, 2024. It is now read-only.

Commit

Permalink
Don't show inline errors twice
Browse files Browse the repository at this point in the history
  • Loading branch information
reivilibre committed Jun 25, 2024
1 parent e5a21a6 commit 2c8ed61
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions frontend/src/routes/password.change.index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,10 @@ function ChangePassword(): React.ReactNode {
}
};

const handleableError =
result.data && result.data.setPassword.status !== SetPasswordStatus.Allowed;
const unhandleableError = result.error !== undefined;

const errorMsg: string | undefined = ((): string | undefined => {
switch (result.data?.setPassword.status) {
case SetPasswordStatus.InvalidNewPassword:
return t(
"frontend.password_change.failure.description.invalid_new_password",
);
case SetPasswordStatus.NoCurrentPassword:
return t(
"frontend.password_change.failure.description.no_current_password",
Expand All @@ -123,11 +117,16 @@ function ChangePassword(): React.ReactNode {
return t(
"frontend.password_change.failure.description.password_changes_disabled",
);

case SetPasswordStatus.WrongPassword:
return t("frontend.password_change.failure.description.wrong_password");
case SetPasswordStatus.InvalidNewPassword:
// These cases are shown as inline errors in the form itself.
return undefined;

case SetPasswordStatus.Allowed:
case undefined:
return undefined;

default:
throw new Error(
`unexpected error when changing password: ${result.data!.setPassword.status}`,
Expand Down Expand Up @@ -159,7 +158,7 @@ function ChangePassword(): React.ReactNode {
</Alert>
)}

{handleableError && (
{errorMsg !== undefined && (
<Alert
type="critical"
title={t("frontend.password_change.failure.title")}
Expand Down

0 comments on commit 2c8ed61

Please sign in to comment.