/** * External dependencies */ import { __ } from '@wordpress/i18n'; import { useStoreCart } from '@woocommerce/base-context/hooks'; import { useEffect } from '@wordpress/element'; import LoadingMask from '@woocommerce/base-components/loading-mask'; import { CURRENT_USER_IS_ADMIN } from '@woocommerce/settings'; import BlockErrorBoundary from '@woocommerce/base-components/block-error-boundary'; import { translateJQueryEventToNative } from '@woocommerce/base-utils'; import withScrollToTop from '@woocommerce/base-hocs/with-scroll-to-top'; import { CartEventsProvider, CartProvider, noticeContexts, } from '@woocommerce/base-context'; import { SlotFillProvider, StoreNoticesContainer, } from '@woocommerce/blocks-checkout'; /** * Internal dependencies */ import { CartBlockContext } from './context'; import './style.scss'; const reloadPage = () => void window.location.reload( true ); const Cart = ( { children, attributes = {} } ) => { const { cartIsLoading } = useStoreCart(); const { hasDarkControls } = attributes; return ( { children } ); }; const ScrollOnError = ( { scrollToTop } ) => { useEffect( () => { // Make it so we can read jQuery events triggered by WC Core elements. const removeJQueryAddedToCartEvent = translateJQueryEventToNative( 'added_to_cart', 'wc-blocks_added_to_cart' ); document.body.addEventListener( 'wc-blocks_added_to_cart', scrollToTop ); return () => { removeJQueryAddedToCartEvent(); document.body.removeEventListener( 'wc-blocks_added_to_cart', scrollToTop ); }; }, [ scrollToTop ] ); return null; }; const Block = ( { attributes, children, scrollToTop } ) => ( { __( 'Reload the page', 'woo-gutenberg-products-block' ) } } showErrorMessage={ CURRENT_USER_IS_ADMIN } > { children } ); export default withScrollToTop( Block );