woocommerce/plugins/woocommerce-admin/client/wp-admin-scripts/woo-connect-notice/index.js

47 lines
1.3 KiB
JavaScript
Raw Normal View History

/**
* External dependencies
*/
import { recordEvent } from '@woocommerce/tracks';
2024-04-17 10:13:24 +00:00
window.jQuery( document ).ready( function () {
// hide the notice when the customer clicks the dismiss button up until 1 month, then it will be shown again.
const wooConnectNoticeSelector = '.woo-connect-notice';
const wooConnectNoticeLinkSelector = '#woo-connect-notice-url';
2024-04-17 10:13:24 +00:00
const localStorageKey = 'woo-connect-notice-settings-dismissed';
window
.jQuery( wooConnectNoticeSelector )
.on( 'click', 'button.notice-dismiss', function () {
window.localStorage.setItem(
localStorageKey,
new Date().toString()
);
recordEvent( 'woo_connect_notice_in_settings_dismissed' );
2024-04-17 10:13:24 +00:00
} );
window.jQuery( wooConnectNoticeLinkSelector ).on( 'click', function () {
recordEvent( 'woo_connect_notice_in_settings_clicked' );
return true;
} );
2024-04-17 10:13:24 +00:00
let shouldHideNotice = false;
const savedDismissedDate = window.localStorage.getItem( localStorageKey );
const parsedDismissedDate = new Date( savedDismissedDate || '' );
const aMonthAgo = new Date();
aMonthAgo.setMonth( aMonthAgo.getMonth() - 1 );
if (
savedDismissedDate &&
aMonthAgo.valueOf() < parsedDismissedDate.valueOf()
) {
shouldHideNotice = true;
}
if ( shouldHideNotice ) {
window.jQuery( wooConnectNoticeSelector ).remove();
} else {
recordEvent( 'woo_connect_notice_in_settings_shown' );
2024-04-17 10:13:24 +00:00
}
} );