2022-12-28 16:30:46 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { _n } from '@wordpress/i18n';
|
|
|
|
import { Notice, ExternalLink } from '@wordpress/components';
|
2023-02-24 10:57:24 +00:00
|
|
|
import { createInterpolateElement, useEffect } from '@wordpress/element';
|
2023-02-07 07:06:05 +00:00
|
|
|
import { Alert } from '@woocommerce/icons';
|
2022-12-28 16:30:46 +00:00
|
|
|
import { Icon } from '@wordpress/icons';
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2023-02-24 10:57:24 +00:00
|
|
|
import { useIncompatiblePaymentGatewaysNotice } from './use-incompatible-payment-gateways-notice';
|
2022-12-28 16:30:46 +00:00
|
|
|
import './editor.scss';
|
|
|
|
|
|
|
|
interface PaymentGatewaysNoticeProps {
|
|
|
|
toggleDismissedStatus: ( status: boolean ) => void;
|
2023-02-24 10:57:24 +00:00
|
|
|
block: 'woocommerce/cart' | 'woocommerce/checkout';
|
2022-12-28 16:30:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function IncompatiblePaymentGatewaysNotice( {
|
|
|
|
toggleDismissedStatus,
|
2023-02-24 10:57:24 +00:00
|
|
|
block,
|
2022-12-28 16:30:46 +00:00
|
|
|
}: PaymentGatewaysNoticeProps ) {
|
2023-02-24 10:57:24 +00:00
|
|
|
const [
|
|
|
|
isVisible,
|
|
|
|
dismissNotice,
|
|
|
|
incompatiblePaymentMethods,
|
|
|
|
numberOfIncompatiblePaymentMethods,
|
|
|
|
] = useIncompatiblePaymentGatewaysNotice( block );
|
2022-12-28 16:30:46 +00:00
|
|
|
|
|
|
|
useEffect( () => {
|
2023-02-24 10:57:24 +00:00
|
|
|
toggleDismissedStatus( ! isVisible );
|
|
|
|
}, [ isVisible, toggleDismissedStatus ] );
|
2022-12-28 16:30:46 +00:00
|
|
|
|
2023-02-24 10:57:24 +00:00
|
|
|
if ( ! isVisible ) {
|
2022-12-28 16:30:46 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const noticeContent = createInterpolateElement(
|
|
|
|
_n(
|
|
|
|
'The following extension is incompatible with the block-based checkout. <a>Learn more</a>',
|
|
|
|
'The following extensions are incompatible with the block-based checkout. <a>Learn more</a>',
|
|
|
|
numberOfIncompatiblePaymentMethods,
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
),
|
|
|
|
{
|
|
|
|
a: (
|
|
|
|
// Suppress the warning as this <a> will be interpolated into the string with content.
|
|
|
|
// eslint-disable-next-line jsx-a11y/anchor-has-content
|
|
|
|
<ExternalLink href="https://woocommerce.com/document/cart-checkout-blocks-support-status/" />
|
|
|
|
),
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Notice
|
|
|
|
className="wc-blocks-incompatible-extensions-notice"
|
|
|
|
status={ 'warning' }
|
2023-02-24 10:57:24 +00:00
|
|
|
onRemove={ dismissNotice }
|
2022-12-28 16:30:46 +00:00
|
|
|
spokenMessage={ noticeContent }
|
|
|
|
>
|
|
|
|
<div className="wc-blocks-incompatible-extensions-notice__content">
|
|
|
|
<Icon
|
|
|
|
className="wc-blocks-incompatible-extensions-notice__warning-icon"
|
2023-02-07 07:06:05 +00:00
|
|
|
icon={ <Alert /> }
|
2022-12-28 16:30:46 +00:00
|
|
|
/>
|
|
|
|
<div>
|
|
|
|
<p>{ noticeContent }</p>
|
|
|
|
<ul>
|
|
|
|
{ Object.entries( incompatiblePaymentMethods ).map(
|
|
|
|
( [ id, title ] ) => (
|
|
|
|
<li
|
|
|
|
key={ id }
|
|
|
|
className="wc-blocks-incompatible-extensions-notice__element"
|
|
|
|
>
|
|
|
|
{ title }
|
|
|
|
</li>
|
|
|
|
)
|
|
|
|
) }
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Notice>
|
|
|
|
);
|
|
|
|
}
|