import { ExternalLink, Spinner } from '@wordpress/components' import { __, _n, sprintf } from '@wordpress/i18n' import classNames from 'classnames' import { Checkmark } from '@onboarding/svg' import { useTasks } from '@assist/hooks/useTasks' import { useSelectionStore, useSelectionStoreReady, } from '@assist/state/Selections' import { useTasksStoreReady, useTasksStore } from '@assist/state/Tasks' export const TasksList = () => { const { isCompleted } = useTasksStore() const { tasks, loading, error } = useTasks() const readyTasks = useTasksStoreReady() const readyPlugins = useSelectionStoreReady() const pluginBasedGoals = useSelectionStore((state) => state.plugins?.reduce( (acc, plugin) => [...acc, ...(plugin?.goals ?? [])], [], ), ) if (loading || !readyTasks || !readyPlugins || error) { return (
) } if (tasks.length === 0) { return (
{__('No tasks found...', 'extendify')}
) } // Filter out tasks that have goal dependencies that don't match the user's goals const tasksFiltered = tasks.filter((task) => { // If no goals, show the task if (!task?.goals?.length) return true // Check if task.goals intersect with pluginBasedGoals return task?.goals?.some((goal) => pluginBasedGoals.includes(goal)) }) const remainingTasks = tasksFiltered?.reduce( (count, task) => count - Number(isCompleted(task.slug)), tasksFiltered.length, ) return (

{__('Get ready to go live', 'extendify')}

{remainingTasks > 0 && ( {remainingTasks} )}
{tasksFiltered.map((task) => ( ))}
) } const TaskCheckBox = ({ task }) => { const { isCompleted, toggleCompleted } = useTasksStore() return (
toggleCompleted(task.slug)} /> {task.description}{' '} {task.link && ( {__('Learn more', 'extendify')} )}
) }