Commit Graph

4062 Commits

Author SHA1 Message Date
Tarun Vijwani 75d6e84552 Hide the shipping address form from the Checkout when the "Force shipping to the customer billing address" is enabled (https://github.com/woocommerce/woocommerce-blocks/pull/7268)
* Hide shipping address form from the Checkout when forced billing address is enabled.

* Update shipping address when billing address is changed

* Display shipping options

* Fixed needs shipping condition

Co-authored-by: Saad Tarhi <saad.trh@gmail.com>
2022-10-07 08:50:26 +01:00
Daniel W. Robert 27ad42cd20 Add updated deps from fresh install. (https://github.com/woocommerce/woocommerce-blocks/pull/7296) 2022-10-06 13:46:48 -04:00
Niels Lange 5fe9de69f6 Render HTML in description of active payment integrations (https://github.com/woocommerce/woocommerce-blocks/pull/7313) 2022-10-06 23:52:42 +07:00
Alex Florisca aefcf65dd8 Consolidate Address types (https://github.com/woocommerce/woocommerce-blocks/pull/7272)
* Consolidate Address types

* Revert "Consolidate Address types"

This reverts commit cb708a3d714621717414ec17f5e1071be5ca5e96.

* Rename EnteredAddress to CustomerAddress

* Delete unused Address type

* Thomas suggestions

* Fix duplicate ShippingAddress symbol
2022-10-06 15:48:52 +01:00
Alba Rincón f3295f1780 Register new header patterns (https://github.com/woocommerce/woocommerce-blocks/pull/7292)
* Register new header patterns

* Fix name

* Capitalize the header word

* Remove ref from the navigation menu
2022-10-06 14:16:32 +01:00
Alex Florisca 7bf79f33d9 Rename payment-method-data-context to payment-events-context and PAYMENT_METHOD_DATA_STORE_KEY to PAYMENT_STORE_KEY (https://github.com/woocommerce/woocommerce-blocks/pull/7304)
* Rename payment-method-data-context to payment-event-context and tidy up types and things

* Rename uses of PAYMENT_METHOD_DATA_STORE_KEY to PAYMENT_STORE_KEY

* Rename __internalInitializePaymentMethodDataStore and unsubscribeInitializePaymentMethodDataStore

* Rename unsubscribeInitializePaymentMethodDataStore
2022-10-06 13:46:46 +01:00
Manish Menaria 918c9515d7 Register new footer patterns (https://github.com/woocommerce/woocommerce-blocks/pull/7306)
* Register new footer patterns

* Capitalize the footer word

* Fix large footer pattern content cut-off issue

For more info:
https://github.com/woocommerce/woocommerce-blocks/pull/7306#issuecomment-1268491571
https://github.com/woocommerce/woocommerce-blocks/pull/7306#issuecomment-1269717251

Co-authored-by: Alba Rincón <alba.rincon@automattic.com>
2022-10-06 17:57:09 +05:30
Niels Lange 40204ce740 Update readme.txt (https://github.com/woocommerce/woocommerce-blocks/pull/7280)
* Update readme.txt

* Add missing blocks
2022-10-06 13:07:36 +07:00
Luigi Teschio f7cee9e54a Import useEffect from @wordpress/element package (https://github.com/woocommerce/woocommerce-blocks/pull/7298)
Import useEffect from @wordpress/element package
2022-10-05 15:20:34 +02:00
Thomas Roberts df3b785244 Rename `wc/store/payment-methods` to `wc/store/payment` (https://github.com/woocommerce/woocommerce-blocks/pull/7267)
* Rename wc/store/payment-methods to wc/store/payment

* Rename folder to payment

Co-authored-by: Alex Florisca <alex.florisca@automattic.com>
2022-10-05 13:01:56 +01:00
Alex Florisca eace72a31f Prefix all actions in the checkout and payment-method stores with `__internal` (https://github.com/woocommerce/woocommerce-blocks/pull/7266)
* Rename setProcessingResponse to setPaymentResult and remove setOrderId from the checkout data store actions

* Fix accidentally changing data exposed to the observers

* Rename all checkout actions with the __internal prefix

* Prefix all payment method data store actions with __internal

* Pedantic spacing

* Fix ts error
2022-10-05 11:04:16 +01:00
Hsing-yu Flowers cad30afc79 Fix use of sanitizeHTML (https://github.com/woocommerce/woocommerce-blocks/pull/7231)
* Remove object from sanitizeHTML return value

* Import sanitizeHTML from utils

* Fix dangerously set inner HTML format

* Update package-lock

* Update package-lock

* Update package-lock

* Update @types/dompurify version

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>
2022-10-05 02:59:38 -07:00
Alex Florisca ce68c6ef40 Return 424 instead of 400 when checkout payment fails (https://github.com/woocommerce/woocommerce-blocks/pull/7273)
* Return 424 instead of 400 when checkout payment fails

* Change status for 424 to 402
2022-10-05 10:50:05 +01:00
Thomas Roberts 2e13856173 Add `showRemoveItemLink` filter to `CartLineItemRow` (https://github.com/woocommerce/woocommerce-blocks/pull/7242)
* Add showRemoveItemLink filter

This is a filter that will allow developers to set whether the link to remove a cartItem is visible

* Add test for showRemoveItemLink filter

* Remove unnecessary quantity override

* Move definition of cart to avoid hardcoding id value in filter

* Updated documentation for `showRemoveItemLink` filter

* available-filters.md tweak

* available-filters.md tweak

* Add example to filters for showRemoveItemLink

* Remove whitespace

Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com>
Co-authored-by: Niels Lange <info@nielslange.de>
2022-10-04 13:51:07 +01:00
Niels Lange dcde8dee05 Adjust Cart inner block titles (https://github.com/woocommerce/woocommerce-blocks/pull/7232) 2022-10-04 09:22:32 +07:00
Daniel W. Robert 3cfc4ec44c Minor Refactor to Prod Image Backend Render Functions (https://github.com/woocommerce/woocommerce-blocks/pull/7247)
* Refactor Product Image anchor render function.

Move closing tag for the anchor into the render function and pass badge
and image output into anchor children as args.

Also removes duplicate border radius logic from anchor render function,
as it is already present on the class render method.

* Clean up sprintf args.

* Replace deprecated placeholder function.

The `woocommerce_placeholder_img_src` function has been depricated since
v3.0. This replaces that function with the `wc_placeholder_img_src`
function.
2022-10-03 19:48:51 -04:00
Mike Jolley 6f93c5cf1b Store API - Cart JWT tokens/session handling (https://github.com/woocommerce/woocommerce-blocks/pull/5953)
* Re-apply token support

* Updated nonce headers

* Updated package-lock.json

* test commit to debug failing git hooks

* Revert "test commit to debug failing git hooks"

This reverts commit e64086b0a7aede154705be09c7b3433b08bc1e34.

* JsonWebToken utility class for generating and validating HS256 JWT tokens. Removed third-party JWT library.

* Add ext-hash to composer (required by hash_hmac())

* Removed unnecessary method param.

* Tests for retrieving cart contents via Cart-Token

* Removed token tests ( we can't properly test cart token functionality until we refactor the way it intercepts calls to replace the session object )

* Abstracted payload from JsonWebToken class. We can now use it to encode custom payloads and reuse them wherever we want.

* Fixed missing check for token expiration in the payload.

* MD lint error and config fix

* Update composer.lock

* Fixed bug using the wrong nonce header.

* Refactor to properly save session data based on cart token.

* Refactored DB queries to properly use prepared statement

* Removed underscore prefix for class attributes

* Fixed spaces instead of tabs indenting composer.json. Cleaned up .editorconfig

* Cleaned up borked .md comments.

* Comment for WP_SETUP_CONFIG check.

* Reverted SQL prepared statement for including table names.

* Used hash_equals() for signature comparison. Renamed some wrongly named properties.

* Updated composer.lock

* Reverted some accidentally removed lines on some documentation files.

* Reverted accidentally removed line on docs/internal-developers/testing/releases/404.md

* Changed param type from mixed to

Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com>
Co-authored-by: Seghir Nadir <nadir.seghir@gmail.com>
2022-10-03 11:49:32 +01:00
Alex Florisca 33910f316f Document the actions in the checkout and payment-method stores (https://github.com/woocommerce/woocommerce-blocks/pull/7255)
* Remove setPristine as it's not used

* Comment checkout actions

* Rename setProcessingResponse to setPaymentResult and remove setOrderId from the checkout data store actions

* Add comments to payment actions

* Update documentation with data stores

* Fix accidentally changing data exposed to the observers

* Document missing parameters for actions
2022-09-30 15:34:14 +01:00
Mik 6d5f4dbe7a Support a GT tracking ID (https://github.com/woocommerce/woocommerce-blocks/pull/7213) 2022-09-30 06:54:20 +01:00
Alex Florisca 4a82b73baf Fix failing filter test (https://github.com/woocommerce/woocommerce-blocks/pull/7253) 2022-09-30 08:38:34 +07:00
Niels Lange c360c5654a Add filter for place order button label (https://github.com/woocommerce/woocommerce-blocks/pull/7154)
* WIP add filter for place order button label

* Solve TS issue

* Add display priority

* Refactor display priority

* WIP Implement useMemo()

* Try using a global cache

* Add docs for placeOrderLabel filter

* Update docs/third-party-developers/extensibility/checkout-block/available-filters.md

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>

* Adjust docs

* Rename “placeOrderLabel” to “placeOrderButtonLabel”

* Update assets/js/types/type-defs/payments.ts

Co-authored-by: Alex Florisca <alex.florisca@automattic.com>

Co-authored-by: Nadir Seghir <nadir.seghir@gmail.com>
Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>
Co-authored-by: Alex Florisca <alex.florisca@automattic.com>
Co-authored-by: Lucio Giannotta <lucio.giannotta@a8c.com>
2022-09-29 15:46:10 +07:00
Daniel Dudzic 8ae19b5a42 Add a Products by Rating filter block (https://github.com/woocommerce/woocommerce-blocks/pull/7048)
* Add interactivity to the Product by Rating filter block

* Fix block with the latest repo changes

* Product by Rating: Code tidying up

* Add an experimental build gate and update block title and description

* Remove redundant title and description

* Add support for the CheckboxList component in the Products by Rating block

* Products by Rating: Minor code clean-up

* Active Filters: Fix the Clear All button for Ratings. Closes #woocommerce/woocommerce-blocks#7172

* Products by Rating: Add misc TS fixes
2022-09-28 23:12:14 +02:00
Luigi Teschio 790dbd3765 Remove qm/debug action (https://github.com/woocommerce/woocommerce-blocks/pull/7240)
Remove qm/debug action
2022-09-28 15:58:07 +02:00
Luigi Teschio 222407cb93 [Product Query] Add support for the Filter By Price Block (https://github.com/woocommerce/woocommerce-blocks/pull/7162)
* Product Query: Fix pagination issue

* Product Query - Add support for the Filter By Price Block woocommerce/woocommerce-blocks#6790

Product Query - Add support for the Filter By Price Block

* fix query relation

* fix on sale query

* fix bugged pagination and on-sale filter after refactor

* fix reload page when the Filter By Price block is used with All Products block

* use array_intersect instead of array_merge
2022-09-28 15:44:20 +02:00
Alex Florisca a97cd87ba1 Rebuild package-lock 2022-09-28 13:45:42 +01:00
Niels Lange 0e1eb2d597 Document the selectors for the wc/store/checkout data store (https://github.com/woocommerce/woocommerce-blocks/pull/7085) 2022-09-28 13:45:42 +01:00
Alex Florisca 9e2d7963ce Tests for the Checkout data store (https://github.com/woocommerce/woocommerce-blocks/pull/7044) 2022-09-28 13:45:42 +01:00
Thomas Roberts 65c0bfc0df Refactor `getValidationError` and `getValidationErrorId` selectors in `wc/store/validation` data store (https://github.com/woocommerce/woocommerce-blocks/pull/7146)
* Convert checkout context to data store - part 1 (https://github.com/woocommerce/woocommerce-blocks/pull/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 <5656702+opr@users.noreply.github.com>

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

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>

* Update docs

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

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>

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

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>

* 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 <5656702+opr@users.noreply.github.com>

* Move checkout state code into thunks and rename `CheckoutState` context to `CheckoutEvents` (https://github.com/woocommerce/woocommerce-blocks/pull/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 059533da4eb34f9982f66cd4adacc7b2c24f939f.

* 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` (https://github.com/woocommerce/woocommerce-blocks/pull/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 4479a2ef5599d9c8d99c3629616b3d662210fc08.

* 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 <thomas.roberts@automattic.com>
Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>

* 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 <alex.florisca@automattic.com>
Co-authored-by: Niels Lange <info@nielslange.de>
2022-09-28 13:45:42 +01:00
Thomas Roberts 512aa911f3 Fix failing express payment method unit test (https://github.com/woocommerce/woocommerce-blocks/pull/7165) 2022-09-28 13:45:42 +01:00
Alex Florisca 37d6802252 Remove unused properties from store select 2022-09-28 13:45:42 +01:00
Alex Florisca 080cdbeac2 Fix bug where active payment methods were checked too early 2022-09-28 13:45:42 +01:00
Alex Florisca dfe5151f7f Fix payment status being set to pristine not working correctly 2022-09-28 13:45:42 +01:00
Thomas Roberts dcffe242dd Fix docs linting errors 2022-09-28 13:45:42 +01:00
Alex Florisca 4ac0806990 Update assets/js/blocks/cart-checkout-shared/payment-methods/payment-method-card.js
Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>
2022-09-28 13:45:42 +01:00
Thomas Roberts 53650ff6ba Only allow payment methods to show that are in availablePaymentMethods 2022-09-28 13:45:42 +01:00
Thomas Roberts 3a49e0bd57 Revert "Include @wordpress/redux-routine in transformIgnorePatterns jest config"
This reverts commit 6b132358327ce9a36289e9f27defe7e28caee94a.
2022-09-28 13:45:42 +01:00
Alex Florisca ef1dc66068 Remove all traces of Notification Context 2022-09-28 13:45:42 +01:00
Thomas Roberts 1d78f097cb Remove missing import 2022-09-28 13:45:42 +01:00
Alex Florisca b927fcfe80 Remove Notices context 2022-09-28 13:45:42 +01:00
Thomas Roberts 28659ee653 Refactor registration of payment methods and update unit tests for payment data store (https://github.com/woocommerce/woocommerce-blocks/pull/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 <saad.trh@gmail.com>
2022-09-28 13:45:42 +01:00
Thomas Roberts aa9fd66e8e Fix lint errors 2022-09-28 13:45:42 +01:00
Alex Florisca d13d5b3fdd Feature: Data Store Migration - Payments (https://github.com/woocommerce/woocommerce-blocks/pull/6619)
* Move paymentMethodDataProvider into a data store (https://github.com/woocommerce/woocommerce-blocks/pull/6208)

* Fix typographical error on LegacyRegisterExpressPaymentMethodFunction type

* Add default state for PaymentMethod data store

* Add preliminary action types

* Add preliminary action dispatchers

* Create payment method data store

* Add preliminary reducers for payment method data store

* Add preliminary selectors for payment method data store

* Add reducers/actions for registering payment methods

* Export payment method data store key

* Add test for payment method data reducers

* Add shouldSavePaymentMethod selector

* Add store key as constant

* Add more action types for registering and initializing payment methods

* Get active payment method from data store instead of from context

* Add registered methods to default state of payment method data store

* Dispatch name of registered payment method to payment method data store

* Remove setShouldSavePayment from payment method dispatcher and types

* Get payment methods from registry instead of payment context

* Add available payment methods to store

* Add function to check whether payment methods are allowed to be used

* Add selector to check if payments are initialised

* Remove resolvers and add controls to payment method data store

* Change type of payment requirements to string[]

* Turn addRegistered and addRegisteredExpress into generators

This is so we can check each payment method's validity before adding it to the list of available payment methods

* Add action type for setting express payments as initialized

* Only select from available methods in payment method options

* Remove argument from addRegisteredPaymentMethod in payment method registry

* Rename folder and store name to not contain the word data

* Add selectors for express payment methods and their initialisation

* Delete controls again in favour of thunks

* Rename payment-method-data to payment-methdods

* Create new setDefaultPaymentMethod function

This will set the payment method when the cart loads.

* Add CustomerPaymentMethodConfiguration type

* Make getAvailableExpressPaymentMethods return correct data

* Check express methods and normal methods when cart changes

* Add action for setting active express payment methods

* Handle express methods in checkPaymentMethodCanPay

* Hide express payments area if none are available

* Add selector for paymentMethodData

* Add customer data to default state and add selector for it

* Add setPaymentStatus action and reducer case

* Set the default payment method when one isn't selected

* Correct types on getCustomerPaymentMethods

* Set status in data store alongside context status

* Comment out active gateway selection - remove later

* Set status in express payment methods in data store

* Use correct key in payment method data context

* Directly check payment methods from the list in blocks-registry

* Add semicolon to import statement

* Fix payment method data state call

* Get paymentMethodData from store not context

* Fix linting issues

Co-authored-by: Saad Tarhi <saad.trh@gmail.com>
Co-authored-by: Alex Florisca <alex.florisca@automattic.com>

* Rebase on the update/checkout-data-store branch & Fix failed payments (https://github.com/woocommerce/woocommerce-blocks/pull/6587)

* 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 <5656702+opr@users.noreply.github.com>

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

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>

* Update docs

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

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>

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

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>

* Revert feedback changes

* REvert feedback formatting

* Update docs formatting

* Fix typographical error on LegacyRegisterExpressPaymentMethodFunction type

* Add default state for PaymentMethod data store

* Add preliminary action types

* Add preliminary action dispatchers

* Create payment method data store

* Add preliminary reducers for payment method data store

* Add preliminary selectors for payment method data store

* Add reducers/actions for registering payment methods

* Export payment method data store key

* Add test for payment method data reducers

* Add shouldSavePaymentMethod selector

* Add store key as constant

* Add more action types for registering and initializing payment methods

* Get active payment method from data store instead of from context

* Add registered methods to default state of payment method data store

* Dispatch name of registered payment method to payment method data store

* Remove setShouldSavePayment from payment method dispatcher and types

* Get payment methods from registry instead of payment context

* Add available payment methods to store

* Add function to check whether payment methods are allowed to be used

* Add selector to check if payments are initialised

* Remove resolvers and add controls to payment method data store

* Change type of payment requirements to string[]

* Turn addRegistered and addRegisteredExpress into generators

This is so we can check each payment method's validity before adding it to the list of available payment methods

* Add action type for setting express payments as initialized

* Only select from available methods in payment method options

* Remove argument from addRegisteredPaymentMethod in payment method registry

* Rename folder and store name to not contain the word data

* Add selectors for express payment methods and their initialisation

* Delete controls again in favour of thunks

* Rename payment-method-data to payment-methdods

* Create new setDefaultPaymentMethod function

This will set the payment method when the cart loads.

* Add CustomerPaymentMethodConfiguration type

* Make getAvailableExpressPaymentMethods return correct data

* Check express methods and normal methods when cart changes

* Add action for setting active express payment methods

* Handle express methods in checkPaymentMethodCanPay

* Hide express payments area if none are available

* Add selector for paymentMethodData

* Add customer data to default state and add selector for it

* Add setPaymentStatus action and reducer case

* Set the default payment method when one isn't selected

* Correct types on getCustomerPaymentMethods

* Set status in data store alongside context status

* Comment out active gateway selection - remove later

* Set status in express payment methods in data store

* Directly check payment methods from the list in blocks-registry

* Add semicolon to import statement

* Fix payment method data state call

* Get paymentMethodData from store not context

* Add addPaymentMethodData action/reducer case

* Update payment method on payment success

* Add 'getCurrentStatus' selector

* Remove the temporary solution

For getting payment method data into the data store

* Prevent the 'success' context action from being dispatched

* Update the "setPaymentStatus" data store action

Accept status as an object instead of string

* Fix the "currentStatus" reducer state update value

* Get payment data into data store

* Set the correct payment status to data store

* Get the success status of payment from data store

* Use store data in the payment dispatchers

Replace the React useReducers action in the payment dispatchers file with
the payment method data store

* Get payment status from data store

* Use data store for the payment error status

* Use payment data store failed status

* Use payment data store for the isFinished status

Co-authored-by: Alex Florisca <alex.florisca@automattic.com>
Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>
Co-authored-by: Thomas Roberts <thomas.roberts@automattic.com>

* Fix merge conflict error

* Set & get the provider's state from our data store instead of React's useReducer (https://github.com/woocommerce/woocommerce-blocks/pull/6588)

* 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 <5656702+opr@users.noreply.github.com>

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

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>

* Update docs

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

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>

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

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>

* Revert feedback changes

* REvert feedback formatting

* Update docs formatting

* Fix typographical error on LegacyRegisterExpressPaymentMethodFunction type

* Add default state for PaymentMethod data store

* Add preliminary action types

* Add preliminary action dispatchers

* Create payment method data store

* Add preliminary reducers for payment method data store

* Add preliminary selectors for payment method data store

* Add reducers/actions for registering payment methods

* Export payment method data store key

* Add test for payment method data reducers

* Add shouldSavePaymentMethod selector

* Add store key as constant

* Add more action types for registering and initializing payment methods

* Get active payment method from data store instead of from context

* Add registered methods to default state of payment method data store

* Dispatch name of registered payment method to payment method data store

* Remove setShouldSavePayment from payment method dispatcher and types

* Get payment methods from registry instead of payment context

* Add available payment methods to store

* Add function to check whether payment methods are allowed to be used

* Add selector to check if payments are initialised

* Remove resolvers and add controls to payment method data store

* Change type of payment requirements to string[]

* Turn addRegistered and addRegisteredExpress into generators

This is so we can check each payment method's validity before adding it to the list of available payment methods

* Add action type for setting express payments as initialized

* Only select from available methods in payment method options

* Remove argument from addRegisteredPaymentMethod in payment method registry

* Rename folder and store name to not contain the word data

* Add selectors for express payment methods and their initialisation

* Delete controls again in favour of thunks

* Rename payment-method-data to payment-methdods

* Create new setDefaultPaymentMethod function

This will set the payment method when the cart loads.

* Add CustomerPaymentMethodConfiguration type

* Make getAvailableExpressPaymentMethods return correct data

* Check express methods and normal methods when cart changes

* Add action for setting active express payment methods

* Handle express methods in checkPaymentMethodCanPay

* Hide express payments area if none are available

* Add selector for paymentMethodData

* Add customer data to default state and add selector for it

* Add setPaymentStatus action and reducer case

* Set the default payment method when one isn't selected

* Correct types on getCustomerPaymentMethods

* Set status in data store alongside context status

* Comment out active gateway selection - remove later

* Set status in express payment methods in data store

* Directly check payment methods from the list in blocks-registry

* Add semicolon to import statement

* Fix payment method data state call

* Get paymentMethodData from store not context

* Add addPaymentMethodData action/reducer case

* Update payment method on payment success

* Add 'getCurrentStatus' selector

* Remove the temporary solution

For getting payment method data into the data store

* Prevent the 'success' context action from being dispatched

* Update the "setPaymentStatus" data store action

Accept status as an object instead of string

* Fix the "currentStatus" reducer state update value

* Get payment data into data store

* Set the correct payment status to data store

* Get the success status of payment from data store

* Use store data in the payment dispatchers

Replace the React useReducers action in the payment dispatchers file with
the payment method data store

* Get payment status from data store

* Use data store for the payment error status

* Use payment data store failed status

* Use payment data store for the isFinished status

* Update the setPaymentStatus argument

* Set up setRegisteredPaymentMethods in data store

* Use the data store version of the registeredPaymentMethods

* Fix the default state type of the registeredPaymentMethods

* Set up setRegisteredExpressPaymentMethod in data store

* Use the data version of the registred express payment methods

* Set the correct action type for removing payment methods

* Fix default state express payment methods type

* Use the store data version of activePaymentMethod

* Use setActivePaymentMethod in the dispatchers file

And refactor code

* Update payment status arguments for express payment methods

* Use paymentMethodData from the data store

* Use payment method's errorMessage from data store

* Update paymentMethods list in data store reducer

* Replace remaining payment context data with data store

* Clean up payment method context file

Co-authored-by: Alex Florisca <alex.florisca@automattic.com>
Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>
Co-authored-by: Thomas Roberts <thomas.roberts@automattic.com>

* Get payment method data directly from the data store instead of the usePaymentMethodDataContext hook (https://github.com/woocommerce/woocommerce-blocks/pull/6589)

* 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 <5656702+opr@users.noreply.github.com>

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

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>

* Update docs

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

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>

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

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>

* Revert feedback changes

* REvert feedback formatting

* Update docs formatting

* Fix typographical error on LegacyRegisterExpressPaymentMethodFunction type

* Add default state for PaymentMethod data store

* Add preliminary action types

* Add preliminary action dispatchers

* Create payment method data store

* Add preliminary reducers for payment method data store

* Add preliminary selectors for payment method data store

* Add reducers/actions for registering payment methods

* Export payment method data store key

* Add test for payment method data reducers

* Add shouldSavePaymentMethod selector

* Add store key as constant

* Add more action types for registering and initializing payment methods

* Get active payment method from data store instead of from context

* Add registered methods to default state of payment method data store

* Dispatch name of registered payment method to payment method data store

* Remove setShouldSavePayment from payment method dispatcher and types

* Get payment methods from registry instead of payment context

* Add available payment methods to store

* Add function to check whether payment methods are allowed to be used

* Add selector to check if payments are initialised

* Remove resolvers and add controls to payment method data store

* Change type of payment requirements to string[]

* Turn addRegistered and addRegisteredExpress into generators

This is so we can check each payment method's validity before adding it to the list of available payment methods

* Add action type for setting express payments as initialized

* Only select from available methods in payment method options

* Remove argument from addRegisteredPaymentMethod in payment method registry

* Rename folder and store name to not contain the word data

* Add selectors for express payment methods and their initialisation

* Delete controls again in favour of thunks

* Rename payment-method-data to payment-methdods

* Create new setDefaultPaymentMethod function

This will set the payment method when the cart loads.

* Add CustomerPaymentMethodConfiguration type

* Make getAvailableExpressPaymentMethods return correct data

* Check express methods and normal methods when cart changes

* Add action for setting active express payment methods

* Handle express methods in checkPaymentMethodCanPay

* Hide express payments area if none are available

* Add selector for paymentMethodData

* Add customer data to default state and add selector for it

* Add setPaymentStatus action and reducer case

* Set the default payment method when one isn't selected

* Correct types on getCustomerPaymentMethods

* Set status in data store alongside context status

* Comment out active gateway selection - remove later

* Set status in express payment methods in data store

* Directly check payment methods from the list in blocks-registry

* Add semicolon to import statement

* Fix payment method data state call

* Get paymentMethodData from store not context

* Add addPaymentMethodData action/reducer case

* Update payment method on payment success

* Add 'getCurrentStatus' selector

* Remove the temporary solution

For getting payment method data into the data store

* Prevent the 'success' context action from being dispatched

* Update the "setPaymentStatus" data store action

Accept status as an object instead of string

* Fix the "currentStatus" reducer state update value

* Get payment data into data store

* Set the correct payment status to data store

* Get the success status of payment from data store

* Use store data in the payment dispatchers

Replace the React useReducers action in the payment dispatchers file with
the payment method data store

* Get payment status from data store

* Use data store for the payment error status

* Use payment data store failed status

* Use payment data store for the isFinished status

* Update the setPaymentStatus argument

* Set up setRegisteredPaymentMethods in data store

* Use the data store version of the registeredPaymentMethods

* Fix the default state type of the registeredPaymentMethods

* Set up setRegisteredExpressPaymentMethod in data store

* Use the data version of the registred express payment methods

* Set the correct action type for removing payment methods

* Fix default state express payment methods type

* Use the store data version of activePaymentMethod

* Use setActivePaymentMethod in the dispatchers file

And refactor code

* Update payment status arguments for express payment methods

* Use paymentMethodData from the data store

* Use payment method's errorMessage from data store

* Update paymentMethods list in data store reducer

* Replace remaining payment context data with data store

* Clean up payment method context file

* Get payment method state from data store in the checkout submit hook

* Copy types.ts file into the payment data store folder

* Fix isExpressPaymentMethodActive selector

* Move the entire currentStatus into the data store

* Replace the payment context state with the data store

* Fix getActiveSavedToken & clean up the context file

* Use the accutrate name of the "createErrorNotice"

* Update the payment method data store key import

* Diable unused state from the context

Co-authored-by: Alex Florisca <alex.florisca@automattic.com>
Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>
Co-authored-by: Thomas Roberts <thomas.roberts@automattic.com>

* Refactor the payment method data store & context (https://github.com/woocommerce/woocommerce-blocks/pull/6607)

* 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 <5656702+opr@users.noreply.github.com>

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

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>

* Update docs

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

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>

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

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>

* Revert feedback changes

* REvert feedback formatting

* Update docs formatting

* Fix typographical error on LegacyRegisterExpressPaymentMethodFunction type

* Add default state for PaymentMethod data store

* Add preliminary action types

* Add preliminary action dispatchers

* Create payment method data store

* Add preliminary reducers for payment method data store

* Add preliminary selectors for payment method data store

* Add reducers/actions for registering payment methods

* Export payment method data store key

* Add test for payment method data reducers

* Add shouldSavePaymentMethod selector

* Add store key as constant

* Add more action types for registering and initializing payment methods

* Get active payment method from data store instead of from context

* Add registered methods to default state of payment method data store

* Dispatch name of registered payment method to payment method data store

* Remove setShouldSavePayment from payment method dispatcher and types

* Get payment methods from registry instead of payment context

* Add available payment methods to store

* Add function to check whether payment methods are allowed to be used

* Add selector to check if payments are initialised

* Remove resolvers and add controls to payment method data store

* Change type of payment requirements to string[]

* Turn addRegistered and addRegisteredExpress into generators

This is so we can check each payment method's validity before adding it to the list of available payment methods

* Add action type for setting express payments as initialized

* Only select from available methods in payment method options

* Remove argument from addRegisteredPaymentMethod in payment method registry

* Rename folder and store name to not contain the word data

* Add selectors for express payment methods and their initialisation

* Delete controls again in favour of thunks

* Rename payment-method-data to payment-methdods

* Create new setDefaultPaymentMethod function

This will set the payment method when the cart loads.

* Add CustomerPaymentMethodConfiguration type

* Make getAvailableExpressPaymentMethods return correct data

* Check express methods and normal methods when cart changes

* Add action for setting active express payment methods

* Handle express methods in checkPaymentMethodCanPay

* Hide express payments area if none are available

* Add selector for paymentMethodData

* Add customer data to default state and add selector for it

* Add setPaymentStatus action and reducer case

* Set the default payment method when one isn't selected

* Correct types on getCustomerPaymentMethods

* Set status in data store alongside context status

* Comment out active gateway selection - remove later

* Set status in express payment methods in data store

* Directly check payment methods from the list in blocks-registry

* Add semicolon to import statement

* Fix payment method data state call

* Get paymentMethodData from store not context

* Add addPaymentMethodData action/reducer case

* Update payment method on payment success

* Add 'getCurrentStatus' selector

* Remove the temporary solution

For getting payment method data into the data store

* Prevent the 'success' context action from being dispatched

* Update the "setPaymentStatus" data store action

Accept status as an object instead of string

* Fix the "currentStatus" reducer state update value

* Get payment data into data store

* Set the correct payment status to data store

* Get the success status of payment from data store

* Use store data in the payment dispatchers

Replace the React useReducers action in the payment dispatchers file with
the payment method data store

* Get payment status from data store

* Use data store for the payment error status

* Use payment data store failed status

* Use payment data store for the isFinished status

* Update the setPaymentStatus argument

* Set up setRegisteredPaymentMethods in data store

* Use the data store version of the registeredPaymentMethods

* Fix the default state type of the registeredPaymentMethods

* Set up setRegisteredExpressPaymentMethod in data store

* Use the data version of the registred express payment methods

* Set the correct action type for removing payment methods

* Fix default state express payment methods type

* Use the store data version of activePaymentMethod

* Use setActivePaymentMethod in the dispatchers file

And refactor code

* Update payment status arguments for express payment methods

* Use paymentMethodData from the data store

* Use payment method's errorMessage from data store

* Update paymentMethods list in data store reducer

* Replace remaining payment context data with data store

* Clean up payment method context file

* Get payment method state from data store in the checkout submit hook

* Copy types.ts file into the payment data store folder

* Fix isExpressPaymentMethodActive selector

* Move the entire currentStatus into the data store

* Replace the payment context state with the data store

* Fix getActiveSavedToken & clean up the context file

* Use the accutrate name of the "createErrorNotice"

* Update the payment method data store key import

* Diable unused state from the context

* Get enabled customer payment methods using data store selector

* Remove remaining useReducer action from the dispatchers file

* Update types and remove unused vars

* Remove the payment method dispatchers hook

* Refactor & clean up (remove unused files)

* Remove commented line from payment methods types

* Move event emitter into thunks

Co-authored-by: Alex Florisca <alex.florisca@automattic.com>
Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>
Co-authored-by: Thomas Roberts <thomas.roberts@automattic.com>

* Remove checkout-state after merge conflicts

* Fix linting errors

* Move types to types.ts

* Move default states into respective store folders

* Fix types and add comment

* Move setExpressPaymentError to payment-methods store

* fix express payment methods not showing up

* Check if payment method is active from the state

* Add comments

* Remove commented out code in payment method data context

* Display an error in the check-payment-methods directly from data store

* Remove use-emit-response hook and move utils in event-emit/utils.ts

* Use correct action property to remove payment methods

* Fix formatting

* Only try to initialize payment methods when cart is done loading

* Add function to order payment methods from server

* Add payment methods in the correct order

* Prevent adding registered payment methods before cart is ready

* Ensure payment methods get removed from state when deregistered

* Reorder setting default payment methods to add customer methods first

* Get customer methods from store not context

* Remove error from payment-method state and associated selectors

* Remove use-payment-method-registration and update the payment method state to remove the duplicated registeredPaymentMethods

* Remove errorMessage from payment-methods store

* Rename customerPaymentMethods -> savedPaymentMethods

* Order payment methods when validating

* Refactor payment-methods.js

* Fix "Payment methods not set in editor" woocommerce/woocommerce-blocks#6655 bug

We never get to load the payment methods object in the editor mode
because there are no cart totals to load.

* Initialize payment methods when available payments are loaded

* Remove duplicate code

* Fix data store state mutation anti-pattern

A Redux rule is to never mutate the state in a reducer to avoid any unexpected results

* Set availablePaymentMethods to the paymentMethods object

Instead of its keys. We can get the keys using "Object.keys".

* Use the available ordered payment methods

The `getPaymentMethods` & `getExpressPaymentMethods` may include unordored
& unavailable payment methods.

* Get the correct value from the emit event response

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>
Co-authored-by: Saad Tarhi <saad.trh@gmail.com>
Co-authored-by: Thomas Roberts <thomas.roberts@automattic.com>
2022-09-28 13:45:42 +01:00
Tarun Vijwani 4de3bdb0f1 Convert validation context to data store (https://github.com/woocommerce/woocommerce-blocks/pull/6402)
* Add validation reducers, actions, and action types

* Add selector for getValidationErrors

* Export store key and register store

* Export validation store key

* Move TextInput files to checkout package

* Export ValidatedTextInput from blocks-checkout package

* Update imports of ValidatedTextInput to reflect new location

* Use the validation wp-data store for showing error messages

* Export getValidationError in checkout package

* Move validation store to checkout package

* Move ValidationInputError to blocks-checkout package

* Only export "exposedSelectors" from validation

* Convert validation context to data store

* Fixed linting error

* Fixed linting error

* Change the validation selectors to return a function

* Convert reducer and selectors to TS

* Remove superfluous comments and improve test titles

* Test to ensure visible errors remain visible

* Make test for hasValidationErrors more robust

* Augment the wp-data module to include our selectors and actions

* Removed unused `exposedSelectors` variable

* Remove TS error because of `instanceId` on props

* Remove unnecessary as const

* Use function returned by getValidationError

* Use correct selector/action names now context has been decoupled

* hide validation error when input value changes

* Add correct aria-describedBy now we can get error id from store

* Clear validation error from store when component unmounts

* Clear validation error if input is valid

* convert ValidationInputError to TS and get correct id/error from store

* Ensure checkout block doesn't break when there are no errors

* Get validation data from the store instead of context

* Update country input to remove validation context

* Move validation store out of checkout package

* Move TextInput and ValidationInputError back out of the checkout package

* Remove duplicate internal styles comment

* Remove exports that no longer exist

* Get validation store key from block-data

* Make attribute-select-control use validation data store

* Export FieldValidationStatus type

* Make combobox use validation store not context

* Make Address use validation store not context

* Make Address use validation store not context

* Use hasValidationErrors selector as a function in shipping calculator

* Remove validation context from coupon story

* Import VALIDATION_STORE_KEY from correct location

* Stop coupon story from erroring

* Update useStoreCartCoupons to use validation store not context

* Make TotalsCoupon use validation store instead of context

* Make AddToCartFormContext use validation store not context

* Remove ValidationContext

* Import FieldValidationStatus from correct location

* Import ValidatedTextInput and ValidatedTextInput from correct location

* Remove ValidationContextProvider

* Update components to use validation store not context

* Update useValidation to use the data store

* Replace the validation context in checkout-events file

* Use the re-mapped path for the store key import

* Use "register" instead of the deprecated "registerStore"

* Fix import error of the "FieldValidationStatus" type

* Use TS instead of React's "PropTypes"

* Fix the type of "ValidationInputError" in the "payment-method-interface"

* Fix error not showing on the first place order click bug

We were mutating the state in the reducer, which prevented re-rendering
on state change

* Fix state mutation issue in the Validation reducer

Co-authored-by: Thomas Roberts <thomas.roberts@automattic.com>
Co-authored-by: Saad Tarhi <saad.trh@gmail.com>
2022-09-28 13:45:42 +01:00
Alex Florisca 22f61cf4d9 Fixed missing lint error 2022-09-28 13:45:42 +01:00
Alex Florisca e2c495d7ac Fix lint issues 2022-09-28 13:45:42 +01:00
Alex Florisca 015291ccf3 Move checkout state code into thunks and rename `CheckoutState` context to `CheckoutEvents` (https://github.com/woocommerce/woocommerce-blocks/pull/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 059533da4eb34f9982f66cd4adacc7b2c24f939f.

* 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` (https://github.com/woocommerce/woocommerce-blocks/pull/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 4479a2ef5599d9c8d99c3629616b3d662210fc08.

* 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 <thomas.roberts@automattic.com>
Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>
2022-09-28 13:45:42 +01:00
Alex Florisca 3630b7b03e Convert checkout context to data store - part 1 (https://github.com/woocommerce/woocommerce-blocks/pull/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 <5656702+opr@users.noreply.github.com>

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

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>

* Update docs

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

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>

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

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>

* 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 <5656702+opr@users.noreply.github.com>
2022-09-28 13:45:42 +01:00
Luigi Teschio 3732363ba6 Add to the Product Button block the support for the Product Query block (https://github.com/woocommerce/woocommerce-blocks/pull/6948)
* Adds to the Product Image Block the support for the Product Query Block

Adds to the Product Image Block the support for the Product Query Block woocommerce/woocommerce-blocks#6911

* use shared config

* use shared config

* use shared config

* Add to the Product Button Block the support for the Product Query Block

* Add to the Product Image Block the support for the Product Query Block

* fix lint errors

* address feedback

* set grid view and font-size L as default
2022-09-28 10:54:38 +02:00
Lucio Giannotta 7125b08655 Bump version strings 2022-09-27 18:04:07 +02:00
github-actions[bot] 78b02ce741 Release: 8.6.0 (https://github.com/woocommerce/woocommerce-blocks/pull/7228)
Co-authored-by: Daniel W. Robert <danielwrobert@gmail.com>
Co-authored-by: github-actions <github-actions@github.com>
Co-authored-by: Lucio Giannotta <lucio.giannotta@a8c.com>
Co-authored-by: Niels Lange <info@nielslange.de>
2022-09-27 17:56:29 +02:00