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

Commit 284440a

Browse files
committed
Merge branch 'release/9.4.0' of https://github.com/woocommerce/woocommerce-blocks into release/9.4.1
2 parents 4f1be6f + d1531b2 commit 284440a

File tree

2 files changed

+22
-31
lines changed
  • assets/js/blocks
    • cart/inner-blocks/filled-cart-block
    • mini-cart/mini-cart-contents/inner-blocks/filled-mini-cart-contents-block

2 files changed

+22
-31
lines changed

assets/js/blocks/cart/inner-blocks/filled-cart-block/frontend.tsx

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { SidebarLayout } from '@woocommerce/base-components/sidebar-layout';
66
import { useStoreCart } from '@woocommerce/base-context/hooks';
77
import { useEffect } from '@wordpress/element';
88
import { decodeEntities } from '@wordpress/html-entities';
9-
import { useDispatch, useSelect } from '@wordpress/data';
9+
import { select, useDispatch } from '@wordpress/data';
1010

1111
/**
1212
* Internal dependencies
@@ -24,21 +24,19 @@ const FrontendBlock = ( {
2424
const { hasDarkControls } = useCartBlockContext();
2525
const { createErrorNotice, removeNotice } = useDispatch( 'core/notices' );
2626

27-
/*
28-
* The code for removing old notices is also present in the filled-mini-cart-contents-block/frontend.tsx file and
29-
* will take care of removing outdated errors in the Mini Cart block.
30-
*/
31-
const currentlyDisplayedErrorNoticeCodes = useSelect( ( select ) => {
32-
return select( 'core/notices' )
27+
useEffect( () => {
28+
/*
29+
* The code for removing old notices is also present in the filled-mini-cart-contents-block/frontend.tsx file and
30+
* will take care of removing outdated errors in the Mini Cart block.
31+
*/
32+
const currentlyDisplayedErrorNoticeCodes = select( 'core/notices' )
3333
.getNotices( 'wc/cart' )
3434
.filter(
3535
( notice ) =>
3636
notice.status === 'error' && notice.type === 'default'
3737
)
3838
.map( ( notice ) => notice.id );
39-
} );
4039

41-
useEffect( () => {
4240
// Clear errors out of the store before adding the new ones from the response.
4341
currentlyDisplayedErrorNoticeCodes.forEach( ( id ) => {
4442
removeNotice( id, 'wc/cart' );
@@ -52,12 +50,7 @@ const FrontendBlock = ( {
5250
context: 'wc/cart',
5351
} );
5452
} );
55-
}, [
56-
createErrorNotice,
57-
cartItemErrors,
58-
currentlyDisplayedErrorNoticeCodes,
59-
removeNotice,
60-
] );
53+
}, [ createErrorNotice, cartItemErrors, removeNotice ] );
6154

6255
if ( cartIsLoading || cartItems.length >= 1 ) {
6356
return (

assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/filled-mini-cart-contents-block/frontend.tsx

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import { StoreNoticesContainer } from '@woocommerce/blocks-checkout';
55
import { useStoreCart } from '@woocommerce/base-context/hooks';
66

7-
import { useDispatch, useSelect } from '@wordpress/data';
7+
import { select, useDispatch } from '@wordpress/data';
88
import { useEffect } from '@wordpress/element';
99
import { decodeEntities } from '@wordpress/html-entities';
1010

@@ -21,22 +21,25 @@ const FilledMiniCartContentsBlock = ( {
2121

2222
const { createErrorNotice, removeNotice } = useDispatch( 'core/notices' );
2323

24-
/*
25-
* The code for removing old notices is also present in the filled-cart-block/frontend.tsx file and will take care
26-
* of removing outdated errors in the Cart block.
27-
*/
28-
const currentlyDisplayedErrorNoticeCodes = useSelect( ( select ) => {
29-
return select( 'core/notices' )
24+
// Ensures any cart errors listed in the API response get shown.
25+
useEffect( () => {
26+
/*
27+
* The code for removing old notices is also present in the filled-mini-cart-contents-block/frontend.tsx file and
28+
* will take care of removing outdated errors in the Mini Cart block.
29+
*/
30+
const currentlyDisplayedErrorNoticeCodes = select( 'core/notices' )
3031
.getNotices( 'wc/cart' )
3132
.filter(
3233
( notice ) =>
3334
notice.status === 'error' && notice.type === 'default'
3435
)
3536
.map( ( notice ) => notice.id );
36-
} );
3737

38-
// Ensures any cart errors listed in the API response get shown.
39-
useEffect( () => {
38+
// Clear errors out of the store before adding the new ones from the response.
39+
currentlyDisplayedErrorNoticeCodes.forEach( ( id ) => {
40+
removeNotice( id, 'wc/cart' );
41+
} );
42+
4043
// Clear errors out of the store before adding the new ones from the response.
4144
currentlyDisplayedErrorNoticeCodes.forEach( ( id ) => {
4245
removeNotice( id, 'wc/cart' );
@@ -49,12 +52,7 @@ const FilledMiniCartContentsBlock = ( {
4952
context: 'wc/cart',
5053
} );
5154
} );
52-
}, [
53-
createErrorNotice,
54-
cartItemErrors,
55-
currentlyDisplayedErrorNoticeCodes,
56-
removeNotice,
57-
] );
55+
}, [ createErrorNotice, cartItemErrors, removeNotice ] );
5856

5957
if ( cartItems.length === 0 ) {
6058
return null;

0 commit comments

Comments
 (0)