diff --git a/assets/stylesheets/_components.scss b/assets/stylesheets/_components.scss
index 5931a8c034d9..b11f6b89fd2e 100644
--- a/assets/stylesheets/_components.scss
+++ b/assets/stylesheets/_components.scss
@@ -356,6 +356,7 @@
@import 'my-sites/ads/style';
@import 'my-sites/all-sites-icon/style';
@import 'my-sites/checklist/style';
+@import 'my-sites/checklist/wpcom-checklist/checklist-banner/style';
@import 'my-sites/current-site/style';
@import 'my-sites/current-site/sidebar-banner/style';
@import 'my-sites/customize/style';
@@ -447,7 +448,6 @@
@import 'my-sites/activity/activity-log-tasklist/style';
@import 'my-sites/stats/all-time/style';
@import 'my-sites/stats/annual-site-stats/style';
-@import 'my-sites/stats/checklist-banner/style';
@import 'my-sites/stats/geochart/style';
@import 'my-sites/stats/most-popular/style';
@import 'my-sites/stats/post-performance/style';
diff --git a/client/components/checklist/index.js b/client/components/checklist/index.js
index 274a7db160ce..b529cabcb21d 100644
--- a/client/components/checklist/index.js
+++ b/client/components/checklist/index.js
@@ -16,37 +16,54 @@ import TaskPlaceholder from 'components/checklist/task-placeholder';
export default class Checklist extends PureComponent {
static propTypes = {
isPlaceholder: PropTypes.bool,
+ updateCompletion: PropTypes.func,
};
- state = { hideCompleted: false };
-
- toggleCompleted = () =>
- this.setState( ( { hideCompleted } ) => ( { hideCompleted: ! hideCompleted } ) );
+ componentDidMount() {
+ this.notifyCompletion();
+ }
- renderPlaceholder() {
- return (
-
-
-
- { times( Children.count( this.props.children ), index => (
-
- ) ) }
-
-
- );
+ componentDidUpdate() {
+ this.notifyCompletion();
}
- render() {
- if ( this.props.isPlaceholder ) {
- return this.renderPlaceholder();
+ notifyCompletion() {
+ if ( 'function' === typeof this.props.updateCompletion ) {
+ const [ complete, total ] = this.calculateCompletion();
+ this.props.updateCompletion( { complete: complete >= total } );
}
+ }
+ calculateCompletion() {
const { children } = this.props;
-
- const count = Children.map( children, child => child.props.completed ).reduce(
- ( acc, completed ) => ( true === completed ? acc + 1 : acc ),
+ const childrenArray = Children.toArray( children );
+ const completedCount = childrenArray.reduce(
+ ( count, task ) => ( true === task.props.completed ? count + 1 : count ),
0
);
+ const total = childrenArray.length;
+ return [ completedCount, total ];
+ }
+
+ state = { hideCompleted: false };
+
+ toggleCompleted = () =>
+ this.setState( ( { hideCompleted } ) => ( { hideCompleted: ! hideCompleted } ) );
+
+ render() {
+ const [ completed, total ] = this.calculateCompletion();
+ if ( this.props.isPlaceholder ) {
+ return (
+
+
+
+ { times( total, index => (
+
+ ) ) }
+
+
+ );
+ }
return (
-
{ children }
+
{ this.props.children }
);
}
diff --git a/client/my-sites/checklist/checklist-show/index.jsx b/client/my-sites/checklist/checklist-show/index.jsx
deleted file mode 100644
index 8f4e7e3618c1..000000000000
--- a/client/my-sites/checklist/checklist-show/index.jsx
+++ /dev/null
@@ -1,113 +0,0 @@
-/** @format */
-
-/**
- * External dependencies
- */
-import React, { Fragment, PureComponent } from 'react';
-import { connect } from 'react-redux';
-import { localize } from 'i18n-calypso';
-import { get } from 'lodash';
-
-/**
- * Internal dependencies
- */
-import Checklist from 'components/checklist';
-import Task from 'components/checklist/task';
-import { requestSiteChecklistTaskUpdate } from 'state/checklist/actions';
-import { getSelectedSiteId } from 'state/ui/selectors';
-import getSiteChecklist from 'state/selectors/get-site-checklist';
-import { getSiteSlug } from 'state/sites/selectors';
-import QuerySiteChecklist from 'components/data/query-site-checklist';
-import { getTaskUrls, launchTask, getTasks } from '../onboardingChecklist';
-import { recordTracksEvent } from 'state/analytics/actions';
-import { createNotice } from 'state/notices/actions';
-import { requestGuidedTour } from 'state/ui/guided-tours/actions';
-import QueryPosts from 'components/data/query-posts';
-import { getSitePosts } from 'state/posts/selectors';
-
-class ChecklistShow extends PureComponent {
- isComplete( taskId ) {
- return get( this.props.taskStatuses, [ taskId, 'completed' ], false );
- }
-
- handleTaskStart = task => () => {
- const { requestTour, siteSlug, track, taskUrls } = this.props;
- launchTask( {
- task: {
- ...task,
- completed: task.completed || this.isComplete( task.id ),
- url: taskUrls[ task.id ] || task.url,
- },
- location: 'checklist_show',
- requestTour,
- siteSlug,
- track,
- } );
- };
-
- handleTaskDismiss = task => () => {
- const { notify, siteId, update } = this.props;
-
- if ( task ) {
- notify( 'is-success', 'You completed a task!' );
- update( siteId, task.id );
- }
- };
-
- render() {
- const { siteId, taskStatuses, tasks } = this.props;
-
- return (
-
- { siteId && }
- { siteId && (
-
- ) }
-
- { tasks.map( task => (
-
- ) ) }
-
-
- );
- }
-}
-
-const mapStateToProps = state => {
- const siteId = getSelectedSiteId( state );
-
- return {
- siteId,
- siteSlug: getSiteSlug( state, siteId ),
- taskStatuses: get( getSiteChecklist( state, siteId ), [ 'tasks' ] ),
- taskUrls: getTaskUrls( getSitePosts( state, siteId ) ),
- tasks: getTasks( state, siteId ),
- };
-};
-
-const mapDispatchToProps = {
- track: recordTracksEvent,
- notify: createNotice,
- requestTour: requestGuidedTour,
- update: requestSiteChecklistTaskUpdate,
-};
-
-export default connect(
- mapStateToProps,
- mapDispatchToProps
-)( localize( ChecklistShow ) );
diff --git a/client/my-sites/checklist/main.jsx b/client/my-sites/checklist/main.jsx
index 17413296b554..1d55438801aa 100644
--- a/client/my-sites/checklist/main.jsx
+++ b/client/my-sites/checklist/main.jsx
@@ -3,7 +3,7 @@
* External dependencies
*/
import page from 'page';
-import React, { Fragment, PureComponent } from 'react';
+import React, { PureComponent } from 'react';
import { connect } from 'react-redux';
import { localize } from 'i18n-calypso';
import { some } from 'lodash';
@@ -11,7 +11,6 @@ import { some } from 'lodash';
/**
* Internal dependencies
*/
-import ChecklistShow from './checklist-show';
import ChecklistShowShare from './share';
import DocumentHead from 'components/data/document-head';
import EmptyContent from 'components/empty-content';
@@ -22,21 +21,15 @@ import Main from 'components/main';
import PageViewTracker from 'lib/analytics/page-view-tracker';
import QuerySiteChecklist from 'components/data/query-site-checklist';
import SidebarNavigation from 'my-sites/sidebar-navigation';
+import WpcomChecklist from './wpcom-checklist';
import { getCurrentUser } from 'state/current-user/selectors';
import { getSelectedSiteId } from 'state/ui/selectors';
import { getSiteSlug, isJetpackSite, isNewSite } from 'state/sites/selectors';
import { isEnabled } from 'config';
-/**
- * Included to fix regression.
- * https://github.com/Automattic/wp-calypso/issues/26572
- * @TODO clean up module separation.
- */
-import getSiteChecklist from 'state/selectors/get-site-checklist';
-import { mergeObjectIntoArrayById } from './util';
-import { tasks as wpcomTasks } from './onboardingChecklist';
-
class ChecklistMain extends PureComponent {
+ state = { complete: false };
+
componentDidMount() {
this.maybeRedirectJetpack();
}
@@ -45,6 +38,8 @@ class ChecklistMain extends PureComponent {
this.maybeRedirectJetpack( prevProps );
}
+ handleCompletionUpdate = ( { complete } ) => void this.setState( { complete } );
+
/**
* Redirect Jetpack checklists to /plans/my-plan/:siteSlug
*
@@ -76,12 +71,12 @@ class ChecklistMain extends PureComponent {
}
renderHeader() {
- const { displayMode, isNewlyCreatedSite, tasks, translate } = this.props;
- const completed = tasks && ! some( tasks, { completed: false } );
+ const { displayMode, isNewlyCreatedSite, translate } = this.props;
+ const { complete } = this.state;
- if ( completed ) {
+ if ( complete ) {
return (
-
+ <>
-
+ >
);
}
if ( isNewlyCreatedSite ) {
return (
-
+ <>
-
+ >
);
}
@@ -164,11 +159,11 @@ class ChecklistMain extends PureComponent {
{ checklistAvailable ? (
-
+ <>
{ siteId && }
{ this.renderHeader() }
-
-
+
+ >
) : (
) }
@@ -182,14 +177,6 @@ export default connect( state => {
const isAtomic = isSiteAutomatedTransfer( state, siteId );
const isJetpack = isJetpackSite( state, siteId );
- /**
- * Included to fix regression.
- * https://github.com/Automattic/wp-calypso/issues/26572
- * @TODO clean up module separation.
- */
- const siteChecklist = getSiteChecklist( state, siteId );
- const tasksFromServer = siteChecklist && siteChecklist.tasks;
-
return {
checklistAvailable: ! isAtomic && ( isEnabled( 'jetpack/checklist' ) || ! isJetpack ),
isAtomic,
@@ -199,12 +186,5 @@ export default connect( state => {
siteId,
siteSlug: getSiteSlug( state, siteId ),
user: getCurrentUser( state ),
-
- /**
- * Included to fix regression.
- * https://github.com/Automattic/wp-calypso/issues/26572
- * @TODO clean up module separation.
- */
- tasks: tasksFromServer ? mergeObjectIntoArrayById( wpcomTasks, tasksFromServer ) : null,
};
} )( localize( ChecklistMain ) );
diff --git a/client/my-sites/checklist/onboardingChecklist.js b/client/my-sites/checklist/onboardingChecklist.js
deleted file mode 100644
index 7b7f1c94c468..000000000000
--- a/client/my-sites/checklist/onboardingChecklist.js
+++ /dev/null
@@ -1,176 +0,0 @@
-/** @format */
-/**
- * External dependencies
- */
-import page from 'page';
-import { isDesktop } from 'lib/viewport';
-import { translate } from 'i18n-calypso';
-import { find } from 'lodash';
-import { getSiteOption } from 'state/sites/selectors';
-
-export const tasks = [
- {
- id: 'site_created',
- title: translate( 'Create your site' ),
- description: translate( 'This is where your adventure begins.' ),
- completedTitle: translate( 'You created your site' ),
- completed: true,
- },
- {
- id: 'domain_selected',
- title: translate( 'Pick a website address' ),
- description: translate( 'Choose an address so people can find you on the internet.' ),
- completedTitle: translate( 'You picked a website address' ),
- completed: true,
- image: '/calypso/images/stats/tasks/domains.svg',
- },
- {
- id: 'blogname_set',
- title: translate( 'Give your site a name' ),
- description: translate( 'Give your site a descriptive name to entice visitors.' ),
- duration: translate( '%d minute', '%d minutes', { count: 1, args: [ 1 ] } ),
- completedTitle: translate( 'You updated your site title' ),
- completedButtonText: translate( 'Edit' ),
- url: '/settings/general/$siteSlug',
- image: '/calypso/images/stats/tasks/personalize-your-site.svg',
- tour: 'checklistSiteTitle',
- },
- {
- id: 'site_icon_set',
- title: translate( 'Upload a site icon' ),
- description: translate(
- 'Help people recognize your site in browser tabs — just like the WordPress.com W!'
- ),
- duration: translate( '%d minute', '%d minutes', { count: 1, args: [ 1 ] } ),
- completedTitle: translate( 'You uploaded a site icon' ),
- completedButtonText: translate( 'Change' ),
- url: '/settings/general/$siteSlug',
- image: '/calypso/images/stats/tasks/upload-icon.svg',
- tour: 'checklistSiteIcon',
- },
- {
- id: 'blogdescription_set',
- title: translate( 'Create a tagline' ),
- description: translate( 'Pique readers’ interest with a little more detail about your site.' ),
- duration: translate( '%d minute', '%d minutes', { count: 2, args: [ 2 ] } ),
- completedTitle: translate( 'You created a tagline' ),
- completedButtonText: translate( 'Change' ),
- url: '/settings/general/$siteSlug',
- image: '/calypso/images/stats/tasks/create-tagline.svg',
- tour: 'checklistSiteTagline',
- },
- {
- id: 'avatar_uploaded',
- title: translate( 'Upload your profile picture' ),
- description: translate(
- 'Who’s the person behind the site? Personalize your posts and comments with a custom profile picture.'
- ),
- duration: translate( '%d minute', '%d minutes', { count: 2, args: [ 2 ] } ),
- completedTitle: translate( 'You uploaded a profile picture' ),
- completedButtonText: translate( 'Change' ),
- url: '/me',
- image: '/calypso/images/stats/tasks/upload-profile-picture.svg',
- tour: 'checklistUserAvatar',
- },
- {
- id: 'contact_page_updated',
- title: translate( 'Personalize your Contact page' ),
- description: translate(
- 'Encourage visitors to get in touch — a website is for connecting with people.'
- ),
- duration: translate( '%d minute', '%d minutes', { count: 2, args: [ 2 ] } ),
- completedTitle: translate( 'You updated your Contact page' ),
- completedButtonText: translate( 'Edit' ),
- image: '/calypso/images/stats/tasks/contact.svg',
- url: '/post/$siteSlug/2',
- tour: 'checklistContactPage',
- },
- {
- id: 'post_published',
- title: translate( 'Publish your first blog post' ),
- description: translate( 'Introduce yourself to the world! That’s why you’re here.' ),
- duration: translate( '%d minute', '%d minutes', { count: 10, args: [ 10 ] } ),
- completedTitle: translate( 'You published your first blog post' ),
- completedButtonText: translate( 'Edit' ),
- url: '/post/$siteSlug',
- image: '/calypso/images/stats/tasks/first-post.svg',
- tour: 'checklistPublishPost',
- },
- {
- id: 'custom_domain_registered',
- title: translate( 'Register a custom domain' ),
- description: translate(
- 'Memorable domain names make it easy for people to remember your address — and search engines love ’em.'
- ),
- duration: translate( '%d minute', '%d minutes', { count: 2, args: [ 2 ] } ),
- completedTitle: translate( 'You registered a custom domain' ),
- completedButtonText: translate( 'Change' ),
- url: '/domains/add/$siteSlug',
- image: '/calypso/images/stats/tasks/custom-domain.svg',
- tour: 'checklistDomainRegister',
- },
-];
-
-export function getTasks( state, siteId ) {
- const designType = getSiteOption( state, siteId, 'design_type' );
-
- if ( designType === 'blog' ) {
- return tasks;
- }
-
- return tasks.filter( task => {
- return task.id !== 'avatar_uploaded' && task.id !== 'post_published';
- } );
-}
-
-export function launchTask( { task, location, requestTour, siteSlug, track } ) {
- const checklist_name = 'new_blog';
- const url = task.url && task.url.replace( '$siteSlug', siteSlug );
- const tour = task.tour;
-
- if ( task.completed ) {
- if ( url ) {
- page( url );
- }
- return;
- }
-
- if ( ! tour && ! url ) {
- return;
- }
-
- track( 'calypso_checklist_task_start', {
- checklist_name,
- step_name: task.id,
- location,
- } );
-
- if ( url ) {
- page( url );
- }
-
- if ( tour && isDesktop() ) {
- requestTour( tour );
- }
-}
-
-export function getTaskUrls( posts ) {
- const urls = {};
- const firstPost = find( posts, { type: 'post' } );
- const contactPage = find( posts, post => {
- return (
- post.type === 'page' &&
- find( post.metadata, { key: '_headstart_post', value: '_hs_contact_page' } )
- );
- } );
-
- if ( firstPost ) {
- urls.post_published = '/post/$siteSlug/' + firstPost.ID;
- }
-
- if ( contactPage ) {
- urls.contact_page_updated = '/post/$siteSlug/' + contactPage.ID;
- }
-
- return urls;
-}
diff --git a/client/my-sites/checklist/test/util.js b/client/my-sites/checklist/test/util.js
deleted file mode 100644
index fd1f21949850..000000000000
--- a/client/my-sites/checklist/test/util.js
+++ /dev/null
@@ -1,80 +0,0 @@
-/** @format */
-
-/**
- * Internal dependencies
- */
-import { mergeObjectIntoArrayById } from '../util';
-
-describe( 'mergeObjectIntoArrayById', () => {
- test( 'should produce a new array', () => {
- const arr = [ { id: 'a', prop: 'prop' } ];
- const obj = { a: { newProp: 'newProp' } };
- expect( mergeObjectIntoArrayById( arr, obj ) ).not.toBe( arr );
- } );
-
- test( 'should produce a new object when merging', () => {
- const arr = [ { id: 'a', prop: 'prop' } ];
- const obj = { a: { newProp: 'newProp' } };
-
- const result = mergeObjectIntoArrayById( arr, obj );
- expect( result[ 0 ] ).not.toBe( arr[ 0 ] );
- expect( result[ 0 ] ).not.toBe( obj );
- } );
-
- test( 'should not replace unchanged objects', () => {
- const arr = [ { id: 'a', prop: 'prop' }, { id: 'b' } ];
- const obj = { a: { newProp: 'newProp' } };
-
- expect( mergeObjectIntoArrayById( arr, obj )[ 1 ] ).toBe( arr[ 1 ] );
- } );
-
- test( 'should overwrite existing props', () => {
- const arr = [ { id: 'a', prop: 'prop' } ];
- const obj = { a: { prop: 'updated' } };
-
- expect( mergeObjectIntoArrayById( arr, obj ) ).toEqual( [
- {
- id: 'a',
- prop: 'updated',
- },
- ] );
- } );
-
- test( 'should keep existing props', () => {
- const arr = [ { id: 'a', prop: 'prop', untouched: 'stay-the-same' } ];
- const obj = { a: { prop: 'updated' } };
-
- expect( mergeObjectIntoArrayById( arr, obj ) ).toEqual( [
- {
- id: 'a',
- prop: 'updated',
- untouched: 'stay-the-same',
- },
- ] );
- } );
-
- test( 'should add new props', () => {
- const arr = [ { id: 'a', prop: 'prop' } ];
- const obj = { a: { newProp: 'add me' } };
-
- expect( mergeObjectIntoArrayById( arr, obj ) ).toEqual( [
- {
- id: 'a',
- prop: 'prop',
- newProp: 'add me',
- },
- ] );
- } );
-
- test( 'should ignore object keys not present in the array', () => {
- const arr = [ { id: 'a', prop: 'prop' } ];
- const obj = { c: { ignore: 'me' } };
-
- expect( mergeObjectIntoArrayById( arr, obj ) ).toEqual( [
- {
- id: 'a',
- prop: 'prop',
- },
- ] );
- } );
-} );
diff --git a/client/my-sites/checklist/util.js b/client/my-sites/checklist/util.js
deleted file mode 100644
index 499f3cde6ba6..000000000000
--- a/client/my-sites/checklist/util.js
+++ /dev/null
@@ -1,26 +0,0 @@
-/** @format */
-
-/**
- * Update an array of objects with an id property with an object of objects keyed by id.
- *
- * Given an array of objects with an id property, update and add properties from the provided object
- * keyed by id.
- *
- * @example
- * mergeObjectIntoArrayById(
- * [ { id: 'a', prop: 'stale', keep: 'keep' } ],
- * {
- * a: { prop: 'fresh', add: 'new' }
- * }
- * )
- * // results in…
- * [ { id: 'a', prop: 'fresh', keep: 'keep', add: 'new' } ],
- *
- * @param {Array