2023-09-29 10:39:57 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2023-11-30 14:37:19 +00:00
|
|
|
import { __, _n, sprintf } from '@wordpress/i18n';
|
2023-12-19 07:44:09 +00:00
|
|
|
import { Notice, ExternalLink } from '@wordpress/components';
|
2024-05-16 14:52:06 +00:00
|
|
|
import { createInterpolateElement } from '@wordpress/element';
|
2023-09-29 10:39:57 +00:00
|
|
|
import { Alert } from '@woocommerce/icons';
|
2023-11-30 14:37:19 +00:00
|
|
|
import { Icon, chevronDown } from '@wordpress/icons';
|
2023-10-19 15:43:43 +00:00
|
|
|
|
2023-09-29 10:39:57 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { useCombinedIncompatibilityNotice } from './use-combined-incompatibility-notice';
|
2023-12-19 07:44:09 +00:00
|
|
|
import { SwitchToClassicShortcodeButton } from '../switch-to-classic-shortcode-button';
|
2023-09-29 10:39:57 +00:00
|
|
|
import './editor.scss';
|
|
|
|
|
|
|
|
interface ExtensionNoticeProps {
|
|
|
|
block: 'woocommerce/cart' | 'woocommerce/checkout';
|
2023-10-19 15:43:43 +00:00
|
|
|
clientId: string;
|
2023-09-29 10:39:57 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 15:43:43 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2023-09-29 10:39:57 +00:00
|
|
|
export function IncompatibleExtensionsNotice( {
|
|
|
|
block,
|
2023-10-19 15:43:43 +00:00
|
|
|
clientId,
|
2023-09-29 10:39:57 +00:00
|
|
|
}: ExtensionNoticeProps ) {
|
|
|
|
const [
|
|
|
|
isVisible,
|
|
|
|
dismissNotice,
|
2023-11-30 14:37:19 +00:00
|
|
|
incompatibleExtensions,
|
|
|
|
incompatibleExtensionsCount,
|
2023-09-29 10:39:57 +00:00
|
|
|
] = useCombinedIncompatibilityNotice( block );
|
|
|
|
|
|
|
|
if ( ! isVisible ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const noticeContent = (
|
|
|
|
<>
|
2023-11-30 14:37:19 +00:00
|
|
|
{ incompatibleExtensionsCount > 1
|
2023-09-29 10:39:57 +00:00
|
|
|
? createInterpolateElement(
|
|
|
|
__(
|
2023-10-19 15:43:43 +00:00
|
|
|
'Some active extensions do not yet support this block. This may impact the shopper experience. <a>Learn more</a>',
|
2023-12-12 22:12:36 +00:00
|
|
|
'woocommerce'
|
2023-09-29 10:39:57 +00:00
|
|
|
),
|
|
|
|
{
|
|
|
|
a: (
|
2024-04-09 08:50:15 +00:00
|
|
|
<ExternalLink href="https://woocommerce.com/document/cart-checkout-blocks-status/" />
|
2023-09-29 10:39:57 +00:00
|
|
|
),
|
|
|
|
}
|
|
|
|
)
|
|
|
|
: createInterpolateElement(
|
|
|
|
sprintf(
|
2023-10-19 15:43:43 +00:00
|
|
|
// translators: %s is the name of the extension.
|
2023-09-29 10:39:57 +00:00
|
|
|
__(
|
2023-10-19 15:43:43 +00:00
|
|
|
'<strong>%s</strong> does not yet support this block. This may impact the shopper experience. <a>Learn more</a>',
|
2023-12-12 22:12:36 +00:00
|
|
|
'woocommerce'
|
2023-09-29 10:39:57 +00:00
|
|
|
),
|
2023-11-30 14:37:19 +00:00
|
|
|
Object.values( incompatibleExtensions )[ 0 ]
|
2023-09-29 10:39:57 +00:00
|
|
|
),
|
|
|
|
{
|
|
|
|
strong: <strong />,
|
|
|
|
a: (
|
2024-04-09 08:50:15 +00:00
|
|
|
<ExternalLink href="https://woocommerce.com/document/cart-checkout-blocks-status/" />
|
2023-09-29 10:39:57 +00:00
|
|
|
),
|
|
|
|
}
|
|
|
|
) }
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
|
2023-11-30 14:37:19 +00:00
|
|
|
const entries = Object.entries( incompatibleExtensions );
|
|
|
|
const remainingEntries = entries.length - 2;
|
|
|
|
|
2023-09-29 10:39:57 +00:00
|
|
|
return (
|
|
|
|
<Notice
|
|
|
|
className="wc-blocks-incompatible-extensions-notice"
|
|
|
|
status={ 'warning' }
|
|
|
|
onRemove={ dismissNotice }
|
|
|
|
spokenMessage={ noticeContent }
|
|
|
|
>
|
|
|
|
<div className="wc-blocks-incompatible-extensions-notice__content">
|
|
|
|
<Icon
|
|
|
|
className="wc-blocks-incompatible-extensions-notice__warning-icon"
|
|
|
|
icon={ <Alert /> }
|
|
|
|
/>
|
|
|
|
<div>
|
|
|
|
<p>{ noticeContent }</p>
|
2023-11-30 14:37:19 +00:00
|
|
|
{ incompatibleExtensionsCount > 1 && (
|
2023-09-29 10:39:57 +00:00
|
|
|
<ul>
|
2023-11-30 14:37:19 +00:00
|
|
|
{ entries.slice( 0, 2 ).map( ( [ id, title ] ) => (
|
|
|
|
<li
|
|
|
|
key={ id }
|
|
|
|
className="wc-blocks-incompatible-extensions-notice__element"
|
|
|
|
>
|
|
|
|
{ title }
|
|
|
|
</li>
|
|
|
|
) ) }
|
|
|
|
</ul>
|
|
|
|
) }
|
|
|
|
|
|
|
|
{ entries.length > 2 && (
|
|
|
|
<details>
|
|
|
|
<summary>
|
|
|
|
<span>
|
|
|
|
{ sprintf(
|
|
|
|
// translators: %s is the number of incompatible extensions.
|
|
|
|
_n(
|
|
|
|
'%s more incompatibility',
|
|
|
|
'%s more incompatibilites',
|
|
|
|
remainingEntries,
|
2023-12-12 22:12:36 +00:00
|
|
|
'woocommerce'
|
2023-11-30 14:37:19 +00:00
|
|
|
),
|
|
|
|
remainingEntries
|
|
|
|
) }
|
|
|
|
</span>
|
|
|
|
<Icon icon={ chevronDown } />
|
|
|
|
</summary>
|
|
|
|
<ul>
|
|
|
|
{ entries.slice( 2 ).map( ( [ id, title ] ) => (
|
2023-09-29 10:39:57 +00:00
|
|
|
<li
|
|
|
|
key={ id }
|
|
|
|
className="wc-blocks-incompatible-extensions-notice__element"
|
|
|
|
>
|
|
|
|
{ title }
|
|
|
|
</li>
|
2023-11-30 14:37:19 +00:00
|
|
|
) ) }
|
|
|
|
</ul>
|
|
|
|
</details>
|
2023-09-29 10:39:57 +00:00
|
|
|
) }
|
2023-12-19 07:44:09 +00:00
|
|
|
<SwitchToClassicShortcodeButton
|
|
|
|
block={ block }
|
|
|
|
clientId={ clientId }
|
2024-01-05 03:47:34 +00:00
|
|
|
type={ 'incompatible' }
|
2023-12-19 07:44:09 +00:00
|
|
|
/>
|
2023-09-29 10:39:57 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Notice>
|
|
|
|
);
|
|
|
|
}
|