2022-03-21 13:52:04 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __, sprintf } from '@wordpress/i18n';
|
|
|
|
import { useMemo } from '@wordpress/element';
|
|
|
|
import { useSelect } from '@wordpress/data';
|
2022-04-25 05:49:11 +00:00
|
|
|
import { getVisibleTasks, ONBOARDING_STORE_NAME } from '@woocommerce/data';
|
2022-03-21 13:52:04 +00:00
|
|
|
import { getSetting } from '@woocommerce/settings';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import './progress-header.scss';
|
|
|
|
import { TaskListMenu } from '~/tasks/task-list-menu';
|
|
|
|
|
|
|
|
type ProgressHeaderProps = {
|
|
|
|
taskListId: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const ProgressHeader: React.FC< ProgressHeaderProps > = ( {
|
|
|
|
taskListId,
|
|
|
|
} ) => {
|
2022-04-29 15:40:01 +00:00
|
|
|
const { loading, tasksCount, completedCount, hasVisitedTasks } = useSelect(
|
|
|
|
( select ) => {
|
|
|
|
const taskList = select( ONBOARDING_STORE_NAME ).getTaskList(
|
|
|
|
taskListId
|
|
|
|
);
|
|
|
|
const finishedResolution = select(
|
|
|
|
ONBOARDING_STORE_NAME
|
|
|
|
).hasFinishedResolution( 'getTaskList', [ taskListId ] );
|
|
|
|
const visibleTasks = getVisibleTasks( taskList?.tasks || [] );
|
2022-03-21 13:52:04 +00:00
|
|
|
|
2022-04-29 15:40:01 +00:00
|
|
|
return {
|
|
|
|
loading: ! finishedResolution,
|
|
|
|
tasksCount: visibleTasks?.length,
|
|
|
|
completedCount: visibleTasks?.filter(
|
|
|
|
( task ) => task.isComplete
|
|
|
|
).length,
|
|
|
|
hasVisitedTasks:
|
|
|
|
visibleTasks?.filter(
|
|
|
|
( task ) =>
|
|
|
|
task.isVisited && task.id !== 'store_details'
|
|
|
|
).length > 0,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
);
|
2022-03-21 13:52:04 +00:00
|
|
|
|
|
|
|
const progressTitle = useMemo( () => {
|
2022-04-29 15:40:01 +00:00
|
|
|
if ( ! hasVisitedTasks || completedCount === tasksCount ) {
|
2022-03-21 13:52:04 +00:00
|
|
|
const siteTitle = getSetting( 'siteTitle' );
|
|
|
|
return siteTitle
|
|
|
|
? sprintf(
|
|
|
|
/* translators: %s = site title */
|
2022-03-30 09:00:04 +00:00
|
|
|
__( 'Welcome to %s', 'woocommerce' ),
|
2022-03-21 13:52:04 +00:00
|
|
|
siteTitle
|
|
|
|
)
|
2022-04-26 17:51:26 +00:00
|
|
|
: __( 'Welcome to your store', 'woocommerce' );
|
2022-03-23 20:01:58 +00:00
|
|
|
}
|
|
|
|
if ( completedCount > 0 && completedCount < 4 ) {
|
2022-03-30 09:00:04 +00:00
|
|
|
return __( "Let's get you started", 'woocommerce' ) + ' 🚀';
|
2022-03-23 20:01:58 +00:00
|
|
|
}
|
2022-03-23 20:24:08 +00:00
|
|
|
if ( completedCount > 3 && completedCount < 6 ) {
|
2022-03-30 09:00:04 +00:00
|
|
|
return __( 'You are on the right track', 'woocommerce' );
|
2022-03-21 13:52:04 +00:00
|
|
|
}
|
2022-03-30 09:00:04 +00:00
|
|
|
return __( 'You are almost there', 'woocommerce' );
|
2022-04-29 15:40:01 +00:00
|
|
|
}, [ completedCount, hasVisitedTasks, tasksCount ] );
|
2022-03-21 13:52:04 +00:00
|
|
|
|
2022-04-14 11:51:47 +00:00
|
|
|
if ( loading ) {
|
2022-03-21 13:52:04 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="woocommerce-task-progress-header">
|
|
|
|
<TaskListMenu
|
|
|
|
id={ taskListId }
|
2022-03-30 09:00:04 +00:00
|
|
|
hideTaskListText={ __( 'Hide setup list', 'woocommerce' ) }
|
2022-03-21 13:52:04 +00:00
|
|
|
/>
|
|
|
|
<div className="woocommerce-task-progress-header__contents">
|
|
|
|
<h1 className="woocommerce-task-progress-header__title">
|
|
|
|
{ progressTitle }
|
|
|
|
</h1>
|
2022-04-14 11:51:47 +00:00
|
|
|
{ completedCount !== tasksCount ? (
|
|
|
|
<>
|
|
|
|
<p>
|
|
|
|
{ sprintf(
|
|
|
|
/* translators: 1: completed tasks, 2: total tasks */
|
|
|
|
__(
|
|
|
|
'Follow these steps to start selling quickly. %1$d out of %2$d complete.',
|
|
|
|
'woocommerce'
|
|
|
|
),
|
|
|
|
completedCount,
|
|
|
|
tasksCount
|
|
|
|
) }
|
|
|
|
</p>
|
|
|
|
<progress
|
|
|
|
className="woocommerce-task-progress-header__progress-bar"
|
|
|
|
max={ tasksCount }
|
|
|
|
value={ completedCount || 0 }
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
) : null }
|
2022-03-21 13:52:04 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|