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

Remove setCustomerId from events and processCheckoutResponseHeaders #6586

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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