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

75 lines
1.8 KiB
JavaScript
Raw Permalink Normal View History

Show notice for expired and expiring subscriptions in settings and in-app extensions page (#47004) * show notice on WC core about subs expired * add notice in wc core my subscription page * dismiss subscription notice * add rest api for dismiss subscription notioce * dismiss notice permanently * code refactor * fix issue in expired subs * not showing expiring subs notice if expired sub notice render not showing expiring subs notice if expired sub notice render * fix lint * added changelog * update comment * fix js lint * update response * added new endpoint for notice * update the endpoint URL * update the endpoint URL * show notice after one month * add css class for refactor * fix lint * Add missing callback after the merge * check plugin is installed on current site * add comments, and fix missing price * fix lint * remove unnecessary duplicate asset load * fix notice so that it only trigger dismiss API on notices close * localize the renew product price * track events in the wc settings page * Use the correct field product_regular_price instead of product_price * Add missing period in the notice message * add nonce to the dismiss notice API * extract dismiss notice API call to different code * extract expired and expiring component to 1 component * add track events for tsx components * fix nonce checking * fix lint * fix lint * enrich the button and hyperlink url to contains the product_id of expiring / expired subscription * fix lint * fix lint --------- Co-authored-by: Akeda Bagus <akeda.bagus@automattic.com> Co-authored-by: prahesa.setia <prahesa.kusuma.setia@automattic.com>
2024-05-31 01:34:36 +00:00
/**
* External dependencies
*/
import { recordEvent } from '@woocommerce/tracks';
window.jQuery( document ).ready( function () {
const expiredNoticeSelector = '#woo-subscription-expired-notice';
const expiringNoticeSelector = '#woo-subscription-expiring-notice';
if ( window.jQuery( expiredNoticeSelector ).length ) {
recordEvent( 'woo_subscription_expired_notice_in_settings_shown' );
}
if ( window.jQuery( expiringNoticeSelector ).length ) {
recordEvent( 'woo_subscription_expiring_notice_in_settings_shown' );
}
const callDismissNoticeAPI = function ( notice_id, nonce ) {
const data = {
notice_id,
dismiss_notice_nonce: nonce,
};
window.wp.apiFetch( {
path: `/wc-admin/notice/dismiss`,
method: 'POST',
data,
} );
};
window
.jQuery( expiredNoticeSelector )
.on( 'click', 'button.notice-dismiss', function () {
recordEvent(
'woo_subscription_expired_notice_in_settings_dismissed'
);
const dismiss_notice_nonce = window
.jQuery( expiredNoticeSelector )
.data( 'dismissnonce' );
callDismissNoticeAPI(
'woo-subscription-expired-notice',
dismiss_notice_nonce
);
} );
window.jQuery( expiredNoticeSelector ).on( 'click', 'a', function () {
recordEvent( 'woo_subscription_expired_notice_in_settings_clicked' );
return true;
} );
window
.jQuery( expiringNoticeSelector )
.on( 'click', 'button.notice-dismiss', function () {
recordEvent(
'woo_subscription_expiring_notice_in_settings_dismissed'
);
const dismiss_notice_nonce = window
.jQuery( expiredNoticeSelector )
.data( 'dismissnonce' );
callDismissNoticeAPI(
'woo-subscription-expiring-notice',
dismiss_notice_nonce
);
} );
window.jQuery( expiringNoticeSelector ).on( 'click', 'a', function () {
recordEvent( 'woo_subscription_expiring_notice_in_settings_clicked' );
return true;
} );
} );