Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): add customer change password for logged-in customer #704

Merged
merged 1 commit into from
May 8, 2024

Conversation

bc-alexsaiannyi
Copy link
Contributor

@bc-alexsaiannyi bc-alexsaiannyi commented Mar 25, 2024

What/Why?

This PR adds functionality for changed password if Customer is logged in.

Account settings form is a placehodler. Will be updated in separate PR.

Testing

locally

@bc-alexsaiannyi bc-alexsaiannyi requested a review from a team as a code owner March 25, 2024 14:24
Copy link

changeset-bot bot commented Mar 25, 2024

🦋 Changeset detected

Latest commit: 3c9ee32

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@bigcommerce/catalyst-core Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Mar 25, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
catalyst-core ❌ Failed (Inspect) May 8, 2024 1:42pm
catalyst-latest ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 8, 2024 1:42pm
catalyst-storybook ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 8, 2024 1:42pm
catalyst-testbed ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 8, 2024 1:42pm
4 Ignored Deployments
Name Status Preview Comments Updated (UTC)
catalyst-1millionproducts-store ⬜️ Ignored (Inspect) Visit Preview May 8, 2024 1:42pm
catalyst-au ⬜️ Ignored (Inspect) Visit Preview May 8, 2024 1:42pm
catalyst-test-store ⬜️ Ignored (Inspect) Visit Preview May 8, 2024 1:42pm
catalyst-uk ⬜️ Ignored (Inspect) Visit Preview May 8, 2024 1:42pm

Copy link
Contributor

@matthewvolk matthewvolk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing locally seems to work! However, rather than including the account settings placeholder in this PR, can we just add the code required for changing passwords to work?

The reason behind this request is because if we cut another Catalyst release with the placeholder work included, people will be creating Catalyst storefronts locally with placeholder forms and that could lead to confusion, I'd imagine.

@bc-alexsaiannyi
Copy link
Contributor Author

...

The reason behind this request is because if we cut another Catalyst release with the placeholder work included, people will be creating Catalyst storefronts locally with placeholder forms and that could lead to confusion, I'd imagine.

Hey, Matt. Yeah, it's a fair point so I've removed account-settings-form together with app router related to account's tabs ( account settings form is also one of these tabs). Now PR should be little bit cleaner in terms of functionality.

Comment on lines 89 to 91
if (e.target.form) {
formData = new FormData(e.target.form);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we have a case when we have no form and formData is null?

Copy link
Contributor Author

@bc-alexsaiannyi bc-alexsaiannyi Mar 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's a good question. e.target.form possibly can be null but your question brought me up to a small refactoring -I've simplified code and removed checking for FormData is null on a second step. Now it's done like:

if (e.target.form) {
   currentPasswordValue = new FormData(e.target.form).get('current-password');
}

Thanks!

Copy link
Contributor

@yurytut1993 yurytut1993 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


if (!session) {
redirect('/login');
}

if (action === 'reset_password') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts on having this as a different page? Should help simplify change-password-form.ts

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean to create separate page alongside change-password-form that will be used exclusively for logged-in Customers?🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To chime in on this, there is usually two flows for how to change your password:

  1. Update your password when logged in – has a session tied to it.
  2. Forgot your password as a guest – the email sent to the user will contain a redirect link with code to generate a "session" in order to validate changing the password.

Since those are two separate use-cases, I think sharing a form shouldn't be an option here, especially from a security perspective.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, guys. it's updated

Comment on lines 101 to 82
let newPasswordValue: FormDataEntryValue | null = null;
const confirmPasswordValue = e.target.value;

return setIsConfirmPasswordValid(confirmPassword === newPassword);
if (e.target.form) {
newPasswordValue = new FormData(e.target.form).get('new-password');
}

setIsConfirmPasswordValid(
confirmPasswordValue.length > 0 && newPasswordValue === confirmPasswordValue,
);
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use the schema CustomerChangePasswordSchema here? We can modify it to check for equality and length requirements.

Copy link
Contributor Author

@bc-alexsaiannyi bc-alexsaiannyi Apr 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've refactored this part but not sure if it's for good. it looks bulkier now. What do you say?

};
}

return { status: 'error', message: 'Unknown error' };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return { status: 'error', message: 'Unknown error' };
return { status: 'error', message: 'Unknown error.' };

});

if (response.errors.length === 0) {
return { status: 'success', message: '' };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we return response here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a message here but we basically don't use any data.

Copy link
Contributor

github-actions bot commented May 8, 2024

⚡️🏠 Lighthouse report

Lighthouse ran against https://catalyst-latest-gzpcucyzw-bigcommerce-platform.vercel.app

🖥️ Desktop

We ran Lighthouse against the changes on a desktop and produced this report. Here's the summary:

Category Score
🟢 Performance 100
🟢 Accessibility 100
🟢 Best practices 100
🟢 SEO 90

📱 Mobile

We ran Lighthouse against the changes on a mobile and produced this report. Here's the summary:

Category Score
🟠 Performance 89
🟢 Accessibility 100
🟢 Best practices 100
🟢 SEO 92

@bc-alexsaiannyi bc-alexsaiannyi added this pull request to the merge queue May 8, 2024
Merged via the queue into main with commit 6e93873 May 8, 2024
11 checks passed
@bc-alexsaiannyi bc-alexsaiannyi deleted the customer-change-password branch May 8, 2024 13:46
This was referenced May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants