Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Launchpad My Home: Showing snackbar when a task was completed #98865

Open
wants to merge 4 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions apps/wpcom-block-editor/src/wpcom/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import './features/fix-coblocks-fonts';
import './features/reorder-block-categories';
import './features/tracking';
import './features/use-classic-block-guide';
import { OnboardingNextStepAfterPublishingPost } from './features/onboarding-next-step-after-publishing-post';
import { RedirectOnboardingUserAfterPublishingPost } from './features/redirect-onboarding-user-after-publishing-post';
import InserterMenuTrackingEvent from './features/tracking/wpcom-inserter-menu-search-term';
import './features/site-editor-env-consistency';
Expand All @@ -23,3 +24,9 @@ registerPlugin( 'start-writing-flow', {
return <RedirectOnboardingUserAfterPublishingPost />;
},
} );

registerPlugin( 'onboarding-next-step-after-publishing-post', {
render() {
return <OnboardingNextStepAfterPublishingPost />;
},
} );
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { dispatch, select, subscribe, useSelect } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { Icon, pending } from '@wordpress/icons';
import { getQueryArg } from '@wordpress/url';

export function OnboardingNextStepAfterPublishingPost() {
const currentPostType = useSelect(
( localSelect ) => localSelect( 'core/editor' ).getCurrentPostType(),
[]
);

const hasPublishFirstPostTaskQueryArg = window.location.hash === '#publish-first-post';

if ( ! hasPublishFirstPostTaskQueryArg || currentPostType !== 'post' ) {
return false;
}

// Save site origin in session storage to be used in editor refresh.
const siteOriginParam = getQueryArg( window.location.search, 'origin' );
if ( siteOriginParam ) {
window.sessionStorage.setItem( 'site-origin', siteOriginParam );
}

const siteOrigin = window.sessionStorage.getItem( 'site-origin' ) || 'https://wordpress.com';
const siteSlug = window.location.hostname;

const unsubscribe = subscribe( () => {
const isSavingPost = select( 'core/editor' ).isSavingPost();
const getCurrentPostRevisionsCount = select( 'core/editor' ).getCurrentPostRevisionsCount();

if ( isSavingPost ) {
const unsubscribeFromSavingPost = subscribe( () => {
const postStatus = select( 'core/editor' ).getEditedPostAttribute( 'status' );
if (
( postStatus === 'publish' || postStatus === 'future' ) &&
getCurrentPostRevisionsCount >= 1
) {
unsubscribeFromSavingPost();
unsubscribe();
dispatch( 'core/edit-post' ).closePublishSidebar();

const unsubscribeFromNotices = subscribe( () => {
const notices = select( 'core/notices' ).getNotices();
if ( notices.some( ( notice ) => notice.id === 'editor-save' ) ) {
dispatch( 'core/notices' ).removeNotice( 'editor-save' );

// Show success notice with Next steps link
dispatch( 'core/notices' ).createSuccessNotice(
__( 'Well done publishing your first post!', 'wpcom-onboarding-task' ),
{
actions: [
{
label: 'Next steps',
url: `${ siteOrigin }/home/${ siteSlug }`,
},
],
type: 'snackbar',
isDismissible: true,
explicitDismiss: true,
icon: <Icon icon={ pending } fill="white" size={ 24 } />,
id: 'NEXT_STEPS_NOTICE_ID',
}
);

unsubscribeFromNotices();
}
} );
}
} );
}
} );
}
Loading