Skip to content

Commit

Permalink
- fix error messages on password change
Browse files Browse the repository at this point in the history
- clear password change fields when password change was successful
  • Loading branch information
knoxfighter committed Jul 13, 2024
1 parent a6dc541 commit 299b33e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions ui/App/views/UserManagement/components/ChangePasswordForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ import Input from "../../../components/Input";
import Error from "../../../components/Error";

const ChangePasswordForm = () => {
const {register, handleSubmit, formState: {errors}, watch} = useForm();
const {register, handleSubmit, reset, formState: {errors}, watch} = useForm();

const new_password = watch("new_password");

const onSubmit = async (data) => {
const res = await user.changePassword(data);
if (res) {
// Update successful
window.flash("Password changed", "green")
reset();
}
}

Expand All @@ -37,7 +40,7 @@ const ChangePasswordForm = () => {
</div>
<div className="mb-4">
<Label htmlFor="new_password_confirmation" text="New Password Confirmation"/>
<Input register={register('new_password_confirmation',{required: true})}
<Input register={register('new_password_confirmation',{required: true, validate: value => value === new_password})}
type="password"
placeholder="New Password"
/>
Expand Down
2 changes: 1 addition & 1 deletion ui/api/resources/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default {
return response.data;
},
changePassword: async data => {
const response = await client.post('/api/user/password', data);
const response = await client.post('/api/user/password', data).catch(err => window.flash(err.response.data, "red"));
return response.data;
}
}

0 comments on commit 299b33e

Please sign in to comment.