2024-05-13 06:45:43 +00:00
|
|
|
/**
|
|
|
|
* 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';
|
2024-05-13 06:45:43 +00:00
|
|
|
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()
|
|
|
|
);
|
2024-05-13 06:45:43 +00:00
|
|
|
recordEvent( 'woo_connect_notice_in_settings_dismissed' );
|
2024-04-17 10:13:24 +00:00
|
|
|
} );
|
|
|
|
|
2024-05-13 06:45:43 +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();
|
2024-05-13 06:45:43 +00:00
|
|
|
} else {
|
|
|
|
recordEvent( 'woo_connect_notice_in_settings_shown' );
|
2024-04-17 10:13:24 +00:00
|
|
|
}
|
|
|
|
} );
|