2020-03-16 20:57:12 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2022-12-19 15:30:13 +00:00
|
|
|
import { useSelect } from '@wordpress/data';
|
2022-10-06 12:46:46 +00:00
|
|
|
import { PAYMENT_STORE_KEY } from '@woocommerce/block-data';
|
2022-08-22 14:07:13 +00:00
|
|
|
|
2020-03-16 20:57:12 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import './style.scss';
|
2022-12-19 15:30:13 +00:00
|
|
|
import StoreNotices from './store-notices';
|
|
|
|
import SnackbarNotices from './snackbar-notices';
|
|
|
|
import type { StoreNoticesContainerProps, StoreNotice } from './types';
|
2020-03-16 20:57:12 +00:00
|
|
|
|
2022-12-19 15:30:13 +00:00
|
|
|
const formatNotices = (
|
|
|
|
notices: StoreNotice[],
|
|
|
|
context: string
|
|
|
|
): StoreNotice[] => {
|
|
|
|
return notices.map( ( notice ) => ( {
|
|
|
|
...notice,
|
|
|
|
context,
|
|
|
|
} ) );
|
2020-03-16 20:57:12 +00:00
|
|
|
};
|
|
|
|
|
2022-12-19 15:30:13 +00:00
|
|
|
const StoreNoticesContainer = ( {
|
|
|
|
className = '',
|
|
|
|
context,
|
2022-04-08 12:11:50 +00:00
|
|
|
additionalNotices = [],
|
2022-11-17 13:33:58 +00:00
|
|
|
}: StoreNoticesContainerProps ): JSX.Element | null => {
|
2022-12-19 15:30:13 +00:00
|
|
|
const suppressNotices = useSelect( ( select ) =>
|
2022-10-06 12:46:46 +00:00
|
|
|
select( PAYMENT_STORE_KEY ).isExpressPaymentMethodActive()
|
2022-08-22 14:07:13 +00:00
|
|
|
);
|
2022-04-08 12:11:50 +00:00
|
|
|
|
2022-12-19 15:30:13 +00:00
|
|
|
const notices = useSelect< StoreNotice[] >( ( select ) => {
|
|
|
|
const { getNotices } = select( 'core/notices' );
|
|
|
|
|
|
|
|
return formatNotices(
|
|
|
|
( getNotices( context ) as StoreNotice[] ).concat(
|
|
|
|
additionalNotices
|
|
|
|
),
|
|
|
|
context
|
|
|
|
).filter( Boolean ) as StoreNotice[];
|
2022-04-08 12:11:50 +00:00
|
|
|
} );
|
2020-03-16 20:57:12 +00:00
|
|
|
|
2022-12-19 15:30:13 +00:00
|
|
|
if ( suppressNotices ) {
|
2020-03-16 20:57:12 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-12-19 15:30:13 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<StoreNotices
|
|
|
|
className={ className }
|
|
|
|
context={ context }
|
|
|
|
notices={ notices.filter(
|
|
|
|
( notice ) => notice.type === 'default'
|
|
|
|
) }
|
|
|
|
/>
|
|
|
|
<SnackbarNotices
|
|
|
|
className={ className }
|
|
|
|
notices={ notices.filter(
|
|
|
|
( notice ) => notice.type === 'snackbar'
|
|
|
|
) }
|
|
|
|
/>
|
|
|
|
</>
|
2020-03-16 20:57:12 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-09-23 18:48:28 +00:00
|
|
|
export default StoreNoticesContainer;
|