2019-10-21 18:13:25 +00:00
|
|
|
|
/**
|
|
|
|
|
* External dependencies
|
|
|
|
|
*/
|
2019-11-12 15:31:44 +00:00
|
|
|
|
import { dispatch } from '@wordpress/data';
|
2019-10-21 18:13:25 +00:00
|
|
|
|
import { __ } from '@wordpress/i18n';
|
2019-11-12 15:31:44 +00:00
|
|
|
|
import domReady from '@wordpress/dom-ready';
|
2022-01-06 12:53:30 +00:00
|
|
|
|
import { getAdminLink } from '@woocommerce/settings';
|
2020-08-20 04:59:52 +00:00
|
|
|
|
import { queueRecordEvent } from '@woocommerce/tracks';
|
2019-10-21 18:13:25 +00:00
|
|
|
|
|
2019-11-15 13:32:02 +00:00
|
|
|
|
/**
|
|
|
|
|
* Internal dependencies
|
|
|
|
|
*/
|
|
|
|
|
|
2019-10-21 18:13:25 +00:00
|
|
|
|
/**
|
2019-11-12 15:31:44 +00:00
|
|
|
|
* Returns a promise and resolves when the post begins to publish.
|
2019-10-21 18:13:25 +00:00
|
|
|
|
*
|
2019-11-12 15:31:44 +00:00
|
|
|
|
* @return {Promise} Promise for overlay existence.
|
2019-10-21 18:13:25 +00:00
|
|
|
|
*/
|
2019-11-12 15:31:44 +00:00
|
|
|
|
const saveStarted = () => {
|
2020-03-02 22:22:32 +00:00
|
|
|
|
if (
|
|
|
|
|
! document
|
|
|
|
|
.querySelector( '.editor-post-publish-button' )
|
|
|
|
|
.classList.contains( 'is-busy' )
|
|
|
|
|
) {
|
2020-02-14 02:23:21 +00:00
|
|
|
|
const promise = new Promise( ( resolve ) => {
|
|
|
|
|
window.requestAnimationFrame( resolve );
|
2019-11-12 15:31:44 +00:00
|
|
|
|
} );
|
|
|
|
|
return promise.then( () => saveStarted() );
|
|
|
|
|
}
|
2019-10-21 18:13:25 +00:00
|
|
|
|
|
2019-11-12 15:31:44 +00:00
|
|
|
|
return Promise.resolve( true );
|
|
|
|
|
};
|
2019-10-21 18:13:25 +00:00
|
|
|
|
|
2019-11-12 15:31:44 +00:00
|
|
|
|
/**
|
|
|
|
|
* Returns a promise and resolves when the post has been saved and notices have shown.
|
|
|
|
|
*
|
|
|
|
|
* @return {Promise} Promise for overlay existence.
|
|
|
|
|
*/
|
|
|
|
|
const saveCompleted = () => {
|
2020-02-14 02:23:21 +00:00
|
|
|
|
if (
|
2020-03-02 22:22:32 +00:00
|
|
|
|
document
|
|
|
|
|
.querySelector( '.editor-post-publish-button' )
|
|
|
|
|
.classList.contains( 'is-busy' )
|
2020-02-14 02:23:21 +00:00
|
|
|
|
) {
|
|
|
|
|
const promise = new Promise( ( resolve ) => {
|
|
|
|
|
window.requestAnimationFrame( resolve );
|
2019-11-12 15:31:44 +00:00
|
|
|
|
} );
|
|
|
|
|
return promise.then( () => saveCompleted() );
|
|
|
|
|
}
|
2019-10-21 18:13:25 +00:00
|
|
|
|
|
2019-11-12 15:31:44 +00:00
|
|
|
|
return Promise.resolve( true );
|
|
|
|
|
};
|
2019-10-21 18:13:25 +00:00
|
|
|
|
|
2019-11-12 15:31:44 +00:00
|
|
|
|
/**
|
|
|
|
|
* Displays a notice on page save and updates the hompage options.
|
|
|
|
|
*/
|
|
|
|
|
const onboardingHomepageNotice = () => {
|
|
|
|
|
const saveButton = document.querySelector( '.editor-post-publish-button' );
|
|
|
|
|
if ( saveButton.classList.contains( 'is-clicked' ) ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-10-21 18:13:25 +00:00
|
|
|
|
|
2019-11-12 15:31:44 +00:00
|
|
|
|
saveButton.classList.add( 'is-clicked' );
|
2019-10-21 18:13:25 +00:00
|
|
|
|
|
2019-11-12 15:31:44 +00:00
|
|
|
|
saveCompleted().then( () => {
|
|
|
|
|
const notificationType =
|
2020-02-14 02:23:21 +00:00
|
|
|
|
document.querySelector( '.components-snackbar__content' ) !== null
|
|
|
|
|
? 'snackbar'
|
|
|
|
|
: 'default';
|
2019-10-21 18:13:25 +00:00
|
|
|
|
|
2019-11-12 15:31:44 +00:00
|
|
|
|
dispatch( 'core/notices' ).removeNotice( 'SAVE_POST_NOTICE_ID' );
|
|
|
|
|
dispatch( 'core/notices' ).createSuccessNotice(
|
2024-08-20 09:13:17 +00:00
|
|
|
|
__( '🏠 Nice work creating your store’s homepage!', 'woocommerce' ),
|
2019-11-12 15:31:44 +00:00
|
|
|
|
{
|
|
|
|
|
id: 'WOOCOMMERCE_ONBOARDING_HOME_PAGE_NOTICE',
|
|
|
|
|
type: notificationType,
|
|
|
|
|
actions: [
|
2019-10-21 18:13:25 +00:00
|
|
|
|
{
|
2022-03-30 09:00:04 +00:00
|
|
|
|
label: __( 'Continue setup.', 'woocommerce' ),
|
2019-11-15 13:32:02 +00:00
|
|
|
|
onClick: () => {
|
2020-02-14 02:23:21 +00:00
|
|
|
|
queueRecordEvent(
|
|
|
|
|
'tasklist_appearance_continue_setup',
|
|
|
|
|
{}
|
|
|
|
|
);
|
2022-08-11 14:04:14 +00:00
|
|
|
|
window.location.href = getAdminLink(
|
2020-02-14 02:23:21 +00:00
|
|
|
|
'admin.php?page=wc-admin&task=appearance'
|
|
|
|
|
);
|
2019-11-15 13:32:02 +00:00
|
|
|
|
},
|
2019-11-12 15:31:44 +00:00
|
|
|
|
},
|
|
|
|
|
],
|
2019-10-21 18:13:25 +00:00
|
|
|
|
}
|
2019-11-12 15:31:44 +00:00
|
|
|
|
);
|
2019-10-21 18:13:25 +00:00
|
|
|
|
} );
|
|
|
|
|
};
|
|
|
|
|
|
2019-11-12 15:31:44 +00:00
|
|
|
|
domReady( () => {
|
2020-02-14 02:23:21 +00:00
|
|
|
|
const publishButton = document.querySelector(
|
2020-03-02 22:22:32 +00:00
|
|
|
|
'.editor-post-publish-button'
|
2020-02-14 02:23:21 +00:00
|
|
|
|
);
|
2019-11-12 15:31:44 +00:00
|
|
|
|
if ( publishButton ) {
|
2020-03-02 22:22:32 +00:00
|
|
|
|
publishButton.addEventListener(
|
|
|
|
|
'click',
|
|
|
|
|
saveStarted().then( () => onboardingHomepageNotice() )
|
|
|
|
|
);
|
2019-10-21 18:13:25 +00:00
|
|
|
|
}
|
|
|
|
|
} );
|