Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Disable "Place order" button in Checkout block if any errors are visible and add explicitDismiss option when throwing API errors #7783

Closed
wants to merge 34 commits into from

Conversation

opr
Copy link
Contributor

@opr opr commented Nov 29, 2022

This PR is based on #7711 and will prevent the "Place order" button from being pressed if any notices of type error are present in any of the notice contexts related to WC Blocks.

It also adds the option to specify an explicitDismiss property in the additional data of an API error, this will in turn pass the value onto the snackbar notice displayed.

Fixes #5972

Screenshots

Before After
image image

Testing

Automated Tests

  • Changes in this PR are covered by Automated Tests.
    • Unit tests
    • E2E tests

User Facing Testing

  1. Add an item to your cart and load the Checkout block.
  2. Open a new tab, and set the item to be out of stock.
  3. Try to check out and ensure an error appears with a cross in it. Ensure the error remains even after 10 seconds.
  4. Before dismissing the error, try to place the order again, ensure the button is disabled.
  5. Clear the error and ensure you can attempt checkout.

Note, there is currently a bug so an actual checkout won't work, so no need to report that. It has been noted here: #7711 (review)

  • Do not include in the Testing Notes

WooCommerce Visibility

  • WooCommerce Core
  • Feature plugin
  • Experimental

Changelog

Disable "Place Order" button if there are errors visible and allow cart/checkout errors from the StoreApi to require explicit dismissal in the client.

mikejolley and others added 30 commits November 21, 2022 14:06
Move snackbar hiding filter before notice creation

Implements showApplyCouponNotice

Refactor context providers

Use STORE_NOTICE_CONTEXTS

use refs to track notice containers

Refactor ref usage

Use existing noticeContexts
* Update API type defs

* Move create notice utils

* Replace useCheckoutNotices with new contexts

* processCheckoutResponseHeaders should check headers are defined

* Scroll to error notices only if we're not editing a field

* Error handling utils

* processErrorResponse when pushing changes

* processErrorResponse when processing checkout

* remove formatStoreApiErrorMessage

* Add todo for cart errors

* Remove unused deps

* unused imports

* Fix linting warnings

* Unused dep

* Update assets/js/types/type-defs/api-response.ts

Co-authored-by: Thomas Roberts <[email protected]>

* Add todo

* Use generic

* remove const

* Update array types

* Phone should be in address blocks

Co-authored-by: Thomas Roberts <[email protected]>
@opr opr added status: needs review focus: rest api Work impacting REST api routes. focus: blocks Specific work involving or impacting how blocks behave. needs: dev note PR that has some text that needs to be included in the release notes. block: cart Issues related to the cart block. block: checkout Issues related to the checkout block. labels Nov 29, 2022
@opr opr requested a review from mikejolley November 29, 2022 19:11
@opr opr self-assigned this Nov 29, 2022
@opr opr added this to the Behind Feature Flag milestone Nov 29, 2022
@rubikuserbot rubikuserbot requested a review from a team November 29, 2022 19:11
@github-actions
Copy link
Contributor

The release ZIP for this PR is accessible via:

https://wcblocks.wpcomstaging.com/wp-content/uploads/woocommerce-gutenberg-products-block-7783.zip

@@ -100,11 +100,9 @@ const updateCustomerData = debounce( (): void => {
}

if ( Object.keys( customerDataToUpdate ).length ) {
removeAllNotices();
Copy link
Contributor Author

@opr opr Nov 29, 2022

Choose a reason for hiding this comment

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

This ensures error notices are removed before trying to update the customer data. If we want to prevent pushing to the API if errors exist, we need to ensure there is a clean slate before trying.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 29, 2022

Script Dependencies Report

The compare-assets action has detected some changed script dependencies between this branch and trunk. Please review and confirm the following are correct before merging.

Script Handle Added Removed
all-reviews.js wp-html-entities 🎉
product-query.js lodash, wp-api-fetch, wp-url 🎉

This comment was automatically generated by the ./github/compare-assets action.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 29, 2022

TypeScript Errors Report

Files with errors: 434
Total errors: 2048

⚠️ ⚠️ This PR introduces new TS errors on 19 files:

assets/js/atomic/blocks/product-elements/category-list/index.ts

assets/js/base/components/cart-checkout/address-form/address-form.tsx

assets/js/base/context/hooks/use-checkout-extension-data.ts

assets/js/base/context/providers/cart-checkout/checkout-events/index.tsx

assets/js/base/utils/create-notice.ts

assets/js/data/cart/resolvers.ts

assets/js/data/cart/test/resolvers.js

assets/js/data/checkout/types.ts

assets/js/data/checkout/utils.ts

assets/js/data/index.ts

assets/js/data/payment/types.ts

assets/js/data/shared-controls.ts

assets/js/data/validation/actions.ts

assets/js/data/validation/reducers.ts

assets/js/data/validation/test/reducers.ts

assets/js/data/validation/test/selectors.ts

packages/checkout/components/store-notices-container/snackbar-notices.tsx

packages/checkout/components/store-notices-container/store-notices.tsx

packages/checkout/components/store-notices-container/test/index.tsx

@github-actions
Copy link
Contributor

github-actions bot commented Nov 29, 2022

Size Change: +167 B (0%)

Total Size: 966 kB

Filename Size Change
build/all-products.js 33.2 kB +1 B (0%)
build/cart-frontend.js 27.4 kB +1 B (0%)
build/checkout-blocks/actions-frontend.js 1.91 kB +84 B (+5%) 🔍
build/checkout-frontend.js 29.3 kB -5 B (0%)
build/checkout.js 40 kB +60 B (0%)
build/filter-wrapper-frontend.js 13.8 kB +3 B (0%)
build/mini-cart-component-frontend.js 20 kB -5 B (0%)
build/single-product-frontend.js 17.3 kB +1 B (0%)
build/single-product.js 9.92 kB +2 B (0%)
build/wc-blocks-data.js 20.1 kB +25 B (0%)
ℹ️ View Unchanged
Filename Size
build/active-filters-frontend.js 7.75 kB
build/active-filters-wrapper-frontend.js 6 kB
build/active-filters.js 7.32 kB
build/all-products-frontend.js 11.3 kB
build/all-reviews.js 7.65 kB
build/attribute-filter-frontend.js 22.6 kB
build/attribute-filter-wrapper-frontend.js 7.11 kB
build/attribute-filter.js 12.3 kB
build/blocks-checkout.js 39.4 kB
build/cart-blocks/cart-accepted-payment-methods-frontend.js 1.38 kB
build/cart-blocks/cart-cross-sells-frontend.js 254 B
build/cart-blocks/cart-cross-sells-products-frontend.js 9.53 kB
build/cart-blocks/cart-express-payment--checkout-blocks/express-payment-frontend.js 5.06 kB
build/cart-blocks/cart-express-payment-frontend.js 781 B
build/cart-blocks/cart-items-frontend.js 299 B
build/cart-blocks/cart-line-items--mini-cart-contents-block/products-table-frontend.js 5.29 kB
build/cart-blocks/cart-line-items-frontend.js 1.06 kB
build/cart-blocks/cart-order-summary-frontend.js 1.11 kB
build/cart-blocks/cart-totals-frontend.js 322 B
build/cart-blocks/empty-cart-frontend.js 345 B
build/cart-blocks/filled-cart-frontend.js 780 B
build/cart-blocks/order-summary-coupon-form-frontend.js 1.76 kB
build/cart-blocks/order-summary-discount-frontend.js 2.17 kB
build/cart-blocks/order-summary-fee-frontend.js 273 B
build/cart-blocks/order-summary-heading-frontend.js 453 B
build/cart-blocks/order-summary-shipping-frontend.js 14.6 kB
build/cart-blocks/order-summary-subtotal-frontend.js 274 B
build/cart-blocks/order-summary-taxes-frontend.js 435 B
build/cart-blocks/proceed-to-checkout-frontend.js 1.19 kB
build/cart.js 46 kB
build/checkout-blocks/billing-address--checkout-blocks/shipping-address-frontend.js 3.9 kB
build/checkout-blocks/billing-address-frontend.js 1.02 kB
build/checkout-blocks/contact-information-frontend.js 1.82 kB
build/checkout-blocks/express-payment-frontend.js 1.13 kB
build/checkout-blocks/fields-frontend.js 345 B
build/checkout-blocks/order-note-frontend.js 1.14 kB
build/checkout-blocks/order-summary-cart-items-frontend.js 3.67 kB
build/checkout-blocks/order-summary-coupon-form-frontend.js 1.92 kB
build/checkout-blocks/order-summary-discount-frontend.js 2.29 kB
build/checkout-blocks/order-summary-fee-frontend.js 275 B
build/checkout-blocks/order-summary-frontend.js 1.11 kB
build/checkout-blocks/order-summary-shipping-frontend.js 14.6 kB
build/checkout-blocks/order-summary-subtotal-frontend.js 274 B
build/checkout-blocks/order-summary-taxes-frontend.js 435 B
build/checkout-blocks/payment-frontend.js 8.32 kB
build/checkout-blocks/shipping-address-frontend.js 1.11 kB
build/checkout-blocks/shipping-methods-frontend.js 4.45 kB
build/checkout-blocks/terms-frontend.js 1.63 kB
build/checkout-blocks/totals-frontend.js 325 B
build/featured-category.js 13 kB
build/featured-product.js 13.3 kB
build/filter-wrapper.js 2.4 kB
build/general-style-rtl.css 1.29 kB
build/general-style.css 1.29 kB
build/handpicked-products.js 7.16 kB
build/legacy-template.js 2.85 kB
build/mini-cart-contents-block/empty-cart-frontend.js 366 B
build/mini-cart-contents-block/filled-cart-frontend.js 230 B
build/mini-cart-contents-block/footer-frontend.js 2.78 kB
build/mini-cart-contents-block/items-frontend.js 237 B
build/mini-cart-contents-block/products-table-frontend.js 590 B
build/mini-cart-contents-block/shopping-button-frontend.js 288 B
build/mini-cart-contents-block/title-frontend.js 368 B
build/mini-cart-contents.js 16.9 kB
build/mini-cart-frontend.js 1.76 kB
build/mini-cart.js 4.29 kB
build/price-filter-frontend.js 13.6 kB
build/price-filter-wrapper-frontend.js 7 kB
build/price-filter.js 8.37 kB
build/price-format.js 1.19 kB
build/product-add-to-cart--product-button--product-category-list--product-image--product-price--product-r--a0326d00.js 227 B
build/product-add-to-cart--product-button--product-image--product-rating--product-title.js 151 B
build/product-add-to-cart-frontend.js 6.71 kB
build/product-add-to-cart.js 8.48 kB
build/product-best-sellers.js 7.5 kB
build/product-button--product-category-list--product-image--product-price--product-rating--product-sale-b--e17c7c01.js 432 B
build/product-button--product-image--product-rating--product-sale-badge--product-title.js 301 B
build/product-button-frontend.js 2.13 kB
build/product-button.js 3.81 kB
build/product-categories.js 2.36 kB
build/product-category-list-frontend.js 1.13 kB
build/product-category-list.js 503 B
build/product-category.js 8.49 kB
build/product-image-frontend.js 2.16 kB
build/product-image.js 3.92 kB
build/product-new.js 7.5 kB
build/product-on-sale.js 7.83 kB
build/product-price-frontend.js 2.16 kB
build/product-price.js 1.53 kB
build/product-query.js 2.89 kB
build/product-rating-frontend.js 1.45 kB
build/product-rating.js 787 B
build/product-sale-badge-frontend.js 1.38 kB
build/product-sale-badge.js 820 B
build/product-search.js 2.61 kB
build/product-sku-frontend.js 627 B
build/product-sku.js 377 B
build/product-stock-indicator-frontend.js 1.26 kB
build/product-stock-indicator.js 645 B
build/product-summary-frontend.js 1.53 kB
build/product-summary.js 920 B
build/product-tag-list-frontend.js 1.13 kB
build/product-tag-list.js 497 B
build/product-tag.js 7.99 kB
build/product-title-frontend.js 1.57 kB
build/product-title.js 3.3 kB
build/product-top-rated.js 7.74 kB
build/products-by-attribute.js 8.41 kB
build/rating-filter-frontend.js 7.15 kB
build/rating-filter-wrapper-frontend.js 5.4 kB
build/rating-filter.js 5.78 kB
build/reviews-by-category.js 11.1 kB
build/reviews-by-product.js 12.2 kB
build/reviews-frontend.js 6.87 kB
build/stock-filter-frontend.js 7.79 kB
build/stock-filter-wrapper-frontend.js 6.03 kB
build/stock-filter.js 6.7 kB
build/vendors--attribute-filter-wrapper--cart-blocks/cart-cross-sells-products--cart-blocks/order-summary--d4fbf258-frontend.js 6.86 kB
build/vendors--attribute-filter-wrapper-frontend.js 8.2 kB
build/vendors--cart-blocks/cart-cross-sells-products--cart-blocks/cart-line-items--cart-blocks/cart-order--671ca56f-frontend.js 5.26 kB
build/vendors--cart-blocks/cart-cross-sells-products--cart-blocks/order-summary-shipping--checkout-blocks--18f9376a-frontend.js 19.1 kB
build/vendors--cart-blocks/cart-cross-sells-products--product-add-to-cart-frontend.js 7.54 kB
build/vendors--cart-blocks/cart-line-items--checkout-blocks/order-summary-cart-items--mini-cart-contents---233ab542-frontend.js 3.14 kB
build/vendors--cart-blocks/order-summary-shipping--checkout-blocks/billing-address--checkout-blocks/order--5b8feb0b-frontend.js 4.86 kB
build/vendors--checkout-blocks/shipping-methods-frontend.js 9.48 kB
build/wc-blocks-editor-style-rtl.css 5.24 kB
build/wc-blocks-editor-style.css 5.24 kB
build/wc-blocks-google-analytics.js 1.56 kB
build/wc-blocks-middleware.js 932 B
build/wc-blocks-registry.js 2.92 kB
build/wc-blocks-shared-context.js 1.52 kB
build/wc-blocks-shared-hocs.js 1.72 kB
build/wc-blocks-style-rtl.css 24.3 kB
build/wc-blocks-style.css 24.3 kB
build/wc-blocks-vendors-style-rtl.css 1.95 kB
build/wc-blocks-vendors-style.css 1.95 kB
build/wc-blocks-vendors.js 62.4 kB
build/wc-blocks.js 2.63 kB
build/wc-payment-method-bacs.js 816 B
build/wc-payment-method-cheque.js 811 B
build/wc-payment-method-cod.js 909 B
build/wc-payment-method-paypal.js 837 B
build/wc-settings.js 2.6 kB

compressed-size-action

@mikejolley
Copy link
Member

Please see my comment here: #5972 (comment)

And refer to the post on woocheckout p2 regarding in which I wrote about “Blocking” Events (the idea that we allow extensions to prevent checkout just before the request is submitted), and:

A way to create “Blocking” errors which can prevent access to “checkout” from the cart page, “place order” from the checkout page, and are reserved for more serious errors that should prevent the checkout flow proceeding further.

Which would show cart-state-related errors before the checkout is displayed.

I'm not convinced blocking the button is good UX for the presence of errors, namely because:

  1. There is a risk that an error exists but is not visible
  2. You force the user to go dismiss an error before placing the order again
  3. Errors (at least in core context) are not related to the state of the fields so we should allow the submission and throw the errors again if needed.

If we're talking specifically about cart state errors like in the screenshots, we could throw the error again. And we should probably offer a CTA to fix the issue without leaving checkout!

@mikejolley
Copy link
Member

I see some other conversations from last week which is probably related to this. Still catching up.

@mikejolley mikejolley force-pushed the refactor/store-notices branch from 3530786 to fc95e40 Compare December 5, 2022 11:34
@github-actions
Copy link
Contributor

This PR has been marked as stale because it has not seen any activity within the past 7 days. Our team uses this tool to help surface pull requests that have slipped through review.

If deemed still relevant, the pr can be kept active by ensuring it's up to date with the main branch and removing the stale label.

@github-actions github-actions bot added the status: stale Stale issues and PRs have had no updates for 60 days. label Dec 13, 2022
@mikejolley mikejolley force-pushed the refactor/store-notices branch from 5f4f70f to fc66f01 Compare December 14, 2022 14:40
@github-actions github-actions bot removed the status: stale Stale issues and PRs have had no updates for 60 days. label Dec 15, 2022
@opr opr force-pushed the refactor/store-notices branch from 1c4ca05 to 0f3bf98 Compare December 16, 2022 12:42
@mikejolley mikejolley force-pushed the refactor/store-notices branch 2 times, most recently from 6aacbfc to c47265f Compare December 19, 2022 12:40
Base automatically changed from refactor/store-notices to trunk December 19, 2022 15:30
@opr opr closed this Dec 23, 2022
@nielslange nielslange deleted the fix/remove-errors-before-updating-api branch April 19, 2023 23:48
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
block: cart Issues related to the cart block. block: checkout Issues related to the checkout block. focus: blocks Specific work involving or impacting how blocks behave. focus: rest api Work impacting REST api routes. needs: dev note PR that has some text that needs to be included in the release notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Interrupt the order payment flow when errors exist
2 participants