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';
|
|
|
|
import { check } from '@wordpress/icons';
|
2021-04-27 15:23:34 +00:00
|
|
|
import { useState, useEffect } from '@wordpress/element';
|
|
|
|
import { useDispatch, useSelect } from '@wordpress/data';
|
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';
|
2021-06-01 18:43:17 +00:00
|
|
|
import { useExperiment } from '@woocommerce/explat';
|
2020-08-20 04:59:52 +00:00
|
|
|
import { recordEvent } from '@woocommerce/tracks';
|
2021-06-09 13:56:45 +00:00
|
|
|
import { ScrollTo } from '@woocommerce/components';
|
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';
|
2021-05-05 17:43:46 +00:00
|
|
|
import { getAllTasks, taskSort } from './tasks';
|
2020-08-13 02:05:22 +00:00
|
|
|
import { getCountryCode } from '../dashboard/utils';
|
2021-05-03 17:13:47 +00:00
|
|
|
import TaskList from './task-list';
|
2021-04-16 13:29:54 +00:00
|
|
|
import { DisplayOption } from '../header/activity-panel/display-options';
|
2021-04-27 15:23:34 +00:00
|
|
|
import { TaskStep } from './task-step';
|
2021-06-01 18:43:17 +00:00
|
|
|
import TaskListPlaceholder from './placeholder';
|
2019-09-23 21:47:08 +00:00
|
|
|
|
2021-04-27 15:23:34 +00:00
|
|
|
const taskDashboardSelect = ( select ) => {
|
|
|
|
const { getProfileItems, getTasksStatus } = select( ONBOARDING_STORE_NAME );
|
|
|
|
const { getSettings } = select( SETTINGS_STORE_NAME );
|
|
|
|
const { getOption } = select( OPTIONS_STORE_NAME );
|
|
|
|
const {
|
|
|
|
getActivePlugins,
|
|
|
|
getInstalledPlugins,
|
|
|
|
isJetpackConnected,
|
|
|
|
} = select( PLUGINS_STORE_NAME );
|
|
|
|
const profileItems = getProfileItems();
|
2021-04-16 13:29:54 +00:00
|
|
|
|
2021-04-27 15:23:34 +00:00
|
|
|
const trackedCompletedTasks =
|
|
|
|
getOption( 'woocommerce_task_list_tracked_completed_tasks' ) || [];
|
|
|
|
|
|
|
|
const { general: generalSettings = {} } = getSettings( 'general' );
|
|
|
|
const countryCode = getCountryCode(
|
|
|
|
generalSettings.woocommerce_default_country
|
|
|
|
);
|
2021-06-01 18:04:21 +00:00
|
|
|
const {
|
|
|
|
woocommerce_store_address: storeAddress,
|
|
|
|
woocommerce_default_country: defaultCountry,
|
|
|
|
woocommerce_store_postcode: storePostCode,
|
|
|
|
} = generalSettings;
|
|
|
|
const hasCompleteAddress = Boolean(
|
|
|
|
storeAddress && defaultCountry && storePostCode
|
|
|
|
);
|
2021-04-27 15:23:34 +00:00
|
|
|
|
|
|
|
const activePlugins = getActivePlugins();
|
|
|
|
const installedPlugins = getInstalledPlugins();
|
|
|
|
const onboardingStatus = getTasksStatus();
|
|
|
|
|
|
|
|
return {
|
|
|
|
activePlugins,
|
|
|
|
countryCode,
|
|
|
|
dismissedTasks: getOption( 'woocommerce_task_list_dismissed_tasks' ),
|
2021-06-03 21:44:05 +00:00
|
|
|
remindMeLaterTasks: getOption(
|
|
|
|
'woocommerce_task_list_remind_me_later_tasks'
|
|
|
|
),
|
2021-04-27 15:23:34 +00:00
|
|
|
isExtendedTaskListComplete:
|
|
|
|
getOption( 'woocommerce_extended_task_list_complete' ) === 'yes',
|
|
|
|
isExtendedTaskListHidden:
|
|
|
|
getOption( 'woocommerce_extended_task_list_hidden' ) === 'yes',
|
|
|
|
isJetpackConnected: isJetpackConnected(),
|
|
|
|
isSetupTaskListHidden:
|
|
|
|
getOption( 'woocommerce_task_list_hidden' ) === 'yes',
|
|
|
|
isTaskListComplete:
|
|
|
|
getOption( 'woocommerce_task_list_complete' ) === 'yes',
|
|
|
|
installedPlugins,
|
|
|
|
onboardingStatus,
|
|
|
|
profileItems,
|
|
|
|
trackedCompletedTasks,
|
2021-06-01 18:04:21 +00:00
|
|
|
hasCompleteAddress,
|
2021-04-27 15:23:34 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const TaskDashboard = ( { userPreferences, query } ) => {
|
|
|
|
const { createNotice } = useDispatch( 'core/notices' );
|
|
|
|
const { updateOptions } = useDispatch( OPTIONS_STORE_NAME );
|
|
|
|
const { installAndActivatePlugins } = useDispatch( PLUGINS_STORE_NAME );
|
|
|
|
const {
|
|
|
|
trackedCompletedTasks,
|
|
|
|
activePlugins,
|
|
|
|
countryCode,
|
|
|
|
installedPlugins,
|
|
|
|
isJetpackConnected,
|
|
|
|
onboardingStatus,
|
|
|
|
profileItems,
|
|
|
|
isSetupTaskListHidden,
|
|
|
|
dismissedTasks,
|
2021-06-03 21:44:05 +00:00
|
|
|
remindMeLaterTasks,
|
2021-04-27 15:23:34 +00:00
|
|
|
isTaskListComplete,
|
|
|
|
isExtendedTaskListHidden,
|
|
|
|
isExtendedTaskListComplete,
|
2021-06-01 18:04:21 +00:00
|
|
|
hasCompleteAddress,
|
2021-04-27 15:23:34 +00:00
|
|
|
} = useSelect( taskDashboardSelect );
|
|
|
|
|
|
|
|
const [ isCartModalOpen, setIsCartModalOpen ] = useState( false );
|
2021-06-01 18:43:17 +00:00
|
|
|
const [ isLoadingExperiment, experimentAssignment ] = useExperiment(
|
|
|
|
'woocommerce_tasklist_progression'
|
|
|
|
);
|
2021-04-27 15:23:34 +00:00
|
|
|
|
|
|
|
useEffect( () => {
|
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' );
|
2021-04-27 15:23:34 +00:00
|
|
|
}, [] );
|
2019-07-18 10:11:21 +00:00
|
|
|
|
2021-04-27 15:23:34 +00:00
|
|
|
const getTaskStartedCount = ( taskName ) => {
|
2020-12-18 13:17:07 +00:00
|
|
|
const trackedStartedTasks =
|
|
|
|
userPreferences.task_list_tracked_started_tasks;
|
|
|
|
if ( ! trackedStartedTasks || ! trackedStartedTasks[ taskName ] ) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return trackedStartedTasks[ taskName ];
|
|
|
|
};
|
|
|
|
|
2021-04-27 15:23:34 +00:00
|
|
|
const updateTrackStartedCount = ( taskName, newCount ) => {
|
2020-12-18 13:17:07 +00:00
|
|
|
const trackedStartedTasks =
|
|
|
|
userPreferences.task_list_tracked_started_tasks || {};
|
|
|
|
userPreferences.updateUserPreferences( {
|
|
|
|
task_list_tracked_started_tasks: {
|
|
|
|
...( trackedStartedTasks || {} ),
|
|
|
|
[ taskName ]: newCount,
|
|
|
|
},
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
2021-04-27 15:23:34 +00:00
|
|
|
const isTaskCompleted = ( taskName ) => {
|
2021-01-07 13:27:12 +00:00
|
|
|
if ( ! trackedCompletedTasks ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return trackedCompletedTasks.includes( taskName );
|
|
|
|
};
|
|
|
|
|
2021-04-27 15:23:34 +00:00
|
|
|
const onTaskSelect = ( taskName ) => {
|
|
|
|
const trackStartedCount = getTaskStartedCount( taskName );
|
2020-12-18 13:17:07 +00:00
|
|
|
recordEvent( 'tasklist_click', {
|
|
|
|
task_name: taskName,
|
|
|
|
} );
|
2021-04-27 15:23:34 +00:00
|
|
|
if ( ! isTaskCompleted( taskName ) ) {
|
|
|
|
updateTrackStartedCount( taskName, trackStartedCount + 1 );
|
2021-01-07 13:27:12 +00:00
|
|
|
}
|
2020-12-18 13:17:07 +00:00
|
|
|
};
|
|
|
|
|
2021-04-27 15:23:34 +00:00
|
|
|
const toggleExtensionTaskList = () => {
|
2021-04-16 13:29:54 +00:00
|
|
|
const newValue = ! isExtendedTaskListHidden;
|
|
|
|
|
|
|
|
recordEvent(
|
|
|
|
newValue ? 'extended_tasklist_hide' : 'extended_tasklist_show'
|
|
|
|
);
|
|
|
|
updateOptions( {
|
|
|
|
woocommerce_extended_task_list_hidden: newValue ? 'yes' : 'no',
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
2021-04-27 15:23:34 +00:00
|
|
|
const toggleCartModal = () => {
|
2020-01-02 02:36:25 +00:00
|
|
|
if ( ! isCartModalOpen ) {
|
|
|
|
recordEvent( 'tasklist_purchase_extensions' );
|
|
|
|
}
|
|
|
|
|
2021-04-27 15:23:34 +00:00
|
|
|
setIsCartModalOpen( ! isCartModalOpen );
|
|
|
|
};
|
2019-12-31 08:50:45 +00:00
|
|
|
|
2021-04-27 15:23:34 +00:00
|
|
|
const getCurrentTask = ( tasks ) => {
|
2021-01-14 16:59:31 +00:00
|
|
|
const { task } = query;
|
2021-04-27 15:23:34 +00:00
|
|
|
const currentTask = tasks.find( ( s ) => s.key === task );
|
2019-07-19 02:54:38 +00:00
|
|
|
|
2021-04-27 15:23:34 +00:00
|
|
|
if ( ! currentTask ) {
|
|
|
|
return null;
|
|
|
|
}
|
2021-04-16 13:29:54 +00:00
|
|
|
|
2021-04-27 15:23:34 +00:00
|
|
|
return currentTask;
|
|
|
|
};
|
2021-04-16 13:29:54 +00:00
|
|
|
|
2021-06-09 13:56:45 +00:00
|
|
|
const getExtendedTaskList = ( extensionTasks ) => {
|
|
|
|
return (
|
|
|
|
<TaskList
|
|
|
|
name="extended_task_list"
|
|
|
|
eventName="extended_tasklist"
|
|
|
|
collapsible
|
|
|
|
dismissedTasks={ dismissedTasks || [] }
|
|
|
|
remindMeLaterTasks={ remindMeLaterTasks || [] }
|
|
|
|
isComplete={ isExtendedTaskListComplete }
|
|
|
|
query={ query }
|
|
|
|
tasks={ extensionTasks }
|
|
|
|
title={ __( 'Things to do next', 'woocommerce-admin' ) }
|
|
|
|
trackedCompletedTasks={ trackedCompletedTasks || [] }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2021-04-27 15:23:34 +00:00
|
|
|
const allTasks = getAllTasks( {
|
|
|
|
activePlugins,
|
|
|
|
countryCode,
|
|
|
|
createNotice,
|
|
|
|
installAndActivatePlugins,
|
|
|
|
installedPlugins,
|
|
|
|
isJetpackConnected,
|
|
|
|
onboardingStatus,
|
|
|
|
profileItems,
|
|
|
|
query,
|
|
|
|
toggleCartModal,
|
|
|
|
onTaskSelect,
|
2021-06-01 18:04:21 +00:00
|
|
|
hasCompleteAddress,
|
2021-04-27 15:23:34 +00:00
|
|
|
} );
|
2019-08-01 18:09:08 +00:00
|
|
|
|
2021-04-27 15:23:34 +00:00
|
|
|
const { extension, setup: setupTasks } = allTasks;
|
|
|
|
const { task } = query;
|
2020-12-18 13:17:07 +00:00
|
|
|
|
2021-04-27 15:23:34 +00:00
|
|
|
const extensionTasks =
|
2021-05-05 17:43:46 +00:00
|
|
|
Array.isArray( extension ) && extension.sort( taskSort );
|
2020-08-03 08:22:25 +00:00
|
|
|
|
2021-04-27 15:23:34 +00:00
|
|
|
const currentTask = getCurrentTask( [
|
|
|
|
...( extensionTasks || [] ),
|
|
|
|
...( setupTasks || [] ),
|
|
|
|
] );
|
|
|
|
|
|
|
|
if ( task && ! currentTask ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
if ( currentTask ) {
|
|
|
|
return (
|
|
|
|
<TaskStep taskContainer={ currentTask.container } query={ query } />
|
|
|
|
);
|
|
|
|
}
|
2019-10-11 12:55:35 +00:00
|
|
|
|
2021-06-09 13:56:45 +00:00
|
|
|
const scrollToExtendedList =
|
|
|
|
window.location.hash.substr( 1 ) === 'extended_task_list';
|
|
|
|
|
2021-04-27 15:23:34 +00:00
|
|
|
return (
|
|
|
|
<>
|
2021-06-01 18:43:17 +00:00
|
|
|
{ setupTasks &&
|
|
|
|
( ! isSetupTaskListHidden || task ) &&
|
|
|
|
( isLoadingExperiment ? (
|
|
|
|
<TaskListPlaceholder />
|
|
|
|
) : (
|
|
|
|
<TaskList
|
|
|
|
name="task_list"
|
|
|
|
eventName="tasklist"
|
|
|
|
expandingItems={
|
|
|
|
experimentAssignment?.variationName === 'treatment'
|
|
|
|
}
|
|
|
|
dismissedTasks={ dismissedTasks || [] }
|
2021-06-03 21:44:05 +00:00
|
|
|
remindMeLaterTasks={ remindMeLaterTasks || [] }
|
2021-06-01 18:43:17 +00:00
|
|
|
isComplete={ isTaskListComplete }
|
|
|
|
query={ query }
|
|
|
|
tasks={ setupTasks }
|
2021-06-07 15:33:40 +00:00
|
|
|
title={ __(
|
|
|
|
'Get ready to start selling',
|
|
|
|
'woocommerce-admin'
|
|
|
|
) }
|
2021-06-01 18:43:17 +00:00
|
|
|
trackedCompletedTasks={ trackedCompletedTasks || [] }
|
|
|
|
onComplete={ () =>
|
|
|
|
updateOptions( {
|
|
|
|
woocommerce_default_homepage_layout:
|
|
|
|
'two_columns',
|
|
|
|
} )
|
|
|
|
}
|
|
|
|
onHide={ () =>
|
|
|
|
updateOptions( {
|
|
|
|
woocommerce_task_list_prompt_shown: true,
|
|
|
|
woocommerce_default_homepage_layout:
|
|
|
|
'two_columns',
|
|
|
|
} )
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
) ) }
|
2021-04-27 15:23:34 +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={ toggleExtensionTaskList }
|
|
|
|
>
|
|
|
|
{ __(
|
|
|
|
'Show things to do next',
|
|
|
|
'woocommerce-admin'
|
|
|
|
) }
|
|
|
|
</MenuItem>
|
|
|
|
</MenuGroup>
|
|
|
|
</DisplayOption>
|
|
|
|
) }
|
2021-06-09 13:56:45 +00:00
|
|
|
{ extensionTasks &&
|
|
|
|
! isExtendedTaskListHidden &&
|
|
|
|
( scrollToExtendedList ? (
|
|
|
|
<ScrollTo offset="-20">
|
|
|
|
{ getExtendedTaskList( extensionTasks ) }
|
|
|
|
</ScrollTo>
|
|
|
|
) : (
|
|
|
|
getExtendedTaskList( extensionTasks )
|
|
|
|
) ) }
|
2021-04-27 15:23:34 +00:00
|
|
|
{ isCartModalOpen && (
|
|
|
|
<CartModal
|
|
|
|
onClose={ () => toggleCartModal() }
|
|
|
|
onClickPurchaseLater={ () => toggleCartModal() }
|
|
|
|
/>
|
|
|
|
) }
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
2020-07-14 01:40:56 +00:00
|
|
|
|
2021-04-27 15:23:34 +00:00
|
|
|
export default TaskDashboard;
|