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

Commit

Permalink
Remove setCustomerId from events and `processCheckoutResponseHeader…
Browse files Browse the repository at this point in the history
…s` (#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
  • Loading branch information
opr authored Jun 20, 2022
1 parent 9d38786 commit bf4c03c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const CheckoutProcessor = () => {
};
} );

const { setCustomerId, setHasError, processCheckoutResponse } = useDispatch(
const { setHasError, processCheckoutResponse } = useDispatch(
CHECKOUT_STORE_KEY
);

Expand Down Expand Up @@ -226,10 +226,7 @@ const CheckoutProcessor = () => {
parse: false,
} )
.then( ( response ) => {
processCheckoutResponseHeaders(
response.headers,
setCustomerId
);
processCheckoutResponseHeaders( response.headers );
if ( ! response.ok ) {
throw new Error( response );
}
Expand All @@ -242,10 +239,7 @@ const CheckoutProcessor = () => {
.catch( ( errorResponse ) => {
try {
if ( errorResponse?.headers ) {
processCheckoutResponseHeaders(
errorResponse.headers,
setCustomerId
);
processCheckoutResponseHeaders( errorResponse.headers );
}
// This attempts to parse a JSON error response where the status code was 4xx/5xx.
errorResponse.json().then( ( response ) => {
Expand Down Expand Up @@ -309,7 +303,6 @@ const CheckoutProcessor = () => {
receiveCart,
setHasError,
processCheckoutResponse,
setCustomerId,
] );

// Process order if conditions are good.
Expand Down
13 changes: 4 additions & 9 deletions assets/js/base/context/providers/cart-checkout/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
* External dependencies
*/
import triggerFetch from '@wordpress/api-fetch';

/**
* Internal dependencies
*/
import type { setCustomerId as setCheckoutCustomerId } from '../../../../data/checkout/actions';
import { dispatch } from '@wordpress/data';
import { CHECKOUT_STORE_KEY } from '@woocommerce/block-data';

/**
* Utility function for preparing payment data for the request.
Expand Down Expand Up @@ -34,10 +31,8 @@ export const preparePaymentData = (
/**
* Process headers from an API response an dispatch updates.
*/
export const processCheckoutResponseHeaders = (
headers: Headers,
setCustomerId: typeof setCheckoutCustomerId
): void => {
export const processCheckoutResponseHeaders = ( headers: Headers ): void => {
const { setCustomerId } = dispatch( CHECKOUT_STORE_KEY );
if (
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore -- this does exist because it's monkey patched in
Expand Down

0 comments on commit bf4c03c

Please sign in to comment.