2019-11-07 00:17:46 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import { dispatch } from '@wordpress/data';
|
|
|
|
import domReady from '@wordpress/dom-ready';
|
2019-11-22 17:07:26 +00:00
|
|
|
import { getAdminLink } from '@woocommerce/wc-admin-settings';
|
2019-11-07 00:17:46 +00:00
|
|
|
|
2019-11-12 01:17:36 +00:00
|
|
|
/**
|
|
|
|
* Returns a promise and resolves when the loader overlay no longer exists.
|
|
|
|
*
|
|
|
|
* @return {Promise} Promise for overlay existence.
|
|
|
|
*/
|
|
|
|
const saveCompleted = () => {
|
|
|
|
if ( document.querySelector( '.blockUI.blockOverlay' ) !== null ) {
|
2020-02-14 02:23:21 +00:00
|
|
|
const promise = new Promise( ( resolve ) => {
|
|
|
|
window.requestAnimationFrame( resolve );
|
2019-11-12 01:17:36 +00:00
|
|
|
} );
|
|
|
|
return promise.then( () => saveCompleted() );
|
|
|
|
}
|
|
|
|
|
|
|
|
return Promise.resolve( true );
|
|
|
|
};
|
|
|
|
|
2019-11-07 00:17:46 +00:00
|
|
|
/**
|
|
|
|
* Displays a notice on tax settings save.
|
|
|
|
*/
|
|
|
|
const showTaxCompletionNotice = () => {
|
2019-11-12 01:17:36 +00:00
|
|
|
const saveButton = document.querySelector( '.woocommerce-save-button' );
|
|
|
|
|
|
|
|
if ( saveButton.classList.contains( 'is-clicked' ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
saveButton.classList.add( 'is-clicked' );
|
|
|
|
saveCompleted().then( () =>
|
|
|
|
dispatch( 'core/notices' ).createSuccessNotice(
|
|
|
|
__( "You've added your first tax rate!", 'woocommerce-admin' ),
|
|
|
|
{
|
|
|
|
id: 'WOOCOMMERCE_ONBOARDING_TAX_NOTICE',
|
|
|
|
actions: [
|
|
|
|
{
|
|
|
|
url: getAdminLink( 'admin.php?page=wc-admin' ),
|
|
|
|
label: __( 'Continue setup.', 'woocommerce-admin' ),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}
|
|
|
|
)
|
2019-11-07 00:17:46 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
domReady( () => {
|
|
|
|
const saveButton = document.querySelector( '.woocommerce-save-button' );
|
|
|
|
if ( saveButton ) {
|
|
|
|
saveButton.addEventListener( 'click', showTaxCompletionNotice );
|
|
|
|
}
|
|
|
|
} );
|