2019-03-28 06:09:44 +00:00
|
|
|
|
/** @format */
|
|
|
|
|
/**
|
|
|
|
|
* External dependencies
|
|
|
|
|
*/
|
|
|
|
|
import { __ } from '@wordpress/i18n';
|
2019-07-18 10:11:21 +00:00
|
|
|
|
import { Component, Fragment } from '@wordpress/element';
|
2019-10-03 16:03:29 +00:00
|
|
|
|
import { filter, get } from 'lodash';
|
2019-08-01 18:09:08 +00:00
|
|
|
|
import { compose } from '@wordpress/compose';
|
2019-10-11 12:55:35 +00:00
|
|
|
|
import classNames from 'classnames';
|
|
|
|
|
import { Snackbar, Icon, Button } from '@wordpress/components';
|
|
|
|
|
import { withDispatch } from '@wordpress/data';
|
2019-07-18 10:11:21 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* WooCommerce dependencies
|
|
|
|
|
*/
|
2019-10-11 12:55:35 +00:00
|
|
|
|
import { Card, List, MenuItem, EllipsisMenu } from '@woocommerce/components';
|
2019-07-19 02:54:38 +00:00
|
|
|
|
import { updateQueryString } from '@woocommerce/navigation';
|
2019-03-28 06:09:44 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Internal depdencies
|
|
|
|
|
*/
|
|
|
|
|
import './style.scss';
|
2019-08-01 18:09:08 +00:00
|
|
|
|
import withSelect from 'wc-api/with-select';
|
2019-10-07 20:27:34 +00:00
|
|
|
|
import { recordEvent } from 'lib/tracks';
|
2019-10-11 12:55:35 +00:00
|
|
|
|
import { getTasks } from './tasks';
|
2019-09-23 21:47:08 +00:00
|
|
|
|
|
2019-08-01 18:09:08 +00:00
|
|
|
|
class TaskDashboard extends Component {
|
2019-07-18 10:11:21 +00:00
|
|
|
|
componentDidMount() {
|
2019-08-21 05:58:47 +00:00
|
|
|
|
document.body.classList.add( 'woocommerce-onboarding' );
|
2019-07-18 10:11:21 +00:00
|
|
|
|
document.body.classList.add( 'woocommerce-task-dashboard__body' );
|
2019-10-07 20:27:34 +00:00
|
|
|
|
|
|
|
|
|
this.recordEvent();
|
2019-10-21 00:33:46 +00:00
|
|
|
|
|
|
|
|
|
if ( this.props.inline ) {
|
|
|
|
|
this.props.updateOptions( {
|
|
|
|
|
woocommerce_task_list_complete: true,
|
|
|
|
|
} );
|
|
|
|
|
}
|
2019-07-18 10:11:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
2019-08-21 05:58:47 +00:00
|
|
|
|
document.body.classList.remove( 'woocommerce-onboarding' );
|
2019-07-18 10:11:21 +00:00
|
|
|
|
document.body.classList.remove( 'woocommerce-task-dashboard__body' );
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-07 20:27:34 +00:00
|
|
|
|
recordEvent() {
|
|
|
|
|
if ( this.getCurrentTask() ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const { profileItems } = this.props;
|
2019-10-11 12:55:35 +00:00
|
|
|
|
const tasks = filter( this.props.tasks, task => task.visible );
|
2019-10-07 20:27:34 +00:00
|
|
|
|
recordEvent( 'tasklist_view', {
|
|
|
|
|
number_tasks: tasks.length,
|
|
|
|
|
store_connected: profileItems.wccom_connected,
|
|
|
|
|
} );
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-11 12:55:35 +00:00
|
|
|
|
keepTaskCard() {
|
|
|
|
|
recordEvent( 'tasklist_completed', {
|
|
|
|
|
action: 'keep_card',
|
|
|
|
|
} );
|
|
|
|
|
|
|
|
|
|
this.props.updateOptions( {
|
|
|
|
|
woocommerce_task_list_prompt_shown: true,
|
|
|
|
|
} );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hideTaskCard( action ) {
|
|
|
|
|
recordEvent( 'tasklist_completed', {
|
|
|
|
|
action,
|
|
|
|
|
} );
|
|
|
|
|
this.props.updateOptions( {
|
|
|
|
|
woocommerce_task_list_hidden: 'yes',
|
|
|
|
|
woocommerce_task_list_prompt_shown: true,
|
|
|
|
|
} );
|
2019-08-01 18:09:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-19 02:54:38 +00:00
|
|
|
|
getCurrentTask() {
|
|
|
|
|
const { task } = this.props.query;
|
2019-10-11 12:55:35 +00:00
|
|
|
|
const currentTask = this.props.tasks.find( s => s.key === task );
|
2019-07-19 02:54:38 +00:00
|
|
|
|
|
|
|
|
|
if ( ! currentTask ) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return currentTask;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-11 12:55:35 +00:00
|
|
|
|
renderPrompt() {
|
|
|
|
|
if ( this.props.promptShown ) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Snackbar className="woocommerce-task-card__prompt">
|
|
|
|
|
<div>
|
|
|
|
|
<div className="woocommerce-task-card__prompt-pointer" />
|
|
|
|
|
<span>{ __( 'Is this card useful?', 'woocommerce-admin' ) }</span>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="woocommerce-task-card__prompt-actions">
|
|
|
|
|
<Button isLink onClick={ () => this.hideTaskCard( 'hide_card' ) }>
|
|
|
|
|
{ __( 'No, hide it', 'woocommerce-admin' ) }
|
|
|
|
|
</Button>
|
|
|
|
|
|
|
|
|
|
<Button isLink onClick={ () => this.keepTaskCard() }>
|
|
|
|
|
{ __( 'Yes, keep it', 'woocommerce-admin' ) }
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</Snackbar>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderMenu() {
|
|
|
|
|
return (
|
|
|
|
|
<EllipsisMenu
|
|
|
|
|
label={ __( 'Task List Options', 'woocommerce-admin' ) }
|
|
|
|
|
renderContent={ () => (
|
|
|
|
|
<div className="woocommerce-task-card__section-controls">
|
|
|
|
|
<MenuItem isClickable onInvoke={ () => this.hideTaskCard( 'remove_card' ) }>
|
|
|
|
|
<Icon icon={ 'trash' } label={ __( 'Remove block' ) } />
|
|
|
|
|
{ __( 'Remove this card', 'woocommerce-admin' ) }
|
|
|
|
|
</MenuItem>
|
|
|
|
|
</div>
|
|
|
|
|
) }
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-28 06:09:44 +00:00
|
|
|
|
render() {
|
2019-07-19 02:54:38 +00:00
|
|
|
|
const currentTask = this.getCurrentTask();
|
2019-10-11 12:55:35 +00:00
|
|
|
|
const tasks = filter( this.props.tasks, task => task.visible ).map( task => {
|
|
|
|
|
task.className = classNames( task.completed ? 'is-complete' : null, task.className );
|
|
|
|
|
task.before = task.completed ? (
|
|
|
|
|
<i className="material-icons-outlined">check_circle</i>
|
|
|
|
|
) : (
|
|
|
|
|
<i className="material-icons-outlined">{ task.icon }</i>
|
|
|
|
|
);
|
|
|
|
|
task.after = <i className="material-icons-outlined">chevron_right</i>;
|
|
|
|
|
task.onClick = () => updateQueryString( { task: task.key } );
|
|
|
|
|
return task;
|
|
|
|
|
} );
|
2019-07-19 02:54:38 +00:00
|
|
|
|
|
2019-03-28 06:09:44 +00:00
|
|
|
|
return (
|
2019-07-18 10:11:21 +00:00
|
|
|
|
<Fragment>
|
|
|
|
|
<div className="woocommerce-task-dashboard__container">
|
2019-07-19 02:54:38 +00:00
|
|
|
|
{ currentTask ? (
|
|
|
|
|
currentTask.container
|
|
|
|
|
) : (
|
2019-10-11 12:55:35 +00:00
|
|
|
|
<Fragment>
|
|
|
|
|
<Card
|
|
|
|
|
className="woocommerce-task-card"
|
|
|
|
|
title={ __( 'Set up your store and start selling', 'woocommerce-admin' ) }
|
|
|
|
|
description={ __(
|
|
|
|
|
'Below you’ll find a list of the most important steps to get your store up and running.',
|
|
|
|
|
'woocommerce-admin'
|
|
|
|
|
) }
|
|
|
|
|
menu={ this.props.inline && this.renderMenu() }
|
|
|
|
|
>
|
|
|
|
|
<List items={ tasks } />
|
|
|
|
|
</Card>
|
|
|
|
|
{ this.props.inline && this.renderPrompt() }
|
|
|
|
|
</Fragment>
|
2019-07-19 02:54:38 +00:00
|
|
|
|
) }
|
2019-03-28 06:09:44 +00:00
|
|
|
|
</div>
|
2019-07-18 10:11:21 +00:00
|
|
|
|
</Fragment>
|
2019-03-28 06:09:44 +00:00
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-08-01 18:09:08 +00:00
|
|
|
|
|
|
|
|
|
export default compose(
|
2019-10-11 12:55:35 +00:00
|
|
|
|
withSelect( ( select, props ) => {
|
2019-10-03 16:03:29 +00:00
|
|
|
|
const { getProfileItems, getOptions } = select( 'wc-api' );
|
2019-08-01 18:09:08 +00:00
|
|
|
|
const profileItems = getProfileItems();
|
2019-10-03 16:03:29 +00:00
|
|
|
|
|
2019-10-11 12:55:35 +00:00
|
|
|
|
const promptShown = get(
|
|
|
|
|
getOptions( [ 'woocommerce_task_list_prompt_shown' ] ),
|
|
|
|
|
[ 'woocommerce_task_list_prompt_shown' ],
|
2019-10-03 16:03:29 +00:00
|
|
|
|
false
|
|
|
|
|
);
|
|
|
|
|
|
2019-10-11 12:55:35 +00:00
|
|
|
|
const tasks = getTasks( {
|
|
|
|
|
profileItems,
|
|
|
|
|
options: getOptions( [ 'woocommerce_onboarding_payments' ] ),
|
|
|
|
|
query: props.query,
|
|
|
|
|
} );
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
profileItems,
|
|
|
|
|
promptShown,
|
|
|
|
|
tasks,
|
|
|
|
|
};
|
|
|
|
|
} ),
|
|
|
|
|
withDispatch( dispatch => {
|
|
|
|
|
const { updateOptions } = dispatch( 'wc-api' );
|
|
|
|
|
return {
|
|
|
|
|
updateOptions,
|
|
|
|
|
};
|
2019-08-01 18:09:08 +00:00
|
|
|
|
} )
|
|
|
|
|
)( TaskDashboard );
|