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

Cart Action Promises with success/reject handling #8272

Merged
merged 13 commits into from
Jan 30, 2023

Conversation

mikejolley
Copy link
Member

@mikejolley mikejolley commented Jan 23, 2023

This PR revises cart error handling so that consumers of the action thunks can dispatch errors (or choose not to), rather than all errors being raised via notifyErrors. This allows extensions such as gift cards to circumvent the notice system and creating their own notices.

This also ensures that all thunks return a promise. This allows consumers to wait for the action to resolve and then handle success/failure, and avoids them monitoring for changes in the data stores using useEffect.

Finally, this merges the error handling code that was split between processErrorResponse and notifyErrors.

An example of usage of this pattern was introduced in #8182 The shipping calculated form uses the promises to show the success or failure state, and also creates a notice under the shipping calculator context so it's displayed in the correct place.

Another consumer (updated in this PR) was the coupon form; previously it had to use useEffect to wait for changes in the data store, but by using promises instead it can just wait for success/fail before toggling itself off after success.

The issue with the current system in trunk was that all notices were thrown internally before extensions had a chance to deal with them, and the errors were no longer surfaced due to the removal of throw error. This was reported here: p1674473844393499-slack-C8X6Q7XQU

Testing

This requires smoke testing in a few different areas that utilise notices.

Shipping Calculator

  1. Add items to cart
  2. Open shipping calculator
  3. Enter invalid data
  4. See the notice shown in the shipping calculator
  5. Correct the address
  6. Address should update and calculator should be dismisses

Coupon Form

  1. Add items to cart
  2. On the cart page try to input an invalid coupon code
  3. See the inline validation error and no top level errors
  4. Apply a valid coupon
  5. Form should close and success notice is displayed

Cart notices

Repeat these testing steps and ensure there are no regressions:

#7938

And these:

#8162

API Errors

Edit this route and add die(1): https://github.com/woocommerce/woocommerce-blocks/blob/trunk/src/StoreApi/Routes/V1/CartSelectShippingRate.php#L74

Go to cart and select a shipping rate. Confirm you see a top level error notice in the cart.

Repeat this on the checkout page.

WooCommerce Visibility

  • WooCommerce Core
  • Feature plugin
  • Experimental

@mikejolley mikejolley self-assigned this Jan 23, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Jan 23, 2023

The release ZIP for this PR is accessible via:

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

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
reviews-frontend.js react, wc-settings, wp-a11y, wp-api-fetch, wp-compose, wp-element, wp-i18n, wp-is-shallow-equal, wp-polyfill ⚠️
active-filters-frontend.js lodash, react, wc-blocks-data-store, wc-price-format, wc-settings, wp-data, wp-element, wp-html-entities, wp-i18n, wp-is-shallow-equal, wp-polyfill, wp-primitives, wp-url ⚠️
all-products-frontend.js lodash, react, wc-blocks-checkout, wc-blocks-data-store, wc-blocks-registry, wc-blocks-shared-context, wc-blocks-shared-hocs, wc-price-format, wc-settings, wp-a11y, wp-api-fetch, wp-autop, wp-block-editor, wp-blocks, wp-compose, wp-data, wp-deprecated, wp-dom, wp-element, wp-hooks, wp-html-entities, wp-i18n, wp-is-shallow-equal, wp-polyfill, wp-primitives, wp-url, wp-warning, wp-wordcount ⚠️
attribute-filter-frontend.js lodash, react, wc-blocks-checkout, wc-blocks-data-store, wc-settings, wp-a11y, wp-block-editor, wp-blocks, wp-compose, wp-data, wp-deprecated, wp-dom, wp-element, wp-html-entities, wp-i18n, wp-is-shallow-equal, wp-keycodes, wp-polyfill, wp-primitives, wp-url, wp-warning ⚠️
cart-frontend.js lodash, react, wc-blocks-checkout, wc-blocks-data-store, wc-blocks-registry, wc-blocks-shared-context, wc-blocks-shared-hocs, wc-price-format, wc-settings, wp-a11y, wp-api-fetch, wp-autop, wp-block-editor, wp-blocks, wp-compose, wp-data, wp-deprecated, wp-dom, wp-element, wp-hooks, wp-html-entities, wp-i18n, wp-is-shallow-equal, wp-keycodes, wp-plugins, wp-polyfill, wp-primitives, wp-url, wp-warning, wp-wordcount ⚠️
checkout-frontend.js lodash, react, wc-blocks-checkout, wc-blocks-data-store, wc-blocks-registry, wc-blocks-shared-hocs, wc-price-format, wc-settings, wp-a11y, wp-api-fetch, wp-autop, wp-compose, wp-data, wp-deprecated, wp-dom, wp-element, wp-hooks, wp-html-entities, wp-i18n, wp-is-shallow-equal, wp-keycodes, wp-plugins, wp-polyfill, wp-primitives, wp-url, wp-warning, wp-wordcount ⚠️
filter-wrapper-frontend.js lodash, react, wc-blocks-checkout, wc-blocks-data-store, wc-blocks-registry, wc-price-format, wc-settings, wp-a11y, wp-block-editor, wp-blocks, wp-compose, wp-data, wp-deprecated, wp-dom, wp-element, wp-html-entities, wp-i18n, wp-is-shallow-equal, wp-keycodes, wp-polyfill, wp-primitives, wp-url, wp-warning ⚠️
mini-cart-frontend.js wc-settings, wp-polyfill ⚠️
price-filter-frontend.js lodash, react, wc-blocks-data-store, wc-price-format, wc-settings, wp-data, wp-element, wp-i18n, wp-is-shallow-equal, wp-polyfill, wp-url ⚠️
rating-filter-frontend.js lodash, react, wc-blocks-checkout, wc-blocks-data-store, wc-settings, wp-a11y, wp-block-editor, wp-blocks, wp-compose, wp-data, wp-deprecated, wp-dom, wp-element, wp-i18n, wp-is-shallow-equal, wp-keycodes, wp-polyfill, wp-primitives, wp-url, wp-warning ⚠️
single-product-frontend.js lodash, react, wc-blocks-checkout, wc-blocks-data-store, wc-blocks-registry, wc-blocks-shared-context, wc-blocks-shared-hocs, wc-price-format, wc-settings, wp-api-fetch, wp-autop, wp-block-editor, wp-blocks, wp-compose, wp-data, wp-deprecated, wp-dom, wp-element, wp-hooks, wp-html-entities, wp-i18n, wp-is-shallow-equal, wp-polyfill, wp-primitives, wp-url, wp-warning, wp-wordcount ⚠️
stock-filter-frontend.js lodash, react, wc-blocks-checkout, wc-blocks-data-store, wc-settings, wp-a11y, wp-block-editor, wp-blocks, wp-compose, wp-data, wp-deprecated, wp-dom, wp-element, wp-html-entities, wp-i18n, wp-is-shallow-equal, wp-keycodes, wp-polyfill, wp-primitives, wp-url, wp-warning ⚠️
mini-cart-component-frontend.js lodash, react, wc-blocks-checkout, wc-blocks-data-store, wc-blocks-registry, wc-price-format, wc-settings, wp-a11y, wp-autop, wp-compose, wp-data, wp-deprecated, wp-dom, wp-element, wp-hooks, wp-html-entities, wp-i18n, wp-is-shallow-equal, wp-keycodes, wp-polyfill, wp-primitives, wp-url, wp-warning, wp-wordcount ⚠️

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

TypeScript Errors Report

  • Files with errors: 495
  • Total errors: 2255

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

assets/js/base/components/cart-checkout/totals/coupon/index.tsx

assets/js/base/components/cart-checkout/totals/coupon/stories/index.tsx

assets/js/base/context/hooks/cart/use-store-cart.ts

comments-aggregator

@github-actions
Copy link
Contributor

github-actions bot commented Jan 23, 2023

Size Change: -295 B (0%)

Total Size: 1.09 MB

Filename Size Change
build/active-filters-frontend.js 7.98 kB -3 B (0%)
build/active-filters-wrapper-frontend.js 6 kB -6 B (0%)
build/active-filters.js 7.29 kB -19 B (0%)
build/all-products-frontend.js 11.7 kB +34 B (0%)
build/all-products.js 33.6 kB +21 B (0%)
build/all-reviews.js 7.67 kB +3 B (0%)
build/attribute-filter-frontend.js 22.9 kB -22 B (0%)
build/attribute-filter-wrapper-frontend.js 7.67 kB -6 B (0%)
build/attribute-filter.js 12.4 kB -22 B (0%)
build/blocks-checkout.js 41 kB -31 B (0%)
build/cart-blocks/cart-cross-sells-products-frontend.js 9.64 kB -2 B (0%)
build/cart-blocks/cart-express-payment--checkout-blocks/express-payment-frontend.js 5.08 kB +3 B (0%)
build/cart-blocks/cart-line-items--mini-cart-contents-block/products-table-frontend.js 5.37 kB +30 B (+1%)
build/cart-blocks/cart-line-items-frontend.js 1.07 kB +1 B (0%)
build/cart-blocks/cart-order-summary-frontend.js 1.25 kB +2 B (0%)
build/cart-blocks/filled-cart-frontend.js 656 B +1 B (0%)
build/cart-blocks/order-summary-coupon-form-frontend.js 1.63 kB -54 B (-3%)
build/cart-blocks/order-summary-discount-frontend.js 2.13 kB +6 B (0%)
build/cart-blocks/order-summary-heading-frontend.js 456 B +1 B (0%)
build/cart-blocks/order-summary-shipping-frontend.js 14.9 kB -1 B (0%)
build/cart-blocks/order-summary-subtotal-frontend.js 274 B -1 B (0%)
build/cart-blocks/proceed-to-checkout-frontend.js 1.24 kB -1 B (0%)
build/cart-frontend.js 28.6 kB -16 B (0%)
build/cart.js 47.6 kB -23 B (0%)
build/catalog-sorting.js 1.71 kB +1 B (0%)
build/checkout-blocks/actions-frontend.js 1.85 kB -3 B (0%)
build/checkout-blocks/billing-address-frontend.js 1.16 kB -1 B (0%)
build/checkout-blocks/contact-information-frontend.js 2.05 kB -1 B (0%)
build/checkout-blocks/order-note-frontend.js 1.14 kB +2 B (0%)
build/checkout-blocks/order-summary-cart-items-frontend.js 3.68 kB -1 B (0%)
build/checkout-blocks/order-summary-coupon-form-frontend.js 1.79 kB -62 B (-3%)
build/checkout-blocks/order-summary-discount-frontend.js 2.3 kB +4 B (0%)
build/checkout-blocks/order-summary-frontend.js 1.25 kB +1 B (0%)
build/checkout-blocks/order-summary-shipping-frontend.js 14.9 kB -1 B (0%)
build/checkout-blocks/order-summary-taxes-frontend.js 435 B +1 B (0%)
build/checkout-blocks/payment-frontend.js 8.33 kB +6 B (0%)
build/checkout-blocks/shipping-address-frontend.js 1.12 kB -2 B (0%)
build/checkout-blocks/shipping-methods-frontend.js 4.83 kB -5 B (0%)
build/checkout-blocks/terms-frontend.js 1.56 kB +1 B (0%)
build/checkout-frontend.js 30.2 kB -12 B (0%)
build/checkout.js 43.4 kB -67 B (0%)
build/customer-account.js 3.08 kB -1 B (0%)
build/featured-category.js 13.1 kB +5 B (0%)
build/featured-product.js 13.4 kB +8 B (0%)
build/filter-wrapper-frontend.js 14 kB +6 B (0%)
build/filter-wrapper.js 2.4 kB +2 B (0%)
build/handpicked-products.js 7.24 kB +2 B (0%)
build/legacy-template.js 2.87 kB +1 B (0%)
build/mini-cart-component-frontend.js 27.9 kB +31 B (0%)
build/mini-cart-contents-block/footer-frontend.js 2.82 kB -3 B (0%)
build/mini-cart-contents.js 17 kB +46 B (0%)
build/mini-cart-frontend.js 2 kB +1 B (0%)
build/mini-cart.js 4.29 kB +1 B (0%)
build/price-filter-frontend.js 13.9 kB -8 B (0%)
build/price-filter-wrapper-frontend.js 7 kB -1 B (0%)
build/price-filter.js 8.39 kB -14 B (0%)
build/product-add-to-cart--product-button--product-category-list--product-image--product-price--product-r--a0326d00.js 227 B +1 B (0%)
build/product-add-to-cart-frontend.js 6.71 kB -1 B (0%)
build/product-add-to-cart.js 8.62 kB +31 B (0%)
build/product-best-sellers.js 7.61 kB +1 B (0%)
build/product-button--product-image--product-price--product-rating--product-sale-badge--product-title.js 258 B +1 B (0%)
build/product-button-frontend.js 2.14 kB -4 B (0%)
build/product-button.js 3.99 kB +22 B (+1%)
build/product-categories.js 2.36 kB -3 B (0%)
build/product-category.js 8.6 kB -1 B (0%)
build/product-image-frontend.js 2.14 kB -2 B (0%)
build/product-image.js 4.09 kB +28 B (+1%)
build/product-new.js 7.6 kB +3 B (0%)
build/product-price-frontend.js 2.23 kB +1 B (0%)
build/product-query.js 5.99 kB +3 B (0%)
build/product-rating-frontend.js 1.57 kB +1 B (0%)
build/product-rating.js 919 B -1 B (0%)
build/product-results-count.js 1.68 kB +4 B (0%)
build/product-sale-badge-frontend.js 1.37 kB -3 B (0%)
build/product-sale-badge.js 812 B -2 B (0%)
build/product-search.js 2.61 kB +1 B (0%)
build/product-sku.js 378 B +1 B (0%)
build/product-stock-indicator-frontend.js 1.26 kB -5 B (0%)
build/product-summary-frontend.js 1.53 kB +2 B (0%)
build/product-summary.js 919 B -1 B (0%)
build/product-tag-list-frontend.js 1.13 kB -3 B (0%)
build/product-tag-list.js 498 B +2 B (0%)
build/product-title-frontend.js 1.57 kB -1 B (0%)
build/product-title.js 3.46 kB +27 B (+1%)
build/product-top-rated.js 7.84 kB -1 B (0%)
build/products-by-attribute.js 8.52 kB +2 B (0%)
build/rating-filter-frontend.js 21.4 kB -35 B (0%)
build/rating-filter-wrapper-frontend.js 6.21 kB +1 B (0%)
build/rating-filter.js 7.43 kB -19 B (0%)
build/reviews-by-category.js 11.2 kB +2 B (0%)
build/reviews-by-product.js 12.3 kB +4 B (0%)
build/reviews-frontend.js 7.14 kB -5 B (0%)
build/single-product-frontend.js 17.8 kB +29 B (0%)
build/single-product.js 9.99 kB -3 B (0%)
build/stock-filter-frontend.js 21.1 kB -31 B (0%)
build/stock-filter-wrapper-frontend.js 5.87 kB -6 B (0%)
build/stock-filter.js 8.14 kB -31 B (0%)
build/vendors--attribute-filter-wrapper--rating-filter-wrapper--stock-filter-wrapper-frontend.js 7.7 kB +1 B (0%)
build/vendors--cart-blocks/cart-cross-sells-products--cart-blocks/order-summary-shipping--checkout-blocks--18f9376a-frontend.js 19.4 kB -2 B (0%)
build/vendors--cart-blocks/order-summary-shipping--checkout-blocks/billing-address--checkout-blocks/order--5b8feb0b-frontend.js 4.83 kB +1 B (0%)
build/vendors--checkout-blocks/shipping-method-frontend.js 12 kB -2 B (0%)
build/vendors--checkout-blocks/shipping-methods-frontend.js 9.48 kB +1 B (0%)
build/wc-blocks-data.js 21.9 kB -130 B (-1%)
build/wc-blocks-vendors.js 64.2 kB -5 B (0%)
ℹ️ View Unchanged
Filename Size
build/cart-blocks/cart-accepted-payment-methods-frontend.js 1.38 kB
build/cart-blocks/cart-cross-sells-frontend.js 253 B
build/cart-blocks/cart-express-payment-frontend.js 720 B
build/cart-blocks/cart-items-frontend.js 299 B
build/cart-blocks/cart-totals-frontend.js 321 B
build/cart-blocks/empty-cart-frontend.js 345 B
build/cart-blocks/order-summary-fee-frontend.js 274 B
build/cart-blocks/order-summary-taxes-frontend.js 435 B
build/checkout-blocks/billing-address--checkout-blocks/shipping-address-frontend.js 3.92 kB
build/checkout-blocks/express-payment-frontend.js 1.13 kB
build/checkout-blocks/fields-frontend.js 344 B
build/checkout-blocks/order-summary-fee-frontend.js 277 B
build/checkout-blocks/order-summary-subtotal-frontend.js 275 B
build/checkout-blocks/pickup-options-frontend.js 2.81 kB
build/checkout-blocks/shipping-method-frontend.js 2.27 kB
build/checkout-blocks/totals-frontend.js 324 B
build/general-style-rtl.css 1.31 kB
build/general-style.css 1.31 kB
build/mini-cart-contents-block/empty-cart-frontend.js 366 B
build/mini-cart-contents-block/filled-cart-frontend.js 268 B
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 313 B
build/mini-cart-contents-block/title-frontend.js 367 B
build/price-format.js 1.19 kB
build/product-add-to-cart--product-button--product-image--product-rating--product-title.js 151 B
build/product-button--product-category-list--product-image--product-price--product-rating--product-sale-b--e17c7c01.js 439 B
build/product-category-list-frontend.js 1.14 kB
build/product-category-list.js 503 B
build/product-on-sale.js 7.92 kB
build/product-price.js 1.58 kB
build/product-sku-frontend.js 629 B
build/product-stock-indicator.js 645 B
build/product-tag.js 8.08 kB
build/store-notices.js 1.65 kB
build/vendors--attribute-filter-wrapper--cart-blocks/cart-cross-sells-products--cart-blocks/order-summary--82e4ed06-frontend.js 6.86 kB
build/vendors--cart-blocks/cart-cross-sells-products--cart-blocks/cart-line-items--cart-blocks/cart-order--3c5fe802-frontend.js 5.26 kB
build/vendors--cart-blocks/cart-cross-sells-products--product-add-to-cart-frontend.js 7.53 kB
build/vendors--cart-blocks/cart-line-items--checkout-blocks/order-summary-cart-items--mini-cart-contents---233ab542-frontend.js 3.14 kB
build/wc-blocks-editor-style-rtl.css 5.47 kB
build/wc-blocks-editor-style.css 5.47 kB
build/wc-blocks-google-analytics.js 1.56 kB
build/wc-blocks-middleware.js 933 B
build/wc-blocks-registry.js 3.16 kB
build/wc-blocks-shared-context.js 1.52 kB
build/wc-blocks-shared-hocs.js 1.73 kB
build/wc-blocks-style-rtl.css 25.7 kB
build/wc-blocks-style.css 25.6 kB
build/wc-blocks-vendors-style-rtl.css 1.96 kB
build/wc-blocks-vendors-style.css 1.96 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
build/wc-shipping-method-pickup-location.js 29.7 kB

compressed-size-action

@mikejolley mikejolley added block: cart Issues related to the cart block. block: checkout Issues related to the checkout block. labels Jan 24, 2023
@mikejolley mikejolley force-pushed the add/cart-action-promises-reject-handling branch from 69bf5f8 to c2cb66b Compare January 24, 2023 12:32
@mikejolley mikejolley marked this pull request as ready for review January 24, 2023 12:32
@woocommercebot woocommercebot requested review from a team and nielslange and removed request for a team January 24, 2023 12:32
@mikejolley mikejolley force-pushed the add/cart-action-promises-reject-handling branch from f998874 to b13ad8c Compare January 25, 2023 13:43
@github-actions
Copy link
Contributor

Many of the functions that return promises in this file n...

Many of the functions that return promises in this file need to be moved to thunks.ts.


// @todo Many of the functions that return promises in this file need to be moved to thunks.ts.
export * from './thunks';
/**

🚀 This comment was generated by the automations bot based on a todo comment in 62da5b2 in #8272. cc @mikejolley

/**
* This function is used to notify the user of cart errors.
*/
export const notifyErrors = ( error: ApiErrorResponse | null = null ) => {
Copy link
Member Author

Choose a reason for hiding this comment

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

This has been consolidated into processErrorResponse.

@@ -23,8 +23,10 @@ import { ACTION_TYPES as types } from './action-types';
import { apiFetchWithHeaders } from '../shared-controls';
Copy link
Member Author

Choose a reason for hiding this comment

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

Each function here will now work in the way way; returning a promise with either the successful response, or rejecting with the error message so that consumers can handle the error objects.

Copy link
Member

Choose a reason for hiding this comment

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

This effectively means we fully moved out notice triggering from data stores and into hooks?

Copy link
Member Author

Choose a reason for hiding this comment

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

@senadir There is some still in receiveCart, but yeah for errors its back inside hooks.

@@ -275,7 +276,8 @@ const CheckoutProcessor = () => {
)
.then( ( response: CheckoutResponseError ) => {
if ( response.data?.cart ) {
receiveCart( response.data.cart );
// We don't want to receive the address here because it will overwrite fields.
receiveCartContents( response.data.cart );
Copy link
Member Author

Choose a reason for hiding this comment

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

This fixes the address data being lost after a failed checkout request if data has not yet persisted. https://a8c.slack.com/archives/C8X6Q7XQU/p1674643137575739

Copy link
Member

Choose a reason for hiding this comment

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

I couldn't find where receiveCartContents is defined so I assume it was already in trunk, I'm trying to understand its role here, at least, I understand that it sets everything except the addresses, but why do we need to do that? Why is the data returned from the server inconsistent? if addresses didn't persist, shouldn't we assume line items and such are going to be incorrect here and just reject the whole thing and show errors?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's in trunk already (#7711). Its there because when you're persisting address data to the server, in particular partial address data, it is not desirable to update the stores with the response—the data in the stores may be more current. We needed this change after introducing partial pushes, since the partial push does not include all current data.

Copy link
Member

Choose a reason for hiding this comment

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

Gotcha! in that case, are partial updates the only place where we deploy receiveCartContents?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes and when editing (updateCustomerData), which is where receiveCartContents was already in use.

} )
.catch( ( error ) => {
createErrorNotice( error.message, {
id: 'coupon-form',
context,
} );
// Finished handling the coupon.
receiveApplyingCoupon( '' );
Copy link
Member Author

Choose a reason for hiding this comment

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

This is handled in the thunks already.

@mikejolley mikejolley force-pushed the add/cart-action-promises-reject-handling branch from 1948990 to 976efa0 Compare January 25, 2023 16:29
@nielslange nielslange added the status: blocker Used on issues or pulls that block work from being released. label Jan 30, 2023
@nielslange nielslange added this to the 9.5.0 milestone Jan 30, 2023
Copy link
Member

@senadir senadir left a comment

Choose a reason for hiding this comment

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

I did a code review for this PR, in some parts, the refactor is great (better error context management, decoupling notices from data stores), the only part I'm struggling with is the recieveCartContent and how it ties into this.

Comment on lines +74 to +83
if ( onSubmit !== undefined ) {
onSubmit( couponValue ).then( ( result ) => {
if ( result ) {
setCouponValue( '' );
setIsCouponFormHidden( true );
}
} );
} else {
setCouponValue( '' );
setIsCouponFormHidden( true );
Copy link
Member

Choose a reason for hiding this comment

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

This is possible confusing, why is onSubmit ever undefined?

Copy link
Member Author

Choose a reason for hiding this comment

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

The typedef allows for undefined, so this just handles that case.

@@ -23,8 +23,10 @@ import { ACTION_TYPES as types } from './action-types';
import { apiFetchWithHeaders } from '../shared-controls';
Copy link
Member

Choose a reason for hiding this comment

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

This effectively means we fully moved out notice triggering from data stores and into hooks?

@@ -275,7 +276,8 @@ const CheckoutProcessor = () => {
)
.then( ( response: CheckoutResponseError ) => {
if ( response.data?.cart ) {
receiveCart( response.data.cart );
// We don't want to receive the address here because it will overwrite fields.
receiveCartContents( response.data.cart );
Copy link
Member

Choose a reason for hiding this comment

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

I couldn't find where receiveCartContents is defined so I assume it was already in trunk, I'm trying to understand its role here, at least, I understand that it sets everything except the addresses, but why do we need to do that? Why is the data returned from the server inconsistent? if addresses didn't persist, shouldn't we assume line items and such are going to be incorrect here and just reject the whole thing and show errors?

Copy link
Member

@nielslange nielslange left a comment

Choose a reason for hiding this comment

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

I've successfully tested the PR against the various test cases mentioned in this PR.

@mikejolley mikejolley merged commit 7a0e1cb into trunk Jan 30, 2023
@mikejolley mikejolley deleted the add/cart-action-promises-reject-handling branch January 30, 2023 15:12
@nielslange nielslange added skip-changelog PRs that you don't want to appear in the changelog. and removed status: blocker Used on issues or pulls that block work from being released. labels Jan 30, 2023
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. skip-changelog PRs that you don't want to appear in the changelog.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants