Address PR feedback and fix some minor issues

This commit is contained in:
Lourens Schep 2022-03-23 17:01:58 -03:00
parent 569e27bf02
commit c934c62351
3 changed files with 42 additions and 11 deletions

View File

@ -22,12 +22,12 @@ export const ProgressHeader: React.FC< ProgressHeaderProps > = ( {
} ) => {
const { loading, tasksCount, completedCount, hasVisitedTasks } = useSelect(
( select ) => {
const isResolving = select( ONBOARDING_STORE_NAME ).isResolving(
'getTaskList'
);
const taskList: TaskListType = select(
ONBOARDING_STORE_NAME
).getTaskList( taskListId );
const finishedResolution = select( ONBOARDING_STORE_NAME ).hasFinishedResolution(
'getTaskList', [ taskListId ]
);
const nowTimestamp = Date.now();
const visibleTasks = taskList?.tasks.filter(
( task ) =>
@ -36,7 +36,7 @@ export const ProgressHeader: React.FC< ProgressHeaderProps > = ( {
);
return {
loading: isResolving,
loading: ! finishedResolution,
tasksCount: visibleTasks?.length,
completedCount: visibleTasks?.filter(
( task ) => task.isComplete
@ -49,7 +49,7 @@ export const ProgressHeader: React.FC< ProgressHeaderProps > = ( {
);
const progressTitle = useMemo( () => {
if ( ! hasVisitedTasks || completedCount === tasksCount ) {
if ( ( ! hasVisitedTasks && completedCount < 2 ) || completedCount === tasksCount ) {
const siteTitle = getSetting( 'siteTitle' );
return siteTitle
? sprintf(
@ -58,12 +58,14 @@ export const ProgressHeader: React.FC< ProgressHeaderProps > = ( {
siteTitle
)
: __( 'Welcome', 'woocommerce-admin' );
} else if ( completedCount > 0 && completedCount < 3 ) {
return __( "Let's get you set up", 'woocommerce-admin' ) + ' 🚀';
} else if ( completedCount > 2 && completedCount < 5 ) {
}
if ( completedCount > 0 && completedCount < 4 ) {
return __( "Let's get you started", 'woocommerce-admin' ) + ' 🚀';
}
if ( completedCount > 3 && completedCount < 7 ) {
return __( 'You are on the right track', 'woocommerce-admin' );
}
return __( 'Just a few tasks left', 'woocommerce-admin' );
return __( 'You are almost there', 'woocommerce-admin' );
}, [ completedCount, hasVisitedTasks ] );
if ( loading || completedCount === tasksCount ) {

View File

@ -11,6 +11,7 @@ import {
OPTIONS_STORE_NAME,
ONBOARDING_STORE_NAME,
TaskType,
useUserPreferences
} from '@woocommerce/data';
import { recordEvent } from '@woocommerce/tracks';
import { List, TaskItem } from '@woocommerce/experimental';
@ -46,7 +47,8 @@ export const TaskList: React.FC< TaskListProps > = ( {
profileItems: getProfileItems(),
};
} );
const { hideTaskList } = useDispatch( ONBOARDING_STORE_NAME );
const { hideTaskList, visitedTask } = useDispatch( ONBOARDING_STORE_NAME );
const userPreferences = useUserPreferences();
const [ headerData, setHeaderData ] = useState< {
task?: TaskType;
goToTask?: () => void;
@ -163,6 +165,30 @@ export const TaskList: React.FC< TaskListProps > = ( {
selectedHeaderCard = visibleTasks[ visibleTasks.length - 1 ];
}
const getTaskStartedCount = ( taskId: string ) => {
const trackedStartedTasks =
userPreferences.task_list_tracked_started_tasks;
if ( ! trackedStartedTasks || ! trackedStartedTasks[ taskId ] ) {
return 0;
}
return trackedStartedTasks[ taskId ];
};
// @todo This would be better as a task endpoint that handles updating the count.
const updateTrackStartedCount = ( taskId: string ) => {
const newCount = getTaskStartedCount( taskId ) + 1;
const trackedStartedTasks =
userPreferences.task_list_tracked_started_tasks || {};
visitedTask( taskId );
userPreferences.updateUserPreferences( {
task_list_tracked_started_tasks: {
...( trackedStartedTasks || {} ),
[ taskId ]: newCount,
},
} );
};
const trackClick = ( task: TaskType ) => {
recordEvent( `${ eventName }_click`, {
task_name: task.id,
@ -171,6 +197,9 @@ export const TaskList: React.FC< TaskListProps > = ( {
const goToTask = ( task: TaskType ) => {
trackClick( task );
if ( ! task.isComplete ) {
updateTrackStartedCount( task.id );
}
updateQueryString( { task: task.id } );
};

View File

@ -73,7 +73,7 @@ class AdditionalPayments extends Payments {
$woocommerce_payments = new WooCommercePayments();
if ( $woocommerce_payments->is_requested() && $woocommerce_payments->is_supported() && ! $woocommerce_payments->is_connected() ) {
if ( ! $woocommerce_payments->is_requested() || ( $woocommerce_payments->is_supported() && ! $woocommerce_payments->is_connected() ) ) {
// Hide task if WC Pay is installed via OBW, in supported country, but not connected.
return false;
}