2024-04-17 10:13:24 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import { Button } from '@wordpress/components';
|
2024-05-13 06:45:43 +00:00
|
|
|
import { recordEvent } from '@woocommerce/tracks';
|
2024-04-17 10:13:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2024-08-01 07:01:21 +00:00
|
|
|
import { appendURLParams, connectUrl } from '~/marketplace/utils/functions';
|
2024-04-17 10:13:24 +00:00
|
|
|
import Notice from '~/marketplace/components/notice/notice';
|
|
|
|
import { getAdminSetting } from '~/utils/admin-settings';
|
|
|
|
|
|
|
|
export default function ConnectNotice(): JSX.Element | null {
|
|
|
|
const localStorageKey = 'woo-connect-notice-marketplace-dismissed';
|
|
|
|
const wccomSettings = getAdminSetting( 'wccomHelper', {} );
|
|
|
|
const noticeType = wccomSettings?.woocomConnectNoticeType || 'none';
|
|
|
|
|
|
|
|
if ( noticeType === 'none' ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const lastDismissed = localStorage.getItem( localStorageKey );
|
|
|
|
const parsedDismissedDate = new Date( lastDismissed || '' );
|
|
|
|
const aMonthAgo = new Date();
|
|
|
|
aMonthAgo.setMonth( aMonthAgo.getMonth() - 1 );
|
|
|
|
|
|
|
|
// try to re-show the notice if it was dismissed more than a month ago.
|
|
|
|
// removing these 2 local storage items will make the notice reappear.
|
|
|
|
if (
|
|
|
|
lastDismissed === null ||
|
|
|
|
isNaN( parsedDismissedDate.valueOf() ) ||
|
|
|
|
aMonthAgo.valueOf() > parsedDismissedDate.valueOf()
|
|
|
|
) {
|
|
|
|
localStorage.removeItem(
|
|
|
|
'wc-marketplaceNoticeClosed-woo-connect-notice'
|
|
|
|
);
|
|
|
|
localStorage.removeItem( localStorageKey );
|
|
|
|
}
|
|
|
|
|
|
|
|
let description = '';
|
|
|
|
|
|
|
|
if ( noticeType === 'long' ) {
|
|
|
|
description = description.concat(
|
|
|
|
__(
|
|
|
|
'Your store might be at risk as you are running old versions of WooCommerce plugins.',
|
|
|
|
'woocommerce'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
description = description.concat( ' ' );
|
|
|
|
}
|
|
|
|
|
|
|
|
description = description.concat(
|
|
|
|
__(
|
|
|
|
'<strong>Connect your store to WooCommerce.com</strong> to get updates and streamlined support for your subscriptions.',
|
|
|
|
'woocommerce'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2024-05-13 06:45:43 +00:00
|
|
|
const handleClick = () => {
|
|
|
|
recordEvent( 'woo_connect_notice_in_marketplace_clicked' );
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleClose = () => {
|
|
|
|
localStorage.setItem( localStorageKey, new Date().toString() );
|
|
|
|
recordEvent( 'woo_connect_notice_in_marketplace_dismissed' );
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleLoad = () => {
|
|
|
|
recordEvent( 'woo_connect_notice_in_marketplace_shown' );
|
|
|
|
};
|
|
|
|
|
2024-08-01 07:01:21 +00:00
|
|
|
const connectUrlWithUTM = appendURLParams( connectUrl(), [
|
|
|
|
[ 'utm_source', 'pu' ],
|
|
|
|
[ 'utm_campaign', 'pu_in_apps_screen_connect' ],
|
|
|
|
] );
|
|
|
|
|
2024-04-17 10:13:24 +00:00
|
|
|
return (
|
|
|
|
<Notice
|
|
|
|
id="woo-connect-notice"
|
|
|
|
description={ description }
|
|
|
|
isDismissible={ true }
|
|
|
|
variant="error"
|
2024-05-13 06:45:43 +00:00
|
|
|
onClose={ handleClose }
|
|
|
|
onLoad={ handleLoad }
|
2024-04-17 10:13:24 +00:00
|
|
|
>
|
2024-05-13 06:45:43 +00:00
|
|
|
<Button
|
2024-08-01 07:01:21 +00:00
|
|
|
href={ connectUrlWithUTM }
|
2024-05-13 06:45:43 +00:00
|
|
|
variant="secondary"
|
|
|
|
onClick={ handleClick }
|
|
|
|
>
|
2024-04-17 10:13:24 +00:00
|
|
|
{ __( 'Connect', 'woocommerce' ) }
|
|
|
|
</Button>
|
|
|
|
</Notice>
|
|
|
|
);
|
|
|
|
}
|