/** * External dependencies */ import { __ } from '@wordpress/i18n'; import { useEffect, useRef, useState, createElement, useContext, } from '@wordpress/element'; import { Button, Card } from '@wordpress/components'; import { useSelect, useDispatch } from '@wordpress/data'; import { EllipsisMenu } from '@woocommerce/components'; import { navigateTo, getNewPath } from '@woocommerce/navigation'; import { ONBOARDING_STORE_NAME, TaskType, useUserPreferences, getVisibleTasks, TaskListType, WCDataSelector, } from '@woocommerce/data'; import { recordEvent } from '@woocommerce/tracks'; import { List } from '@woocommerce/experimental'; import classnames from 'classnames'; /** * Internal dependencies */ import '../tasks/task-list.scss'; import taskHeaders from './task-headers'; import DismissModal from './dismiss-modal'; import TaskListCompleted from './completed'; import { ProgressHeader } from '~/task-lists/progress-header'; import { TaskListItemTwoColumn } from './task-list-item-two-column'; import { TaskListCompletedHeader } from './completed-header'; import { LayoutContext } from '~/layout'; export type TaskListProps = TaskListType & { eventName?: string; twoColumns?: boolean; query: { task?: string; }; cesHeader?: boolean; }; export const TaskList: React.FC< TaskListProps > = ( { query, id, eventName, eventPrefix, tasks, twoColumns, keepCompletedTaskList, isComplete, displayProgressHeader, cesHeader = true, } ) => { const listEventPrefix = eventName ? eventName + '_' : eventPrefix; const { profileItems } = useSelect( ( select: WCDataSelector ) => { const { getProfileItems } = select( ONBOARDING_STORE_NAME ); return { profileItems: getProfileItems(), }; } ); const { hideTaskList, visitedTask, keepCompletedTaskList: keepCompletedTasks, } = useDispatch( ONBOARDING_STORE_NAME ); const userPreferences = useUserPreferences(); const [ headerData, setHeaderData ] = useState< { task?: TaskType; goToTask?: () => void; trackClick?: () => void; } >( {} ); const [ activeTaskId, setActiveTaskId ] = useState( '' ); const [ showDismissModal, setShowDismissModal ] = useState( false ); const layoutContext = useContext( LayoutContext ); const prevQueryRef = useRef( query ); const visibleTasks = getVisibleTasks( tasks ); const recordTaskListView = () => { if ( query.task ) { return; } recordEvent( `${ listEventPrefix }view`, { number_tasks: visibleTasks.length, store_connected: profileItems.wccom_connected, context: layoutContext.toString(), } ); }; useEffect( () => { recordTaskListView(); }, [] ); useEffect( () => { const { task: prevTask } = prevQueryRef.current; const { task } = query; if ( prevTask !== task ) { window.document.documentElement.scrollTop = 0; prevQueryRef.current = query; } }, [ query ] ); const incompleteTasks = tasks.filter( ( task ) => ! task.isComplete && ! task.isDismissed ); const hideTasks = () => { hideTaskList( id ); }; const keepTasks = () => { keepCompletedTasks( id ); }; const renderMenu = () => { return (