Skip to content
New issue

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

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

Already on GitHub? # to your account

[feature]: refactor edit steps out of redux and into local checkout state #1338

Merged
merged 11 commits into from
Jul 29, 2019

Conversation

sirugh
Copy link
Contributor

@sirugh sirugh commented Jun 13, 2019

Description

This is a followup to #1309. The original refactor left much of the original redux piping in place. This PR shows how we can remove parts of it relatively painlessly. Here we are migrating the state of what form is being edited, ie payment, address or shipping, into local form state.

I also removed some unnecessary props and added some safety checks/state to make sure we only enable the submission of billing information when appropriate.

Related Issue

Closes #1405

Verification Steps

  1. Open checkout and work through the steps.
  2. You should be able to open and close each step in no particular order, and no errors should occur.

Screenshots / Screen Captures (if appropriate)

Proposed Labels for Change Type/Package

  • major (e.g x.0.0 - a breaking change)
  • minor (e.g 0.x.0 - a backwards compatible addition)
  • patch (e.g 0.0.x - a bug fix)

Checklist:

  • I have updated the documentation accordingly, if necessary.
  • I have added tests to cover my changes, if necessary.

@sirugh sirugh added hold On hold until another condition is fulfilled. in progress labels Jun 13, 2019
@sirugh sirugh self-assigned this Jun 13, 2019
@vercel
Copy link

vercel bot commented Jun 13, 2019

This pull request is automatically deployed with Now.
To access deployments, click Details below or on the icon next to each push.

Latest deployment for this branch: https://venia-git-reduxrefactor-checkout.magento-research1.now.sh

@sirugh sirugh force-pushed the redux_refactor/checkout branch from a878590 to 623a0da Compare June 28, 2019 14:40
@sirugh sirugh changed the title WIP: Redux refactor/checkout [feature Jun 28, 2019
@sirugh sirugh changed the title [feature [feature]: refactor edit steps out of redux and into local checkout state Jun 28, 2019
@sirugh sirugh removed hold On hold until another condition is fulfilled. in progress labels Jun 28, 2019
@magento magento deleted a comment from PWAStudioBot Jun 28, 2019
@PWAStudioBot
Copy link
Contributor

PWAStudioBot commented Jun 28, 2019

Messages
📖 We are currently working on automating the PR metadata checks. Until that time, you may see failures related to labels/description/linked issues/etc even if you have fixed the problem. Failures will persist until the next push (assuming they are fixed).

Generated by 🚫 dangerJS against a5f5354

@sirugh sirugh added the version: Patch This changeset includes backwards compatible bug fixes. label Jun 28, 2019
@sirugh sirugh assigned sirugh and unassigned sirugh Jun 28, 2019

const handleSubmitAddressForm = useCallback(
formValues => {
submitShippingAddress({
async formValues => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We had to make some of the callbacks async so that they could appropriately handle an error response.

@sirugh sirugh requested a review from jimbo July 10, 2019 13:22
@sirugh sirugh removed their assignment Jul 15, 2019

useEffect(() => {
async function requestPaymentNonce() {
try {
const paymentNonce = await dropinInstance.requestPaymentMethod();
onSuccess(paymentNonce);
} catch (e) {
// If payment details were missing or invalid but we have data
// from a previous successful submission, use the previous data.
const storedPayment = storage.getItem('paymentMethod');
Copy link
Contributor Author

@sirugh sirugh Jul 23, 2019

Choose a reason for hiding this comment

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

This was a weird UX. If storage has a valid payment and I enter a new card but something is invalid (pin/expiry/etc), it'll just close the form and use the storage payment info and I would assume the new info was accepted. I don't think we should do that automatically, so I removed this code. In the future we could display some UX that shows a "edit" button next to saved CC info that would re-mount the braintree dropin but for now we just have to deal with re-entering CC info.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed it was a weird UX. If I remember correctly we were trying to avoid having to re-enter CC info if the only thing that was changing was the billing address.

I think you're right that even though re-entering CC info is cumbersome it is better than leaving the user uncertain or unknowledgeable about what CC info is really being used. I'd rather them have to be explicit.

Copy link
Contributor

@jimbo jimbo left a comment

Choose a reason for hiding this comment

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

This looks good to me. I have small concerns about the async callbacks interacting with reducers, but we'll resolve them when we actually pull state out of Redux.

@vercel vercel bot temporarily deployed to staging July 26, 2019 18:31 Inactive
jimbo
jimbo previously approved these changes Jul 26, 2019
@sirugh
Copy link
Contributor Author

sirugh commented Jul 26, 2019

Uh idk why the tests are failing...

Copy link
Contributor

@zetlen zetlen left a comment

Choose a reason for hiding this comment

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

LGTM, this does simplify things. It may be a candidate for later abstraction and public API, and this makes that more achievable. Thank you!

@dpatil-magento dpatil-magento merged commit 73049f0 into develop Jul 29, 2019
@dpatil-magento dpatil-magento deleted the redux_refactor/checkout branch July 29, 2019 21:55
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
pkg:venia-concept version: Patch This changeset includes backwards compatible bug fixes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feature]: Refactor local state for checkout out of redux
6 participants