/** * External dependencies */ import { __, sprintf } from '@wordpress/i18n'; import { Notice, ExternalLink, Button, TabbableContainer, Modal, } from '@wordpress/components'; import { createInterpolateElement, useEffect, useState, } from '@wordpress/element'; import { Alert } from '@woocommerce/icons'; import { Icon } from '@wordpress/icons'; import { useDispatch, useSelect } from '@wordpress/data'; import { createBlock, BlockInstance } from '@wordpress/blocks'; import { store as noticesStore } from '@wordpress/notices'; import { store as coreStore } from '@wordpress/core-data'; import { store as blockEditorStore } from '@wordpress/block-editor'; import { recordEvent } from '@woocommerce/tracks'; import { findBlock } from '@woocommerce/utils'; /** * Internal dependencies */ import { useCombinedIncompatibilityNotice } from './use-combined-incompatibility-notice'; import { ModalContent } from './modal'; import './editor.scss'; interface ExtensionNoticeProps { toggleDismissedStatus: ( status: boolean ) => void; block: 'woocommerce/cart' | 'woocommerce/checkout'; clientId: string; } /** * Shows a notice when there are incompatible extensions. * * Tracks events: * - switch_to_classic_shortcode_click * - switch_to_classic_shortcode_confirm * - switch_to_classic_shortcode_cancel * - switch_to_classic_shortcode_undo */ export function IncompatibleExtensionsNotice( { toggleDismissedStatus, block, clientId, }: ExtensionNoticeProps ) { const [ isVisible, dismissNotice, incompatiblePaymentMethods, numberOfIncompatiblePaymentMethods, ] = useCombinedIncompatibilityNotice( block ); const [ isOpen, setOpen ] = useState( false ); const openModal = () => setOpen( true ); const closeModal = () => setOpen( false ); const { createInfoNotice } = useDispatch( noticesStore ); const { replaceBlock, selectBlock } = useDispatch( blockEditorStore ); const { undo } = useDispatch( coreStore ); const { getBlocks } = useSelect( ( select ) => { return { getBlocks: select( blockEditorStore ).getBlocks, }; }, [] ); useEffect( () => { toggleDismissedStatus( ! isVisible ); }, [ isVisible, toggleDismissedStatus ] ); if ( ! isVisible ) { return null; } const switchButtonLabel = block === 'woocommerce/cart' ? __( 'Switch to classic cart', 'woo-gutenberg-products-block' ) : __( 'Switch to classic checkout', 'woo-gutenberg-products-block' ); const snackbarLabel = block === 'woocommerce/cart' ? __( 'Switched to classic cart.', 'woo-gutenberg-products-block' ) : __( 'Switched to classic checkout.', 'woo-gutenberg-products-block' ); const noticeContent = ( <> { numberOfIncompatiblePaymentMethods > 1 ? createInterpolateElement( __( 'Some active extensions do not yet support this block. This may impact the shopper experience. Learn more', 'woo-gutenberg-products-block' ), { a: ( ), } ) : createInterpolateElement( sprintf( // translators: %s is the name of the extension. __( '%s does not yet support this block. This may impact the shopper experience. Learn more', 'woo-gutenberg-products-block' ), Object.values( incompatiblePaymentMethods )[ 0 ] ), { strong: , a: ( ), } ) } ); const selectClassicShortcodeBlock = () => { const classicShortcodeBlock = findBlock( { blocks: getBlocks(), findCondition: ( foundBlock: BlockInstance ) => foundBlock.name === 'woocommerce/classic-shortcode', } ); if ( classicShortcodeBlock ) { selectBlock( classicShortcodeBlock.clientId ); } }; return (
} />

{ noticeContent }

{ numberOfIncompatiblePaymentMethods > 1 && (
    { Object.entries( incompatiblePaymentMethods ).map( ( [ id, title ] ) => (
  • { title }
  • ) ) }
) } { isOpen && ( { ' ' } ) }
); }