Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit76bfa9b

Browse files
fix(site): fix validation server error on change password form (#15170)
Before:![image](https://github.com/user-attachments/assets/4fd83c78-4d30-4a92-af2c-7c986a03b426)After:<img width="528" alt="Screenshot 2024-10-21 at 13 07 34"src="https://github.com/user-attachments/assets/797ddeaa-8fb4-4d22-9a1b-93809b92432b">Fix#15152
1 parent212aeff commit76bfa9b

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

‎site/src/pages/ResetPasswordPage/ChangePasswordPage.stories.tsx‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export const WrongConfirmationPassword: Story = {
5151
},
5252
};
5353

54-
exportconstServerError:Story={
54+
exportconstGeneralServerError:Story={
5555
play:async({ canvasElement})=>{
5656
constserverError=
5757
"New password should be different from the old password";
@@ -71,3 +71,29 @@ export const ServerError: Story = {
7171
awaitcanvas.findByText(serverError);
7272
},
7373
};
74+
75+
exportconstValidationServerError:Story={
76+
play:async({ canvasElement})=>{
77+
constvalidationDetail=
78+
"insecure password, try including more special characters, using uppercase letters, using numbers or using a longer password";
79+
consterror=mockApiError({
80+
message:"Invalid password.",
81+
validations:[
82+
{
83+
field:"password",
84+
detail:validationDetail,
85+
},
86+
],
87+
});
88+
spyOn(API,"changePasswordWithOTP").mockRejectedValueOnce(error);
89+
constcanvas=within(canvasElement);
90+
constuser=userEvent.setup();
91+
constnewPasswordInput=awaitcanvas.findByLabelText("Password *");
92+
awaituser.type(newPasswordInput,"password");
93+
constconfirmPasswordInput=
94+
awaitcanvas.findByLabelText("Confirm password *");
95+
awaituser.type(confirmPasswordInput,"password");
96+
awaituser.click(canvas.getByRole("button",{name:/resetpassword/i}));
97+
awaitcanvas.findByText(validationDetail);
98+
},
99+
};

‎site/src/pages/ResetPasswordPage/ChangePasswordPage.tsx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { Interpolation, Theme } from "@emotion/react";
22
importLoadingButtonfrom"@mui/lab/LoadingButton";
33
importButtonfrom"@mui/material/Button";
44
importTextFieldfrom"@mui/material/TextField";
5+
import{isApiError,isApiValidationError}from"api/errors";
56
import{changePasswordWithOTP}from"api/queries/users";
67
import{ErrorAlert}from"components/Alert/ErrorAlert";
78
import{CustomLogo}from"components/CustomLogo/CustomLogo";
@@ -64,7 +65,7 @@ const ChangePasswordPage: FC<ChangePasswordChangeProps> = ({ redirect }) => {
6465
}
6566
},
6667
});
67-
constgetFieldHelpers=getFormHelpers(form);
68+
constgetFieldHelpers=getFormHelpers(form,changePasswordMutation.error);
6869

6970
return(
7071
<>
@@ -86,7 +87,8 @@ const ChangePasswordPage: FC<ChangePasswordChangeProps> = ({ redirect }) => {
8687
>
8788
Choose a new password
8889
</h1>
89-
{changePasswordMutation.error ?(
90+
{changePasswordMutation.error&&
91+
!isApiValidationError(changePasswordMutation.error) ?(
9092
<ErrorAlert
9193
error={changePasswordMutation.error}
9294
css={{marginBottom:24}}

‎site/src/theme/mui.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,11 @@ export const components = {
375375
sx:{
376376
marginLeft:0,
377377
marginTop:1,
378+
"&::first-letter":{
379+
// Server errors are returned in all lowercase. To display them as
380+
// field errors in the UI, we capitalize the first letter.
381+
textTransform:"uppercase",
382+
},
378383
},
379384
},
380385
},

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp