/** * 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'; import { ONBOARDING_STORE_NAME, OPTIONS_STORE_NAME, TaskListType, TaskType, WCDataSelector, } from '@woocommerce/data'; import { recordEvent } from '@woocommerce/tracks'; /** * Internal dependencies */ import { DisplayOption } from '~/activity-panel/display-options'; import './task-lists.scss'; import { SetupTaskList, TaskListPlaceholder as SetupTaskListPlaceholder, } from './setup-task-list'; import './setup-task-list/style.scss'; import { Task } from './components/task'; import { TasksPlaceholder } from './components/placeholder'; import { TaskList } from './components/task-list'; import { getAdminSetting } from '~/utils/admin-settings'; export type TaskListsProps = { query: { task?: string }; context?: string; }; export const TaskLists: React.FC< TaskListsProps > = ( { query } ) => { const { task } = query; const { hideTaskList } = useDispatch( ONBOARDING_STORE_NAME ); const { updateOptions } = useDispatch( OPTIONS_STORE_NAME ); const { isResolving, taskLists } = useSelect( ( select: WCDataSelector ) => { return { isResolving: ! select( ONBOARDING_STORE_NAME ).hasFinishedResolution( 'getTaskLists' ), taskLists: select( ONBOARDING_STORE_NAME ).getTaskLists(), }; } ); const getCurrentTask = () => { if ( ! task ) { return null; } const tasks = taskLists.reduce( ( acc: TaskType[], taskList: TaskListType ) => [ ...acc, ...taskList.tasks, ], [] ); const currentTask = tasks.find( ( t: TaskType ) => t.id === task ); if ( ! currentTask ) { return null; } return currentTask; }; const toggleTaskList = ( taskList: TaskListType ) => { const { id, eventPrefix, isHidden } = taskList; const newValue = ! isHidden; recordEvent( newValue ? `${ eventPrefix }hide` : `${ eventPrefix }show`, {} ); hideTaskList( id ); }; useEffect( () => { // @todo Update this when all task lists have been hidden or completed. // const taskListsFinished = false; updateOptions( { woocommerce_task_list_prompt_shown: true, } ); }, [ taskLists, isResolving ] ); const currentTask = getCurrentTask(); if ( task && ! currentTask ) { return null; } if ( currentTask ) { return (