2021-10-20 16:16:22 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
2021-11-29 21:04:34 +00:00
|
|
|
import { useSelect } from '@wordpress/data';
|
2022-04-04 14:54:34 +00:00
|
|
|
import { ONBOARDING_STORE_NAME } from '@woocommerce/data';
|
2021-10-20 16:16:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import '../tasks/tasks.scss';
|
|
|
|
import './style.scss';
|
|
|
|
import TaskList from './task-list';
|
|
|
|
import TaskListPlaceholder from './placeholder';
|
|
|
|
import { Task } from '../tasks/task';
|
|
|
|
|
|
|
|
const TaskDashboard = ( { query, twoColumns } ) => {
|
|
|
|
const { task } = query;
|
|
|
|
|
|
|
|
const { isResolving, taskLists } = useSelect( ( select ) => {
|
|
|
|
return {
|
2022-03-01 12:34:18 +00:00
|
|
|
taskLists: select( ONBOARDING_STORE_NAME ).getTaskListsByIds( [
|
|
|
|
'setup_two_column',
|
|
|
|
'extended_two_column',
|
|
|
|
] ),
|
2021-10-20 16:16:22 +00:00
|
|
|
isResolving: select( ONBOARDING_STORE_NAME ).isResolving(
|
2022-03-01 12:34:18 +00:00
|
|
|
'getTaskListsByIds'
|
2021-10-20 16:16:22 +00:00
|
|
|
),
|
|
|
|
};
|
|
|
|
} );
|
|
|
|
const getCurrentTask = () => {
|
|
|
|
if ( ! task ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const tasks = taskLists.reduce(
|
|
|
|
( acc, taskList ) => [ ...acc, ...taskList.tasks ],
|
|
|
|
[]
|
|
|
|
);
|
|
|
|
|
|
|
|
const currentTask = tasks.find( ( t ) => t.id === task );
|
|
|
|
|
|
|
|
if ( ! currentTask ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return currentTask;
|
|
|
|
};
|
|
|
|
|
|
|
|
const currentTask = getCurrentTask();
|
|
|
|
|
|
|
|
if ( task && ! currentTask ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-04-04 18:58:50 +00:00
|
|
|
if ( isResolving || ! taskLists[ 0 ] ) {
|
2021-11-02 02:43:46 +00:00
|
|
|
return <TaskListPlaceholder twoColumns={ twoColumns } />;
|
2021-10-20 16:16:22 +00:00
|
|
|
}
|
|
|
|
|
2021-10-26 04:08:05 +00:00
|
|
|
if ( currentTask ) {
|
|
|
|
return (
|
|
|
|
<div className="woocommerce-task-dashboard__container">
|
|
|
|
<Task query={ query } task={ currentTask } />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
// List of task items to be shown on the main task list.
|
|
|
|
// Any other remaining tasks will be moved to the extended task list.
|
2022-03-01 12:34:18 +00:00
|
|
|
const taskList = taskLists[ 0 ];
|
|
|
|
const setupTasks = taskList.tasks;
|
2021-10-26 04:08:05 +00:00
|
|
|
|
2021-10-20 16:16:22 +00:00
|
|
|
const completedTasks = setupTasks.filter(
|
|
|
|
( setupTask ) => setupTask.isComplete
|
|
|
|
);
|
|
|
|
const isTaskListComplete = setupTasks.length === completedTasks.length;
|
|
|
|
|
|
|
|
const dismissedTasks = setupTasks.filter(
|
|
|
|
( setupTask ) => setupTask.isDismissed
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2022-03-01 12:34:18 +00:00
|
|
|
{ setupTasks && ( taskList.isVisible || task ) && (
|
2021-10-20 16:16:22 +00:00
|
|
|
<TaskList
|
2022-03-15 17:40:22 +00:00
|
|
|
id={ taskList.id }
|
2021-10-20 16:16:22 +00:00
|
|
|
eventName="tasklist"
|
|
|
|
twoColumns={ twoColumns }
|
2022-04-04 14:54:34 +00:00
|
|
|
keepCompletedTaskList={ taskList.keepCompletedTaskList }
|
2021-10-20 16:16:22 +00:00
|
|
|
dismissedTasks={ dismissedTasks || [] }
|
|
|
|
isComplete={ isTaskListComplete }
|
|
|
|
query={ query }
|
2022-04-07 19:56:20 +00:00
|
|
|
cesHeader={ false }
|
2021-10-20 16:16:22 +00:00
|
|
|
tasks={ setupTasks }
|
2022-03-30 09:00:04 +00:00
|
|
|
title={ __( 'Get ready to start selling', 'woocommerce' ) }
|
2021-10-20 16:16:22 +00:00
|
|
|
/>
|
|
|
|
) }
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default TaskDashboard;
|