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

Checklist: Update task url based on headstarted posts #26758

Merged
merged 1 commit into from
Aug 20, 2018
Merged
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
14 changes: 12 additions & 2 deletions client/my-sites/checklist/checklist-show/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ 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 { launchTask, tasks } from '../onboardingChecklist';
import { getTaskUrls, launchTask, tasks } from '../onboardingChecklist';
import { loadTrackingTool, 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 {
componentDidMount() {
Expand All @@ -33,11 +35,12 @@ class ChecklistShow extends PureComponent {
}

handleTaskStart = task => () => {
const { requestTour, siteSlug, track } = this.props;
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,
Expand All @@ -61,6 +64,12 @@ class ChecklistShow extends PureComponent {
return (
<Fragment>
{ siteId && <QuerySiteChecklist siteId={ siteId } /> }
{ siteId && (
<QueryPosts
siteId={ siteId }
query={ { type: 'any', number: 10, order_by: 'ID', order: 'ASC' } }
/>
) }
<Checklist isPlaceholder={ ! taskStatuses }>
{ tasks.map( task => (
<Task
Expand Down Expand Up @@ -90,6 +99,7 @@ const mapStateToProps = state => {
siteId,
siteSlug: getSiteSlug( state, siteId ),
taskStatuses: get( getSiteChecklist( state, siteId ), [ 'tasks' ] ),
taskUrls: getTaskUrls( getSitePosts( state, siteId ) ),
};
};

Expand Down
22 changes: 22 additions & 0 deletions client/my-sites/checklist/onboardingChecklist.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import page from 'page';
import { isDesktop } from 'lib/viewport';
import { translate } from 'i18n-calypso';
import { find } from 'lodash';

export const tasks = [
{
Expand Down Expand Up @@ -139,3 +140,24 @@ export function launchTask( { task, location, requestTour, siteSlug, track } ) {
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;
}
18 changes: 15 additions & 3 deletions client/my-sites/stats/checklist-banner/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ import ProgressBar from 'components/progress-bar';
import QuerySiteChecklist from 'components/data/query-site-checklist';
import getSiteChecklist from 'state/selectors/get-site-checklist';
import { getSite, getSiteSlug } from 'state/sites/selectors';
import { launchTask, tasks } from 'my-sites/checklist/onboardingChecklist';
import { getTaskUrls, launchTask, tasks } from 'my-sites/checklist/onboardingChecklist';
import ChecklistShowShare from 'my-sites/checklist/share';
import { recordTracksEvent } from 'state/analytics/actions';
import { requestGuidedTour } from 'state/ui/guided-tours/actions';
import QueryPosts from 'components/data/query-posts';
import { getSitePosts } from 'state/posts/selectors';

const storeKeyForNeverShow = 'sitesNeverShowChecklistBanner';

Expand All @@ -44,11 +46,14 @@ export class ChecklistBanner extends Component {
};

handleClick = () => {
const { requestTour, track, siteSlug } = this.props;
const { requestTour, track, siteSlug, taskUrls } = this.props;
const task = this.getTask();

launchTask( {
task,
task: {
...task,
url: taskUrls[ task.id ] || task.url,
},
location: 'checklist_banner',
requestTour,
siteSlug,
Expand Down Expand Up @@ -146,6 +151,12 @@ export class ChecklistBanner extends Component {
return (
<Card className="checklist-banner">
{ siteId && <QuerySiteChecklist siteId={ siteId } /> }
{ siteId && (
<QueryPosts
siteId={ siteId }
query={ { type: 'any', number: 10, order_by: 'ID', order: 'ASC' } }
/>
) }
<div className="checklist-banner__gauge">
<span className="checklist-banner__gauge-additional-text">{ translate( 'setup' ) }</span>
<Gauge
Expand Down Expand Up @@ -202,6 +213,7 @@ const mapStateToProps = ( state, { siteId } ) => {
siteDesignType,
siteSlug,
taskStatuses,
taskUrls: getTaskUrls( getSitePosts( state, siteId ) ),
};
};

Expand Down