2019-03-28 06:09:44 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2021-01-27 18:40:02 +00:00
|
|
|
import { __ } from '@wordpress/i18n';
|
2021-04-16 13:29:54 +00:00
|
|
|
import { MenuGroup, MenuItem } from '@wordpress/components';
|
2020-12-03 21:16:04 +00:00
|
|
|
import { Component } from '@wordpress/element';
|
2019-08-01 18:09:08 +00:00
|
|
|
import { compose } from '@wordpress/compose';
|
2020-08-05 00:14:56 +00:00
|
|
|
import { withDispatch, withSelect } from '@wordpress/data';
|
2021-04-16 13:29:54 +00:00
|
|
|
import { check } from '@wordpress/icons';
|
2020-06-10 23:49:27 +00:00
|
|
|
import {
|
|
|
|
ONBOARDING_STORE_NAME,
|
2020-12-03 21:16:04 +00:00
|
|
|
OPTIONS_STORE_NAME,
|
|
|
|
PLUGINS_STORE_NAME,
|
2020-08-03 08:22:25 +00:00
|
|
|
SETTINGS_STORE_NAME,
|
2020-06-10 23:49:27 +00:00
|
|
|
} from '@woocommerce/data';
|
2020-08-20 04:59:52 +00:00
|
|
|
import { recordEvent } from '@woocommerce/tracks';
|
2019-03-28 06:09:44 +00:00
|
|
|
|
|
|
|
/**
|
2019-11-14 14:35:55 +00:00
|
|
|
* Internal dependencies
|
2019-03-28 06:09:44 +00:00
|
|
|
*/
|
|
|
|
import './style.scss';
|
2020-08-13 02:05:22 +00:00
|
|
|
import CartModal from '../dashboard/components/cart-modal';
|
2020-12-03 21:16:04 +00:00
|
|
|
import { getAllTasks } from './tasks';
|
2020-08-13 02:05:22 +00:00
|
|
|
import { getCountryCode } from '../dashboard/utils';
|
2020-12-03 21:16:04 +00:00
|
|
|
import TaskList from './list';
|
2021-04-16 13:29:54 +00:00
|
|
|
import { DisplayOption } from '../header/activity-panel/display-options';
|
2019-09-23 21:47:08 +00:00
|
|
|
|
2020-11-06 17:53:03 +00:00
|
|
|
export class TaskDashboard extends Component {
|
2019-11-01 04:00:57 +00:00
|
|
|
constructor( props ) {
|
|
|
|
super( props );
|
|
|
|
this.state = {
|
2019-12-31 08:50:45 +00:00
|
|
|
isCartModalOpen: false,
|
2019-11-01 04:00:57 +00:00
|
|
|
};
|
2021-04-16 13:29:54 +00:00
|
|
|
|
|
|
|
this.toggleExtensionTaskList = this.toggleExtensionTaskList.bind(
|
|
|
|
this
|
|
|
|
);
|
2019-11-01 04:00:57 +00:00
|
|
|
}
|
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' );
|
|
|
|
}
|
|
|
|
|
2020-12-18 13:17:07 +00:00
|
|
|
getTaskStartedCount = ( taskName ) => {
|
|
|
|
const { userPreferences } = this.props;
|
|
|
|
const trackedStartedTasks =
|
|
|
|
userPreferences.task_list_tracked_started_tasks;
|
|
|
|
if ( ! trackedStartedTasks || ! trackedStartedTasks[ taskName ] ) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return trackedStartedTasks[ taskName ];
|
|
|
|
};
|
|
|
|
|
|
|
|
updateTrackStartedCount = ( taskName, newCount ) => {
|
|
|
|
const { userPreferences } = this.props;
|
|
|
|
const trackedStartedTasks =
|
|
|
|
userPreferences.task_list_tracked_started_tasks || {};
|
|
|
|
userPreferences.updateUserPreferences( {
|
|
|
|
task_list_tracked_started_tasks: {
|
|
|
|
...( trackedStartedTasks || {} ),
|
|
|
|
[ taskName ]: newCount,
|
|
|
|
},
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
2021-01-07 13:27:12 +00:00
|
|
|
isTaskCompleted = ( taskName ) => {
|
|
|
|
const { trackedCompletedTasks } = this.props;
|
|
|
|
if ( ! trackedCompletedTasks ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return trackedCompletedTasks.includes( taskName );
|
|
|
|
};
|
|
|
|
|
2020-12-18 13:17:07 +00:00
|
|
|
onTaskSelect = ( taskName ) => {
|
|
|
|
const trackStartedCount = this.getTaskStartedCount( taskName );
|
|
|
|
recordEvent( 'tasklist_click', {
|
|
|
|
task_name: taskName,
|
|
|
|
} );
|
2021-01-07 13:27:12 +00:00
|
|
|
if ( ! this.isTaskCompleted( taskName ) ) {
|
|
|
|
this.updateTrackStartedCount( taskName, trackStartedCount + 1 );
|
|
|
|
}
|
2020-12-18 13:17:07 +00:00
|
|
|
};
|
|
|
|
|
2021-04-16 13:29:54 +00:00
|
|
|
toggleExtensionTaskList = () => {
|
|
|
|
const { isExtendedTaskListHidden, updateOptions } = this.props;
|
|
|
|
const newValue = ! isExtendedTaskListHidden;
|
|
|
|
|
|
|
|
recordEvent(
|
|
|
|
newValue ? 'extended_tasklist_hide' : 'extended_tasklist_show'
|
|
|
|
);
|
|
|
|
updateOptions( {
|
|
|
|
woocommerce_extended_task_list_hidden: newValue ? 'yes' : 'no',
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
2020-07-20 06:19:01 +00:00
|
|
|
getAllTasks() {
|
2020-05-25 00:26:08 +00:00
|
|
|
const {
|
2020-07-14 01:40:56 +00:00
|
|
|
activePlugins,
|
2020-08-24 13:20:57 +00:00
|
|
|
countryCode,
|
2020-07-14 01:40:56 +00:00
|
|
|
createNotice,
|
2020-08-24 13:20:57 +00:00
|
|
|
installAndActivatePlugins,
|
|
|
|
installedPlugins,
|
2020-07-14 01:40:56 +00:00
|
|
|
isJetpackConnected,
|
2020-08-24 13:20:57 +00:00
|
|
|
onboardingStatus,
|
|
|
|
profileItems,
|
|
|
|
query,
|
2020-05-25 00:26:08 +00:00
|
|
|
} = this.props;
|
2019-12-31 08:50:45 +00:00
|
|
|
|
|
|
|
return getAllTasks( {
|
2020-08-24 13:20:57 +00:00
|
|
|
activePlugins,
|
2020-08-03 08:22:25 +00:00
|
|
|
countryCode,
|
2020-08-24 13:20:57 +00:00
|
|
|
createNotice,
|
|
|
|
installAndActivatePlugins,
|
|
|
|
installedPlugins,
|
|
|
|
isJetpackConnected,
|
|
|
|
onboardingStatus,
|
2019-12-31 08:50:45 +00:00
|
|
|
profileItems,
|
2020-02-14 02:23:21 +00:00
|
|
|
query,
|
2019-12-31 08:50:45 +00:00
|
|
|
toggleCartModal: this.toggleCartModal.bind( this ),
|
2020-12-18 13:17:07 +00:00
|
|
|
onTaskSelect: this.onTaskSelect,
|
2020-07-20 06:19:01 +00:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2019-12-31 08:50:45 +00:00
|
|
|
toggleCartModal() {
|
2020-01-02 02:36:25 +00:00
|
|
|
const { isCartModalOpen } = this.state;
|
|
|
|
|
|
|
|
if ( ! isCartModalOpen ) {
|
|
|
|
recordEvent( 'tasklist_purchase_extensions' );
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setState( { isCartModalOpen: ! isCartModalOpen } );
|
2019-12-31 08:50:45 +00:00
|
|
|
}
|
|
|
|
|
2019-03-28 06:09:44 +00:00
|
|
|
render() {
|
2020-12-03 21:16:04 +00:00
|
|
|
const {
|
|
|
|
dismissedTasks,
|
|
|
|
isExtendedTaskListComplete,
|
|
|
|
isExtendedTaskListHidden,
|
2021-01-14 16:59:31 +00:00
|
|
|
isSetupTaskListHidden,
|
2020-12-03 21:16:04 +00:00
|
|
|
isTaskListComplete,
|
|
|
|
query,
|
|
|
|
trackedCompletedTasks,
|
|
|
|
} = this.props;
|
2020-08-05 00:14:56 +00:00
|
|
|
const { isCartModalOpen } = this.state;
|
2020-12-03 21:16:04 +00:00
|
|
|
const allTasks = this.getAllTasks();
|
2021-04-16 13:29:54 +00:00
|
|
|
const { extension, setup: setupTasks } = allTasks;
|
2021-01-14 16:59:31 +00:00
|
|
|
const { task } = query;
|
2019-07-19 02:54:38 +00:00
|
|
|
|
2021-04-16 13:29:54 +00:00
|
|
|
const extensionTasks =
|
|
|
|
Array.isArray( extension ) &&
|
|
|
|
extension.sort( ( a, b ) => {
|
|
|
|
if ( Boolean( a.completed ) === Boolean( b.completed ) ) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return a.completed ? 1 : -1;
|
|
|
|
} );
|
|
|
|
|
2019-03-28 06:09:44 +00:00
|
|
|
return (
|
2020-11-04 21:48:26 +00:00
|
|
|
<>
|
2021-01-14 16:59:31 +00:00
|
|
|
{ setupTasks && ( ! isSetupTaskListHidden || task ) && (
|
2020-12-03 21:16:04 +00:00
|
|
|
<TaskList
|
2020-12-18 13:17:07 +00:00
|
|
|
dismissedTasks={ dismissedTasks || [] }
|
2021-01-27 18:40:02 +00:00
|
|
|
isComplete={ isTaskListComplete }
|
2020-12-03 21:16:04 +00:00
|
|
|
query={ query }
|
2021-01-27 18:40:02 +00:00
|
|
|
tasks={ setupTasks }
|
2021-02-10 23:57:51 +00:00
|
|
|
title={ __(
|
|
|
|
'Get ready to start selling',
|
|
|
|
'woocommerce-admin'
|
|
|
|
) }
|
2020-12-18 13:17:07 +00:00
|
|
|
trackedCompletedTasks={ trackedCompletedTasks || [] }
|
2020-12-03 21:16:04 +00:00
|
|
|
/>
|
|
|
|
) }
|
2021-04-16 13:29:54 +00:00
|
|
|
{ extensionTasks && (
|
|
|
|
<DisplayOption>
|
|
|
|
<MenuGroup
|
|
|
|
className="woocommerce-layout__homescreen-display-options"
|
|
|
|
label={ __( 'Display', 'woocommerce-admin' ) }
|
|
|
|
>
|
|
|
|
<MenuItem
|
|
|
|
className="woocommerce-layout__homescreen-extension-tasklist-toggle"
|
|
|
|
icon={ ! isExtendedTaskListHidden && check }
|
|
|
|
isSelected={ ! isExtendedTaskListHidden }
|
|
|
|
role="menuitemcheckbox"
|
|
|
|
onClick={ this.toggleExtensionTaskList }
|
|
|
|
>
|
|
|
|
{ __(
|
|
|
|
'Show things to do next',
|
|
|
|
'woocommerce-admin'
|
|
|
|
) }
|
|
|
|
</MenuItem>
|
|
|
|
</MenuGroup>
|
|
|
|
</DisplayOption>
|
|
|
|
) }
|
2020-12-03 21:16:04 +00:00
|
|
|
{ extensionTasks && ! isExtendedTaskListHidden && (
|
|
|
|
<TaskList
|
2020-12-18 13:17:07 +00:00
|
|
|
dismissedTasks={ dismissedTasks || [] }
|
2021-01-27 18:40:02 +00:00
|
|
|
isComplete={ isExtendedTaskListComplete }
|
|
|
|
name={ 'extended_task_list' }
|
2020-12-03 21:16:04 +00:00
|
|
|
query={ query }
|
2021-01-27 18:40:02 +00:00
|
|
|
tasks={ extensionTasks }
|
2021-04-16 13:29:54 +00:00
|
|
|
title={ __( 'Things to do next', 'woocommerce-admin' ) }
|
2020-12-18 13:17:07 +00:00
|
|
|
trackedCompletedTasks={ trackedCompletedTasks || [] }
|
2020-12-03 21:16:04 +00:00
|
|
|
/>
|
|
|
|
) }
|
2019-12-31 08:50:45 +00:00
|
|
|
{ isCartModalOpen && (
|
|
|
|
<CartModal
|
|
|
|
onClose={ () => this.toggleCartModal() }
|
|
|
|
onClickPurchaseLater={ () => this.toggleCartModal() }
|
|
|
|
/>
|
|
|
|
) }
|
2020-11-04 21:48:26 +00:00
|
|
|
</>
|
2019-03-28 06:09:44 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2019-08-01 18:09:08 +00:00
|
|
|
|
|
|
|
export default compose(
|
2020-07-20 06:19:01 +00:00
|
|
|
withSelect( ( select ) => {
|
2020-08-24 13:20:57 +00:00
|
|
|
const { getProfileItems, getTasksStatus } = select(
|
|
|
|
ONBOARDING_STORE_NAME
|
|
|
|
);
|
2020-08-03 08:22:25 +00:00
|
|
|
const { getSettings } = select( SETTINGS_STORE_NAME );
|
2020-12-03 21:16:04 +00:00
|
|
|
const { getOption } = select( OPTIONS_STORE_NAME );
|
2020-05-21 17:15:08 +00:00
|
|
|
const {
|
|
|
|
getActivePlugins,
|
|
|
|
getInstalledPlugins,
|
|
|
|
isJetpackConnected,
|
|
|
|
} = select( PLUGINS_STORE_NAME );
|
2019-08-01 18:09:08 +00:00
|
|
|
const profileItems = getProfileItems();
|
2020-12-18 13:17:07 +00:00
|
|
|
|
2021-01-21 00:31:34 +00:00
|
|
|
const trackedCompletedTasks =
|
|
|
|
getOption( 'woocommerce_task_list_tracked_completed_tasks' ) || [];
|
2020-12-18 13:17:07 +00:00
|
|
|
|
2020-08-03 08:22:25 +00:00
|
|
|
const { general: generalSettings = {} } = getSettings( 'general' );
|
|
|
|
const countryCode = getCountryCode(
|
|
|
|
generalSettings.woocommerce_default_country
|
|
|
|
);
|
|
|
|
|
2020-07-14 01:40:56 +00:00
|
|
|
const activePlugins = getActivePlugins();
|
2020-05-25 00:26:08 +00:00
|
|
|
const installedPlugins = getInstalledPlugins();
|
2020-08-24 13:20:57 +00:00
|
|
|
const onboardingStatus = getTasksStatus();
|
2019-10-11 12:55:35 +00:00
|
|
|
|
|
|
|
return {
|
2020-07-20 06:19:01 +00:00
|
|
|
activePlugins,
|
2020-08-03 08:22:25 +00:00
|
|
|
countryCode,
|
2020-12-18 13:17:07 +00:00
|
|
|
dismissedTasks: getOption(
|
|
|
|
'woocommerce_task_list_dismissed_tasks'
|
|
|
|
),
|
2020-12-03 21:16:04 +00:00
|
|
|
isExtendedTaskListComplete:
|
|
|
|
getOption( 'woocommerce_extended_task_list_complete' ) ===
|
|
|
|
'yes',
|
|
|
|
isExtendedTaskListHidden:
|
|
|
|
getOption( 'woocommerce_extended_task_list_hidden' ) === 'yes',
|
2020-07-20 06:19:01 +00:00
|
|
|
isJetpackConnected: isJetpackConnected(),
|
2020-12-03 21:16:04 +00:00
|
|
|
isSetupTaskListHidden:
|
|
|
|
getOption( 'woocommerce_task_list_hidden' ) === 'yes',
|
|
|
|
isTaskListComplete:
|
|
|
|
getOption( 'woocommerce_task_list_complete' ) === 'yes',
|
2020-07-20 06:19:01 +00:00
|
|
|
installedPlugins,
|
2020-08-24 13:20:57 +00:00
|
|
|
onboardingStatus,
|
2019-10-11 12:55:35 +00:00
|
|
|
profileItems,
|
2020-12-18 13:17:07 +00:00
|
|
|
trackedCompletedTasks,
|
2019-10-11 12:55:35 +00:00
|
|
|
};
|
|
|
|
} ),
|
2020-02-14 02:23:21 +00:00
|
|
|
withDispatch( ( dispatch ) => {
|
2020-07-14 10:46:25 +00:00
|
|
|
const { createNotice } = dispatch( 'core/notices' );
|
2020-07-14 01:40:56 +00:00
|
|
|
const { installAndActivatePlugins } = dispatch( PLUGINS_STORE_NAME );
|
2021-04-16 13:29:54 +00:00
|
|
|
const { updateOptions } = dispatch( OPTIONS_STORE_NAME );
|
2020-07-14 01:40:56 +00:00
|
|
|
|
2019-10-11 12:55:35 +00:00
|
|
|
return {
|
2020-07-14 10:46:25 +00:00
|
|
|
createNotice,
|
2020-07-14 01:40:56 +00:00
|
|
|
installAndActivatePlugins,
|
2021-04-16 13:29:54 +00:00
|
|
|
updateOptions,
|
2019-10-11 12:55:35 +00:00
|
|
|
};
|
2019-08-01 18:09:08 +00:00
|
|
|
} )
|
|
|
|
)( TaskDashboard );
|