Skip to content

Commit 299b33e

Browse files
committed
- fix error messages on password change
- clear password change fields when password change was successful
1 parent a6dc541 commit 299b33e

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

ui/App/views/UserManagement/components/ChangePasswordForm.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@ import Input from "../../../components/Input";
77
import Error from "../../../components/Error";
88

99
const ChangePasswordForm = () => {
10-
const {register, handleSubmit, formState: {errors}, watch} = useForm();
10+
const {register, handleSubmit, reset, formState: {errors}, watch} = useForm();
11+
12+
const new_password = watch("new_password");
1113

1214
const onSubmit = async (data) => {
1315
const res = await user.changePassword(data);
1416
if (res) {
1517
// Update successful
1618
window.flash("Password changed", "green")
19+
reset();
1720
}
1821
}
1922

@@ -37,7 +40,7 @@ const ChangePasswordForm = () => {
3740
</div>
3841
<div className="mb-4">
3942
<Label htmlFor="new_password_confirmation" text="New Password Confirmation"/>
40-
<Input register={register('new_password_confirmation',{required: true})}
43+
<Input register={register('new_password_confirmation',{required: true, validate: value => value === new_password})}
4144
type="password"
4245
placeholder="New Password"
4346
/>

ui/api/resources/user.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default {
2626
return response.data;
2727
},
2828
changePassword: async data => {
29-
const response = await client.post('/api/user/password', data);
29+
const response = await client.post('/api/user/password', data).catch(err => window.flash(err.response.data, "red"));
3030
return response.data;
3131
}
3232
}

0 commit comments

Comments
 (0)