Skip to content

Commit

Permalink
fixed profile form updated password
Browse files Browse the repository at this point in the history
  • Loading branch information
davidsingal committed Sep 21, 2023
1 parent 5cf32d4 commit 78edadf
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 9 deletions.
8 changes: 7 additions & 1 deletion client/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/).

## [v0.6.0 Unreleased]
## [Unreleased]

### Fixed

- Update password in profile form was not working as expected [LANDGRIF-1479](https://vizzuality.atlassian.net/browse/LANDGRIF-1479)

## [v1.0.0]

### Added

Expand Down
22 changes: 22 additions & 0 deletions client/cypress/e2e/profile.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
describe('Profile', () => {
beforeEach(() => {
cy.login();
});

afterEach(() => {
cy.logout();
});

it('change password', () => {
cy.intercept('PATCH', '/api/v1/users/me/password', {
statusCode: 200,
body: {},
}).as('updatePasswordRequest');
cy.visit('/profile');

cy.get('[name="currentPassword"]').type(Cypress.env('PASSWORD'));
cy.get('[name="newPassword"]').type(Cypress.env('PASSWORD'));
cy.get('[name="passwordConfirmation"]').type(Cypress.env('PASSWORD'));
cy.get('button[data-testid="submit-update-password"]').click();
});
});
28 changes: 20 additions & 8 deletions client/src/containers/update-password-form/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,22 @@ const UserPasswordForm: React.FC = () => {

const handleEditPassword = useCallback(
(data: PasswordPayload) => {
updatePassword.mutate(data, {
onSuccess: () => {
toast.success('Your changes were successfully saved.');
updatePassword.mutate(
{
// avoid passing passwordConfirmation to the API
currentPassword: data.currentPassword,
newPassword: data.newPassword,
},
onError: (error: ErrorResponse) => {
const { errors } = error.response?.data;
errors.forEach(({ title }) => toast.error(title));
{
onSuccess: () => {
toast.success('Your changes were successfully saved.');
},
onError: (error: ErrorResponse) => {
const { errors } = error.response?.data;
errors.forEach(({ title }) => toast.error(title));
},
},
});
);
},
[updatePassword],
);
Expand Down Expand Up @@ -83,7 +90,12 @@ const UserPasswordForm: React.FC = () => {
</div>
</div>
<div className="flex justify-end h-16 py-3 pr-6 rounded-md bg-gray-50">
<Button type="submit" variant="primary" loading={updatePassword.isLoading}>
<Button
type="submit"
variant="primary"
loading={updatePassword.isLoading}
data-testid="submit-update-password"
>
Save
</Button>
</div>
Expand Down

0 comments on commit 78edadf

Please sign in to comment.