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

Feature: Data Store Migration #6612

Merged
merged 23 commits into from
Sep 28, 2022
Merged

Feature: Data Store Migration #6612

merged 23 commits into from
Sep 28, 2022

Conversation

alexflorisca
Copy link
Member

@alexflorisca alexflorisca commented Jun 21, 2022

This is a feature PR that contains multiple PRs related to the data store migration project. The goal is to replace some of the contexts with data stores, in order to make the data easier to access (not restricted to the context where it's defined)

Fixes #7158

PRs to be merged into this PR:

Issues to be solved before this PR is merged:

  • Update the payment methods unit tests
  • Smoke test like there's no tomorrow using these instructions

Other things to consider before this PR is merged:

  • Write tests for the checkout data store reducer & possibly thunks
  • Make sure there's no failing unit or E2E tests (or if flakey e2e tests make sure they are unrelated, run a few times)

This is a issue tracker of things that are related to this PR, but that can wait until we merge this to trunk
#6625

Other Checks

  • This PR adds/removes a feature flag & I've updated this doc .
  • This PR adds/removes an experimental interfaces and I've updated this doc
  • I tagged two reviewers because this PR makes queries to the database or I think it might have some security impact.

Testing

Automated Tests

This PR includes some automated tests for the reducers of the new data stores

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

Manual Testing

The full instructions for testing this PR can be found here. At a minimum, we will need to smoke test by trying the different stripe failure modes

  • Do not include in the Testing Notes

WooCommerce Visibility

  • WooCommerce Core
  • Feature plugin
  • Experimental

Changelog

Exposed data related to the checkout through wordpress/data stores

@alexflorisca alexflorisca added the block: checkout Issues related to the checkout block. label Jun 21, 2022
@alexflorisca alexflorisca added this to the Behind Feature Flag milestone Jun 21, 2022
@alexflorisca alexflorisca added type: enhancement The issue is a request for an enhancement. focus: blocks Specific work involving or impacting how blocks behave. labels Jun 21, 2022
@alexflorisca alexflorisca force-pushed the feature/data-store-refactor branch from bb4d7db to d44a8b1 Compare June 22, 2022 08:49
@github-actions
Copy link
Contributor

`useEmitResponse` is not a react hook, it just exposes so...

`useEmitResponse` is not a react hook, it just exposes some functions as properties of an object. Refactor this to not be a hook, we could simply import those functions where needed


// TODO: `useEmitResponse` is not a react hook, it just exposes some functions as
// properties of an object. Refactor this to not be a hook, we could simply import
// those functions where needed
/**
* Based on the given observers, create Error Notices where necessary
* and return the error response of the last registered observer
*/
export const handleErrorResponse = ( {
observerResponses,
createErrorNotice,
}: {
observerResponses: unknown[];
createErrorNotice: typeof originalCreateErrorNotice;

🚀 This comment was generated by the automations bot based on a todo comment in e1128eb in #6612. cc @alexflorisca

@github-actions
Copy link
Contributor

Fix this type after we move to validation store

Fix this type after we move to validation store


setValidationErrors, // TODO: Fix this type after we move to validation store
} ) => {
return ( { dispatch, registry } ) => {
const { createErrorNotice } = registry.dispatch( noticesStore );
removeNoticesByStatus( 'error' );
emitEvent(
observers,
EVENTS.CHECKOUT_VALIDATION_BEFORE_PROCESSING,
{}
).then( ( response ) => {
if ( response !== true ) {
if ( Array.isArray( response ) ) {

🚀 This comment was generated by the automations bot based on a todo comment in e1128eb in #6612. cc @alexflorisca

@github-actions
Copy link
Contributor

Gutenberg with Thunks was released in WP 6.0.

Gutenberg with Thunks was released in WP 6.0. Once 6.1 is released, remove the experimental flag here eslint-disable-next-line @typescript-eslint/ban-ts-comment


// TODO: Gutenberg with Thunks was released in WP 6.0. Once 6.1 is released, remove the experimental flag here
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore We pass this in case there is an older version of Gutenberg running.
__experimentalUseThunks: true,
};
const store = createReduxStore( STORE_KEY, config );
register( store );
export const CHECKOUT_STORE_KEY = STORE_KEY;
declare module '@wordpress/data' {
function dispatch(
key: typeof CHECKOUT_STORE_KEY

🚀 This comment was generated by the automations bot based on a todo comment in e1128eb in #6612. cc @alexflorisca

@github-actions
Copy link
Contributor

`useEmitResponse` is not a react hook, it just exposes so...

`useEmitResponse` is not a react hook, it just exposes some functions as properties of an object. Refactor this to not be a hook, we could simply import those functions where needed


// TODO: `useEmitResponse` is not a react hook, it just exposes some functions as
// properties of an object. Refactor this to not be a hook, we could simply import
// those functions where needed
/**
* Based on the given observers, create Error Notices where necessary
* and return the error response of the last registered observer
*/
export const handleErrorResponse = ( {
observerResponses,
createErrorNotice,
}: {
observerResponses: unknown[];
createErrorNotice: typeof originalCreateErrorNotice;

🚀 This comment was generated by the automations bot based on a todo comment in 6cc5a48 in #6612. cc @alexflorisca

@github-actions
Copy link
Contributor

github-actions bot commented Jun 23, 2022

Size Change: -30.7 kB (-3%)

Total Size: 903 kB

Filename Size Change
build/active-filters-frontend.js 7.62 kB +3 B (0%)
build/active-filters.js 8.27 kB -12 B (0%)
build/all-products-frontend.js 26.4 kB -83 B (0%)
build/all-products.js 33.6 kB -522 B (-2%)
build/attribute-filter-frontend.js 22.3 kB -10 B (0%)
build/attribute-filter.js 13.3 kB -25 B (0%)
build/blocks-checkout.js 17.5 kB +74 B (0%)
build/cart-blocks/cart-accepted-payment-methods-frontend.js 1.39 kB +223 B (+19%) ⚠️
build/cart-blocks/cart-cross-sells-frontend.js 252 B -1 B (0%)
build/cart-blocks/cart-cross-sells-products--product-add-to-cart-frontend.js 5.63 kB +201 B (+4%)
build/cart-blocks/cart-cross-sells-products-frontend.js 4.66 kB +4 B (0%)
build/cart-blocks/cart-express-payment-frontend.js 801 B -4.28 kB (-84%) 🏆
build/cart-blocks/cart-line-items--mini-cart-contents-block/products-table-frontend.js 5.26 kB -2 B (0%)
build/cart-blocks/cart-line-items-frontend.js 1.06 kB +632 B (+147%) 🆘
build/cart-blocks/cart-order-summary-frontend.js 1.11 kB +2 B (0%)
build/cart-blocks/cart-totals-frontend.js 322 B -1 B (0%)
build/cart-blocks/empty-cart-frontend.js 347 B +1 B (0%)
build/cart-blocks/filled-cart-frontend.js 782 B -1 B (0%)
build/cart-blocks/order-summary-coupon-form-frontend.js 2.73 kB +85 B (+3%)
build/cart-blocks/order-summary-discount-frontend.js 2.16 kB +8 B (0%)
build/cart-blocks/order-summary-fee-frontend.js 273 B -1 B (0%)
build/cart-blocks/order-summary-heading-frontend.js 455 B +1 B (0%)
build/cart-blocks/order-summary-shipping--checkout-blocks/order-summary-shipping-frontend.js 6.73 kB +208 B (+3%)
build/cart-blocks/order-summary-shipping-frontend.js 428 B +1 B (0%)
build/cart-blocks/order-summary-taxes-frontend.js 432 B -3 B (-1%)
build/cart-blocks/proceed-to-checkout-frontend.js 1.19 kB +33 B (+3%)
build/cart-frontend.js 50.4 kB -5.78 kB (-10%) 👏
build/cart.js 46.4 kB -4.04 kB (-8%)
build/checkout-blocks/actions-frontend.js 1.76 kB +347 B (+25%) 🚨
build/checkout-blocks/billing-address--checkout-blocks/shipping-address-frontend.js 4.94 kB +827 B (+20%) 🚨
build/checkout-blocks/billing-address-frontend.js 927 B +38 B (+4%)
build/checkout-blocks/contact-information-frontend.js 2.99 kB +155 B (+5%) 🔍
build/checkout-blocks/express-payment-frontend.js 1.18 kB -4.19 kB (-78%) 🏆
build/checkout-blocks/fields-frontend.js 342 B -3 B (-1%)
build/checkout-blocks/order-note-frontend.js 1.13 kB +56 B (+5%) 🔍
build/checkout-blocks/order-summary-cart-items-frontend.js 3.67 kB +6 B (0%)
build/checkout-blocks/order-summary-coupon-form-frontend.js 2.88 kB +87 B (+3%)
build/checkout-blocks/order-summary-discount-frontend.js 2.28 kB +8 B (0%)
build/checkout-blocks/order-summary-fee-frontend.js 275 B -1 B (0%)
build/checkout-blocks/order-summary-frontend.js 1.11 kB +2 B (0%)
build/checkout-blocks/order-summary-shipping-frontend.js 604 B +3 B (0%)
build/checkout-blocks/order-summary-subtotal-frontend.js 274 B -1 B (0%)
build/checkout-blocks/order-summary-taxes-frontend.js 433 B -2 B (0%)
build/checkout-blocks/payment-frontend.js 7.89 kB +208 B (+3%)
build/checkout-blocks/shipping-address-frontend.js 1.06 kB +34 B (+3%)
build/checkout-blocks/shipping-methods-frontend.js 4.98 kB +72 B (+1%)
build/checkout-blocks/terms-frontend.js 1.62 kB +392 B (+32%) 🚨
build/checkout-blocks/totals-frontend.js 323 B -2 B (-1%)
build/checkout-frontend.js 52.5 kB -5.57 kB (-10%) 👏
build/checkout.js 40.1 kB -3.77 kB (-9%)
build/featured-category.js 13.2 kB -25 B (0%)
build/featured-product.js 13.4 kB -22 B (0%)
build/handpicked-products.js 7.29 kB -45 B (-1%)
build/legacy-template.js 2.84 kB -1 B (0%)
build/mini-cart-component-frontend.js 16.8 kB -40 B (0%)
build/mini-cart-contents-block/filled-cart-frontend.js 230 B +1 B (0%)
build/mini-cart-contents-block/footer--mini-cart-contents-block/products-table-frontend.js 0 B -4.69 kB (removed) 🏆
build/mini-cart-contents-block/footer-frontend.js 3.18 kB -4.21 kB (-57%) 🏆
build/mini-cart-contents-block/products-table-frontend.js 592 B +301 B (+103%) 🆘
build/mini-cart-contents.js 17 kB -6.44 kB (-27%) 🎉
build/mini-cart.js 4.57 kB +4 B (0%)
build/price-filter.js 9.34 kB -14 B (0%)
build/product-add-to-cart--product-button--product-image--product-title.js 2.66 kB -28 B (-1%)
build/product-add-to-cart-frontend.js 1.24 kB -1.36 kB (-52%) 🏆
build/product-add-to-cart.js 6.48 kB -393 B (-6%)
build/product-best-sellers.js 7.62 kB -79 B (-1%)
build/product-button--product-category-list--product-image--product-price--product-rating--product-sale-b--e17c7c01.js 432 B +1 B (0%)
build/product-button-frontend.js 1.88 kB -6 B (0%)
build/product-button.js 1.58 kB -5 B (0%)
build/product-categories.js 2.36 kB -5 B (0%)
build/product-category-list-frontend.js 878 B -3 B (0%)
build/product-category-list.js 502 B -1 B (0%)
build/product-category.js 8.61 kB -80 B (-1%)
build/product-image-frontend.js 1.91 kB -1 B (0%)
build/product-image.js 1.61 kB -1 B (0%)
build/product-new.js 7.62 kB -75 B (-1%)
build/product-on-sale.js 7.94 kB -73 B (-1%)
build/product-price.js 1.53 kB +5 B (0%)
build/product-query.js 649 B +2 B (0%)
build/product-rating-frontend.js 1.18 kB +2 B (0%)
build/product-rating.js 772 B -1 B (0%)
build/product-sale-badge.js 817 B +3 B (0%)
build/product-search.js 2.62 kB -1 B (0%)
build/product-sku-frontend.js 381 B +1 B (0%)
build/product-sku.js 379 B -1 B (0%)
build/product-stock-indicator-frontend.js 993 B -1 B (0%)
build/product-stock-indicator.js 624 B +1 B (0%)
build/product-summary-frontend.js 1.29 kB +2 B (0%)
build/product-summary.js 920 B -1 B (0%)
build/product-tag.js 7.99 kB -57 B (-1%)
build/product-title-frontend.js 1.33 kB -3 B (0%)
build/product-title.js 936 B -2 B (0%)
build/product-top-rated.js 7.86 kB -71 B (-1%)
build/products-by-attribute.js 8.53 kB -91 B (-1%)
build/reviews-by-category.js 11.2 kB -84 B (-1%)
build/reviews-by-product.js 12.3 kB -102 B (-1%)
build/reviews-frontend.js 7.01 kB +1 B (0%)
build/single-product-frontend.js 29.3 kB -106 B (0%)
build/single-product.js 10 kB -41 B (0%)
build/stock-filter-frontend.js 7.62 kB +4 B (0%)
build/stock-filter.js 7.53 kB -23 B (0%)
build/vendors--cart-blocks/cart-cross-sells-products--cart-blocks/cart-line-items--cart-blocks/cart-order--04fe80d1-frontend.js 5.26 kB -1 B (0%)
build/vendors--cart-blocks/cart-cross-sells-products--cart-blocks/order-summary-shipping--checkout-blocks--18f9376a-frontend.js 19.1 kB +8 B (0%)
build/vendors--cart-blocks/cart-cross-sells-products--product-add-to-cart-frontend.js 7.53 kB +620 B (+9%) 🔍
build/vendors--cart-blocks/cart-line-items--checkout-blocks/order-summary-cart-items--mini-cart-contents---233ab542-frontend.js 3.14 kB -1 B (0%)
build/vendors--cart-blocks/order-summary-shipping--checkout-blocks/billing-address--checkout-blocks/order--5b8feb0b-frontend.js 4.85 kB -1 B (0%)
build/vendors--mini-cart-contents-block/footer-frontend.js 6.86 kB +2 B (0%)
build/wc-blocks-data.js 15.9 kB +5.98 kB (+60%) 🆘
build/wc-blocks-middleware.js 932 B +1 B (0%)
build/wc-blocks-registry.js 2.79 kB +93 B (+3%)
build/wc-blocks-shared-context.js 1.52 kB +2 B (0%)
build/wc-blocks-shared-hocs.js 1.72 kB +9 B (+1%)
build/wc-blocks-style-rtl.css 24 kB -5 B (0%)
build/wc-blocks-style.css 23.9 kB -5 B (0%)
build/wc-blocks-vendors.js 62 kB -29 B (0%)
build/wc-blocks.js 2.62 kB -1 B (0%)
build/wc-settings.js 2.6 kB -1 B (0%)
build/cart-blocks/cart-express-payment--checkout-blocks/express-payment-frontend.js 5.12 kB +5.12 kB (new file) 🆕
ℹ️ View Unchanged
Filename Size
build/all-reviews.js 7.79 kB
build/cart-blocks/cart-items-frontend.js 299 B
build/cart-blocks/order-summary-subtotal-frontend.js 274 B
build/general-style-rtl.css 1.29 kB
build/general-style.css 1.29 kB
build/mini-cart-contents-block/empty-cart-frontend.js 366 B
build/mini-cart-contents-block/items-frontend.js 237 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-frontend.js 1.72 kB
build/price-filter-frontend.js 13.4 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 226 B
build/product-button--product-image--product-rating--product-sale-badge--product-title.js 302 B
build/product-price-frontend.js 1.91 kB
build/product-sale-badge-frontend.js 1.14 kB
build/product-tag-list-frontend.js 874 B
build/product-tag-list.js 497 B
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-vendors-style-rtl.css 1.95 kB
build/wc-blocks-vendors-style.css 1.95 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

compressed-size-action

@github-actions
Copy link
Contributor

`useEmitResponse` is not a react hook, it just exposes so...

`useEmitResponse` is not a react hook, it just exposes some functions as properties of an object. Refactor this to not be a hook, we could simply import those functions where needed


// TODO: `useEmitResponse` is not a react hook, it just exposes some functions as
// properties of an object. Refactor this to not be a hook, we could simply import
// those functions where needed
/**
* Based on the given observers, create Error Notices where necessary
* and return the error response of the last registered observer
*/
export const handleErrorResponse = ( {
observerResponses,
createErrorNotice,
}: {
observerResponses: unknown[];
createErrorNotice: typeof originalCreateErrorNotice;

🚀 This comment was generated by the automations bot based on a todo comment in 4dff564 in #6612. cc @alexflorisca

@github-actions
Copy link
Contributor

`useEmitResponse` is not a react hook, it just exposes so...

`useEmitResponse` is not a react hook, it just exposes some functions as properties of an object. Refactor this to not be a hook, we could simply import those functions where needed


// TODO: `useEmitResponse` is not a react hook, it just exposes some functions as
// properties of an object. Refactor this to not be a hook, we could simply import
// those functions where needed
/**
* Based on the given observers, create Error Notices where necessary
* and return the error response of the last registered observer
*/
export const handleErrorResponse = ( {
observerResponses,
createErrorNotice,
}: {
observerResponses: unknown[];
createErrorNotice: typeof originalCreateErrorNotice;

🚀 This comment was generated by the automations bot based on a todo comment in 850f395 in #6612. cc @alexflorisca

@github-actions
Copy link
Contributor

github-actions bot commented Jul 1, 2022

`useEmitResponse` is not a react hook, it just exposes so...

`useEmitResponse` is not a react hook, it just exposes some functions as properties of an object. Refactor this to not be a hook, we could simply import those functions where needed


// TODO: `useEmitResponse` is not a react hook, it just exposes some functions as
// properties of an object. Refactor this to not be a hook, we could simply import
// those functions where needed
/**
* Based on the given observers, create Error Notices where necessary
* and return the error response of the last registered observer
*/
export const handleErrorResponse = ( {
observerResponses,
createErrorNotice,
}: {
observerResponses: unknown[];
createErrorNotice: typeof originalCreateErrorNotice;

🚀 This comment was generated by the automations bot based on a todo comment in 6b4dd69 in #6612. cc @alexflorisca

@github-actions
Copy link
Contributor

github-actions bot commented Jul 14, 2022

Script Dependencies Report

There is no changed script dependency between this branch and trunk.

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

@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-6612.zip

return state.currentStatus;
};

export const getShouldSavePaymentMethod = ( state: PaymentMethodDataState ) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

There is another selector above called shouldSavePaymentMethod that returns the same thing. Let's remove one.

@github-actions
Copy link
Contributor

See if we can stop this being dispatched if the currently...

See if we can stop this being dispatched if the currently selected method is still available.


// TODO See if we can stop this being dispatched if the currently selected method is still available.
await setDefaultPaymentMethod( paymentMethods );
dispatch( {
type: ACTION_TYPES.SET_AVAILABLE_PAYMENT_METHODS,
paymentMethods,
} );
};
};
/**
* Set the available express payment methods.
* An available payment method is one that has been validated and can make a payment.

🚀 This comment was generated by the automations bot based on a todo comment in c5b173d in #6612. cc @alexflorisca

@opr opr force-pushed the feature/data-store-refactor branch 2 times, most recently from f6d5513 to a5940d4 Compare August 25, 2022 09:38
@alexflorisca alexflorisca marked this pull request as ready for review August 25, 2022 09:48
@rubikuserbot rubikuserbot requested review from a team and nielslange and removed request for a team August 25, 2022 09:48
@opr opr force-pushed the feature/data-store-refactor branch from afeb55a to 065770b Compare September 5, 2022 14:08
@alexflorisca
Copy link
Member Author

While smoke testing this PR, I found and fixed 2 bugs.

  1. When reseting the payment status to pristine, we were not resetting the other status properties. This is due to the complex nature of the payment status implementation, which will be refactored in a future, based on this issue. This caused stripe to not refresh its payment-key for each payment attempt, which means it was trying to create a new payment attempt that already existed, and exited with a generic error.

This was fixed in this commit, by reseting the rest of the status properties to their default values, whenever the status is changed to PRISTINE.

  1. Active payment methods were checked before the stripe scripts had chance to run, so the stripe-gateway payment method was returning an api key not set error message.

This was fixed in this commit, by checking if the store is initialised before we check active payment methods. The cart store checks the active payment methods on every change because third party developers can choose to activate/deactivate payment methods based on cart data.

opr and others added 16 commits September 28, 2022 10:38
…yment data store (#6669)

* Mock getCartTotals

* Change test to use data store instead of context

* Move payment method context test to data store selectors

* Change description of test suite

* Bump commit to trigger tests

* Fix path in test

* update package lock

* Set correct state payment method reducer tests/use correct actions

* Get saved payment methods from store not context

* Mock stores and update tests to allow switching payment methods

* Update tests to get onSubmit from checkoutEventsContext

* Remove cartTotalsLoaded check from payment method initialize check

* Make PaymentMethods test wait until payments initialized

* initialize payment method data store when cart is loaded

* Remove unneeded actions and add initializePaymentMethodDataStore

* Remove check for cart totals loaded in checkPaymentMethods

* Remove updateAvilablePaymentMethods from registry

* Remove unneeded mock

* Remove unused import

* Rename imports to fix eslint errors

* Remove unused imports

* Remove return false from checkPaymentMethods

* Remove unnecessary setPaymentMethodsInitialized call

* Add todo comment to track refactoring opportunity

* Remove savedpayment methods from payment method context and rename it

* Rename payment method data context to payment method events context

* Add tests for setDefaultPaymentMethods

* Optimize the availablePaymentMethods state data

Store only the "name" attribute for now.

* Get list of payment methods from the registry instead of the store

We are using this hook to get some React elements in the payment method
object. So, we are getting the raw data directly from the registry instead
of the store.

* Fix payment state not loading on the Checkout edit page

* Handle checkout edit page case

* Fix infinite loop error on C&C Blocks

* Include @wordpress/redux-routine in transformIgnorePatterns jest config

Co-authored-by: Saad Tarhi <[email protected]>
… `wc/store/validation` data store (#7146)

* Convert checkout context to data store - part 1 (#6232)

* Add checkout data store

* wip on checkout data store

* CheckoutContext now uses the checkout store

* Investigated and removed setting the redirectUrl on the default state

* update extension and address hooks to use checkout data store

* use checkout data store in checkout-processor and use-checkout-button

* trim useCheckoutContext from use-payment-method-interface && use-store-cart-item-quantity

* Remove useCheckoutContext from shipping provider

* Remove isCalculating from state

* Removed useCheckoutContext from lots of places

* Remove useCheckoutContext from checkout-payment-block

* Remove useCheckoutContext in checkout-shipping-methods-block and checkout-shipping-address-block

* add isCart selector and action and update the checkoutstate context

* Fixed redirectUrl bug by using thunks

* Remove dispatchActions from checkout-state

* Change SET_HAS_ERROR action to be neater

* Thomas' feedback

* Tidy up

* Oops, deleted things I shouldn't have

* Typescript

* Fix types

* Fix tests

* Remove isCart

* Update docs and remove unecessary getRedirectUrl() selector

* set correct type for preloadedCheckoutData

* Remove duplicate Address type

* Fix missing addresses from type-defs index

* Update docs/block-client-apis/checkout/checkout-api.md

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

* Update docs/block-client-apis/checkout/checkout-api.md

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

* Update docs

* Update docs/block-client-apis/checkout/checkout-api.md

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

* Update docs/block-client-apis/checkout/checkout-api.md

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

* Revert feedback changes

* REvert feedback formatting

* Update docs formatting

* Delete empty types.ts file

* remove merge conflict from docs

* Correct linting in docs

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

* Move checkout state code into thunks and rename `CheckoutState` context to `CheckoutEvents` (#6455)

* Add checkout data store

* wip on checkout data store

* CheckoutContext now uses the checkout store

* Investigated and removed setting the redirectUrl on the default state

* update extension and address hooks to use checkout data store

* use checkout data store in checkout-processor and use-checkout-button

* trim useCheckoutContext from use-payment-method-interface && use-store-cart-item-quantity

* Remove useCheckoutContext from shipping provider

* Remove isCalculating from state

* Removed useCheckoutContext from lots of places

* Remove useCheckoutContext from checkout-payment-block

* Remove useCheckoutContext in checkout-shipping-methods-block and checkout-shipping-address-block

* add isCart selector and action and update the checkoutstate context

* Fixed redirectUrl bug by using thunks

* Remove dispatchActions from checkout-state

* Change SET_HAS_ERROR action to be neater

* Thomas' feedback

* Tidy up

* Oops, deleted things I shouldn't have

* Typescript

* Fix types

* Fix tests

* Remove isCart

* Update docs and remove unecessary getRedirectUrl() selector

* validate event emitter button

* Added thunks in a separate file

* Call thunks from checkout-state

* Checkout logic tested and working

* Remove dependency injection as much as poss, tidy up and fix some TS errors

* Fix types in thunks.ts

* Fixed some ts errors

* WIP

* Fixed bug

* Shift side effects from checkout-state to checkout-processor

* Revert "Shift side effects from checkout-state to checkout-processor"

This reverts commit 059533d.

* Rename CheckoutState to CheckoutEvents

* Move status check outside the thunk

* remove duplicate EVENTS constant

* remove temp buttons

* Remove console logs

* Augment @wordpress/data package with our new store types

* Add correct type for CheckoutAction

* Remove createErrorNotice arg from runCheckoutAfterProcessingWithErrorObservers

* Remove createErrorNotice from emit event types

* Use type keyword when importing types

* Add correct types for dispatch and select in thunks

* Update wordpress/data types

* Replace store creation with new preferred method

* Set correct action type on reducer

* Remove unnecessary async from thunk

* add CHECKOUT_ prefix to checkout events again

* export EVENTS with eveything else in checkout0-events/event-emit

* Remove duplicate SelectFromMap and TailParameters

* Updated type for paymentStatus

* TODO remove wp/data experimental thunks

* Remove `setCustomerId` from events and `processCheckoutResponseHeaders` (#6586)

* Prevent passing dispatch, instead get actions direct from store

* Get setCustomerId from the store instead of passing it to processCheckoutResponseHeaders

* Revert "Prevent passing dispatch, instead get actions direct from store"

This reverts commit 4479a2e.

* Auto stash before revert of "Prevent passing dispatch, instead get actions direct from store"

* Remove duplicate dispatch

* Fix unit tests

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

* Refactor selectors to not return functions anymore

This is a poor DevEx and naming did not reflect what the selector was returning.

* Update combobox to be more explicit when selecting validation error

* Update useValidation to use the new getValidationError selector

* Include @woocommerce/base-hooks in tsconfig

* Update ValidationInputError to use new selector

* Update ValidatedTextInput to use new selectors

* Prevent reference errors when getting validation errors in ComboBox

* Defend against case where message prop of error object is undefined

* Fix totals/coupon to use new validation selector

* Use validation data store in CheckoutTerms block

* Update AddressForm to use new validation selector

* Update AttributeSelectControl to use new validation selector

* Fix syntax error in ValidatedTextInput

* Fix multiple import error from rebase

* Fix lint issue in useStoreCartItemQantity

* Fix tests to reflect new selector API

* Remove unused validation prop from CheckoutTermsBlock

* Change CheckoutTermsBlock unit tests to use validation data store

* Fix JSDOC syntax

* fix merge conflict in checkout-api.md

Co-authored-by: Alex Florisca <[email protected]>
Co-authored-by: Niels Lange <[email protected]>
@alexflorisca alexflorisca force-pushed the feature/data-store-refactor branch from 6446933 to f761e76 Compare September 28, 2022 09:39
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
block: checkout Issues related to the checkout block. focus: blocks Specific work involving or impacting how blocks behave. type: enhancement The issue is a request for an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

canMakePayment not running on initial pageload
3 participants