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

Commit

Permalink
support context as array in StoreNotice
Browse files Browse the repository at this point in the history
  • Loading branch information
senadir committed Feb 9, 2023
1 parent 4abc453 commit 021c521
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 22 deletions.
2 changes: 1 addition & 1 deletion assets/js/blocks/products/all-products/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Block extends Component {
parentName="woocommerce/all-products"
parentClassName="wc-block-grid"
>
<StoreNoticesContainer contexts={ [ 'wc/all-products' ] } />
<StoreNoticesContainer context={ 'wc/all-products' } />
<ProductListContainer
attributes={ attributes }
urlParameterSuffix={ urlParameterSuffix }
Expand Down
15 changes: 0 additions & 15 deletions docs/internal-developers/block-client-apis/notices.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
- [Notices in WooCommerce Blocks](#notices-in-woocommerce-blocks)
- [`StoreNoticesContainer`](#storenoticescontainer)
- [Snackbar notices in WooCommerce Blocks](#snackbar-notices-in-woocommerce-blocks)
- [`SnackbarNoticesContainer`](#snackbarnoticescontainer)

## Notices in WooCommerce Blocks

Expand Down Expand Up @@ -74,17 +73,3 @@ dispatch( 'core/notices' ).createNotice(
'snackbar-notice-id'
);
```

### `SnackbarNoticesContainer`

To display snackbar notices, use the `SnackbarNoticesContainer` component. This component is rendered with the Cart and Checkout blocks, so there is no need to add another. The context it displays notices for is `default`. If, for some reason you do need to show snackbar messages for a different context, you can render this component again and pass the context as a prop to the component.

```jsx
import { SnackbarNoticesContainer } from '@woocommerce/base-components/snackbar-notices-container';

const AlternativeSnackbarNotices = () => {
return (
<SnackbarNoticesContainer context="wc/alternative-snackbar-notices" />
);
};
```
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import { getClassNameFromStatus } from './utils';
import type { StoreNotice } from './types';

const StoreNotices = ( {
contexts,
context,
className,
notices,
}: {
contexts: string[];
context: string | string[];
className: string;
notices: StoreNotice[];
} ): JSX.Element => {
Expand Down Expand Up @@ -64,14 +64,14 @@ const StoreNotices = ( {
} );
}
}, [ noticeIds, previousNoticeIds, ref ] );

// Register the container context with the parent.
useEffect( () => {
contexts.map( ( context ) => registerContainer( context ) );
const contexts = Array.isArray( context ) ? context : [ context ];
contexts.map( ( _context ) => registerContainer( _context ) );
return () => {
contexts.map( ( context ) => unregisterContainer( context ) );
contexts.map( ( _context ) => unregisterContainer( _context ) );
};
}, [ contexts, registerContainer, unregisterContainer ] );
}, [ context, registerContainer, unregisterContainer ] );

// Group notices by whether or not they are dismissible. Dismissible notices can be grouped.
const dismissibleNotices = notices.filter(
Expand Down

0 comments on commit 021c521

Please sign in to comment.