2021-10-26 04:08:05 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import { MenuGroup, MenuItem } from '@wordpress/components';
|
|
|
|
import { check } from '@wordpress/icons';
|
|
|
|
import { Fragment, useEffect } from '@wordpress/element';
|
|
|
|
import { useDispatch, useSelect } from '@wordpress/data';
|
2022-04-20 04:49:27 +00:00
|
|
|
import {
|
|
|
|
ONBOARDING_STORE_NAME,
|
|
|
|
OPTIONS_STORE_NAME,
|
|
|
|
WCDataSelector,
|
|
|
|
TaskListType,
|
2022-04-20 08:24:58 +00:00
|
|
|
TaskType,
|
2022-04-20 04:49:27 +00:00
|
|
|
} from '@woocommerce/data';
|
2021-10-26 04:08:05 +00:00
|
|
|
import { recordEvent } from '@woocommerce/tracks';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2021-12-14 16:56:42 +00:00
|
|
|
import { DisplayOption } from '~/activity-panel/display-options';
|
2021-10-26 04:08:05 +00:00
|
|
|
import { TaskList } from '../tasks/task-list';
|
|
|
|
import { TasksPlaceholder } from '../tasks/placeholder';
|
|
|
|
import '../tasks/tasks.scss';
|
|
|
|
|
|
|
|
export type TasksProps = {
|
|
|
|
query: { task?: string };
|
|
|
|
};
|
|
|
|
|
2022-02-07 00:50:20 +00:00
|
|
|
const ExtendedTask: React.FC< TasksProps > = ( { query } ) => {
|
2021-10-26 04:08:05 +00:00
|
|
|
const { hideTaskList } = useDispatch( ONBOARDING_STORE_NAME );
|
|
|
|
const { updateOptions } = useDispatch( OPTIONS_STORE_NAME );
|
2022-02-07 00:50:20 +00:00
|
|
|
const { task } = query;
|
2021-10-26 04:08:05 +00:00
|
|
|
|
2022-04-20 08:24:58 +00:00
|
|
|
const {
|
|
|
|
isResolving,
|
|
|
|
taskLists,
|
|
|
|
}: {
|
|
|
|
isResolving: boolean;
|
|
|
|
taskLists: TaskListType[];
|
|
|
|
} = useSelect( ( select: WCDataSelector ) => {
|
|
|
|
return {
|
|
|
|
isResolving: select( ONBOARDING_STORE_NAME ).isResolving(
|
|
|
|
'getTaskListsByIds'
|
|
|
|
),
|
|
|
|
taskLists: select( ONBOARDING_STORE_NAME ).getTaskListsByIds( [
|
|
|
|
'extended_two_column',
|
|
|
|
] ),
|
|
|
|
};
|
|
|
|
} );
|
2022-04-20 04:49:27 +00:00
|
|
|
const toggleTaskList = ( taskList: TaskListType ) => {
|
2021-10-26 04:08:05 +00:00
|
|
|
const { id, isHidden } = taskList;
|
|
|
|
const newValue = ! isHidden;
|
|
|
|
|
|
|
|
recordEvent(
|
|
|
|
newValue ? `${ id }_tasklist_hide` : `${ id }_tasklist_show`,
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
|
|
|
|
hideTaskList( id );
|
|
|
|
};
|
|
|
|
|
|
|
|
useEffect( () => {
|
|
|
|
updateOptions( {
|
|
|
|
woocommerce_task_list_prompt_shown: true,
|
|
|
|
} );
|
|
|
|
}, [ taskLists, isResolving ] );
|
|
|
|
|
2022-02-07 00:50:20 +00:00
|
|
|
// If a task detail is being shown, we shouldn't show the extended tasklist.
|
|
|
|
if ( task ) {
|
2021-10-26 04:08:05 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( isResolving ) {
|
|
|
|
return <TasksPlaceholder query={ query } />;
|
|
|
|
}
|
|
|
|
|
2022-03-01 12:34:18 +00:00
|
|
|
const extendedTaskList = taskLists[ 0 ];
|
2021-10-26 04:08:05 +00:00
|
|
|
|
2022-03-01 12:34:18 +00:00
|
|
|
if ( ! extendedTaskList || extendedTaskList.tasks.length === 0 ) {
|
2021-10-26 04:08:05 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const completedTasks = extendedTaskList.tasks.filter(
|
2022-04-20 08:24:58 +00:00
|
|
|
( extendedTaskListTask: TaskType ) => {
|
2022-04-20 04:49:27 +00:00
|
|
|
return extendedTaskListTask.isComplete;
|
2021-10-26 04:08:05 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
// Use custom isComplete since we're manually adding tasks
|
|
|
|
// to the extended task list.
|
|
|
|
const isComplete = completedTasks.length === extendedTaskList.tasks.length;
|
|
|
|
|
|
|
|
const {
|
|
|
|
id,
|
2022-03-01 12:34:18 +00:00
|
|
|
eventPrefix,
|
2021-10-26 04:08:05 +00:00
|
|
|
isHidden,
|
|
|
|
isVisible,
|
|
|
|
isToggleable,
|
|
|
|
title,
|
|
|
|
tasks,
|
2022-04-20 08:24:58 +00:00
|
|
|
displayProgressHeader,
|
2022-04-20 04:49:27 +00:00
|
|
|
keepCompletedTaskList,
|
2021-10-26 04:08:05 +00:00
|
|
|
} = extendedTaskList;
|
|
|
|
|
|
|
|
if ( ! isVisible ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Fragment key={ id }>
|
|
|
|
<TaskList
|
2022-04-20 08:24:58 +00:00
|
|
|
query={ query }
|
2021-10-26 04:08:05 +00:00
|
|
|
id={ id }
|
2022-03-01 12:34:18 +00:00
|
|
|
eventPrefix={ eventPrefix }
|
2021-10-26 04:08:05 +00:00
|
|
|
isComplete={ isComplete }
|
|
|
|
tasks={ tasks }
|
|
|
|
title={ title }
|
2022-04-20 08:24:58 +00:00
|
|
|
isHidden={ isHidden }
|
|
|
|
isVisible={ isVisible }
|
|
|
|
displayProgressHeader={ displayProgressHeader }
|
2022-04-20 04:49:27 +00:00
|
|
|
keepCompletedTaskList={ keepCompletedTaskList }
|
2021-10-26 04:08:05 +00:00
|
|
|
/>
|
|
|
|
{ isToggleable && (
|
|
|
|
<DisplayOption>
|
|
|
|
<MenuGroup
|
|
|
|
className="woocommerce-layout__homescreen-display-options"
|
2022-03-30 09:00:04 +00:00
|
|
|
label={ __( 'Display', 'woocommerce' ) }
|
2021-10-26 04:08:05 +00:00
|
|
|
>
|
|
|
|
<MenuItem
|
|
|
|
className="woocommerce-layout__homescreen-extension-tasklist-toggle"
|
2022-04-20 04:49:27 +00:00
|
|
|
icon={ isHidden ? undefined : check }
|
2021-10-26 04:08:05 +00:00
|
|
|
isSelected={ ! isHidden }
|
|
|
|
role="menuitemcheckbox"
|
|
|
|
onClick={ () => toggleTaskList( extendedTaskList ) }
|
|
|
|
>
|
2022-03-30 09:00:04 +00:00
|
|
|
{ __( 'Show things to do next', 'woocommerce' ) }
|
2021-10-26 04:08:05 +00:00
|
|
|
</MenuItem>
|
|
|
|
</MenuGroup>
|
|
|
|
</DisplayOption>
|
|
|
|
) }
|
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ExtendedTask;
|