2022-03-22 15:28:58 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __, sprintf } from '@wordpress/i18n';
|
2022-04-25 05:49:11 +00:00
|
|
|
import { useSelect, useDispatch } from '@wordpress/data';
|
2022-03-22 15:28:58 +00:00
|
|
|
import {
|
|
|
|
ONBOARDING_STORE_NAME,
|
|
|
|
OPTIONS_STORE_NAME,
|
|
|
|
TaskListType,
|
|
|
|
} from '@woocommerce/data';
|
|
|
|
import { Button } from '@wordpress/components';
|
|
|
|
import { Link } from '@woocommerce/components';
|
|
|
|
import { getAdminLink } from '@woocommerce/settings';
|
|
|
|
import { close as closeIcon } from '@wordpress/icons';
|
|
|
|
import interpolateComponents from '@automattic/interpolate-components';
|
|
|
|
import { useEffect } from '@wordpress/element';
|
2022-04-13 23:24:55 +00:00
|
|
|
import { getQuery } from '@woocommerce/navigation';
|
2022-04-21 19:01:56 +00:00
|
|
|
import { recordEvent } from '@woocommerce/tracks';
|
2022-03-22 15:28:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import './reminder-bar.scss';
|
|
|
|
|
|
|
|
type ReminderBarProps = {
|
|
|
|
taskListId: string;
|
|
|
|
updateBodyMargin: () => void;
|
|
|
|
};
|
|
|
|
|
|
|
|
type ReminderTextProps = {
|
2022-04-07 19:39:47 +00:00
|
|
|
remainingCount: number | null;
|
2022-04-21 19:01:56 +00:00
|
|
|
tracksProps: {
|
|
|
|
completed: number;
|
|
|
|
is_homescreen: boolean;
|
|
|
|
is_active_task_page: boolean;
|
|
|
|
};
|
2022-03-22 15:28:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const REMINDER_BAR_HIDDEN_OPTION = 'woocommerce_task_list_reminder_bar_hidden';
|
|
|
|
|
2022-04-21 19:01:56 +00:00
|
|
|
const ReminderText: React.FC< ReminderTextProps > = ( {
|
|
|
|
remainingCount,
|
|
|
|
tracksProps,
|
|
|
|
} ) => {
|
2022-03-22 15:28:58 +00:00
|
|
|
const translationText =
|
|
|
|
remainingCount === 1
|
|
|
|
? /* translators: 1: remaining tasks count */
|
|
|
|
__(
|
|
|
|
'🎉 Almost there. Only {{strongText}}%1$d step left{{/strongText}} get your store up and running. {{setupLink}}Finish setup{{/setupLink}}',
|
2022-03-30 09:00:04 +00:00
|
|
|
'woocommerce'
|
2022-03-22 15:28:58 +00:00
|
|
|
)
|
|
|
|
: /* translators: 1: remaining tasks count */
|
|
|
|
__(
|
|
|
|
"🚀 You're doing great! {{strongText}}%1$d steps left{{/strongText}} to get your store up and running. {{setupLink}}Continue setup{{/setupLink}}",
|
2022-03-30 09:00:04 +00:00
|
|
|
'woocommerce'
|
2022-03-22 15:28:58 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<p>
|
|
|
|
{ interpolateComponents( {
|
|
|
|
mixedString: sprintf( translationText, remainingCount ),
|
|
|
|
components: {
|
|
|
|
strongText: <strong />,
|
|
|
|
setupLink: (
|
|
|
|
<Link
|
|
|
|
href={ getAdminLink( 'admin.php?page=wc-admin' ) }
|
2022-04-21 19:01:56 +00:00
|
|
|
onClick={ () =>
|
|
|
|
recordEvent(
|
|
|
|
'tasklist_reminder_bar_continue',
|
|
|
|
tracksProps
|
|
|
|
)
|
|
|
|
}
|
2022-03-22 15:28:58 +00:00
|
|
|
type="wp-admin"
|
2022-04-21 04:44:19 +00:00
|
|
|
>
|
|
|
|
<></>
|
|
|
|
</Link>
|
2022-03-22 15:28:58 +00:00
|
|
|
),
|
|
|
|
},
|
|
|
|
} ) }
|
|
|
|
</p>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const TasksReminderBar: React.FC< ReminderBarProps > = ( {
|
2022-04-27 20:58:14 +00:00
|
|
|
taskListId,
|
2022-03-22 15:28:58 +00:00
|
|
|
updateBodyMargin,
|
|
|
|
} ) => {
|
|
|
|
const { updateOptions } = useDispatch( OPTIONS_STORE_NAME );
|
|
|
|
const {
|
|
|
|
remainingCount,
|
|
|
|
loading,
|
|
|
|
taskListHidden,
|
|
|
|
taskListComplete,
|
|
|
|
reminderBarHidden,
|
|
|
|
completedTasksCount,
|
2022-04-25 05:49:11 +00:00
|
|
|
} = useSelect( ( select ) => {
|
2022-03-22 15:28:58 +00:00
|
|
|
const {
|
|
|
|
getTaskList,
|
|
|
|
hasFinishedResolution: onboardingHasFinishedResolution,
|
|
|
|
} = select( ONBOARDING_STORE_NAME );
|
|
|
|
const {
|
|
|
|
getOption,
|
|
|
|
hasFinishedResolution: optionHasFinishedResolution,
|
|
|
|
} = select( OPTIONS_STORE_NAME );
|
|
|
|
const reminderBarHiddenOption = getOption( REMINDER_BAR_HIDDEN_OPTION );
|
2022-04-25 06:16:39 +00:00
|
|
|
const taskList = getTaskList( taskListId );
|
2022-03-22 15:28:58 +00:00
|
|
|
const taskListIsResolved = onboardingHasFinishedResolution(
|
|
|
|
'getTaskList',
|
|
|
|
[ taskListId ]
|
|
|
|
);
|
|
|
|
const optionIsResolved = optionHasFinishedResolution( 'getOption', [
|
|
|
|
REMINDER_BAR_HIDDEN_OPTION,
|
|
|
|
] );
|
|
|
|
|
2022-04-25 06:16:39 +00:00
|
|
|
const visibleTasks =
|
|
|
|
taskList?.tasks.filter(
|
|
|
|
( task ) =>
|
|
|
|
! task.isDismissed &&
|
|
|
|
( ! task.isSnoozed || task.snoozedUntil < Date.now() )
|
|
|
|
) || [];
|
2022-03-22 15:28:58 +00:00
|
|
|
|
2022-03-25 08:06:40 +00:00
|
|
|
const completedTasks =
|
|
|
|
visibleTasks?.filter( ( task ) => task.isComplete ) || [];
|
2022-03-22 15:28:58 +00:00
|
|
|
|
|
|
|
const isResolved = taskListIsResolved && optionIsResolved;
|
|
|
|
|
|
|
|
return {
|
|
|
|
reminderBarHidden: reminderBarHiddenOption === 'yes',
|
2022-04-25 06:16:39 +00:00
|
|
|
taskListHidden: isResolved ? taskList?.isHidden : false,
|
|
|
|
taskListComplete: isResolved ? taskList?.isComplete : false,
|
2022-03-22 15:28:58 +00:00
|
|
|
loading: ! isResolved,
|
2022-03-23 16:57:48 +00:00
|
|
|
completedTasksCount: completedTasks.length,
|
2022-03-22 15:28:58 +00:00
|
|
|
remainingCount: isResolved
|
2022-03-23 16:57:48 +00:00
|
|
|
? visibleTasks?.length - completedTasks.length
|
2022-03-22 15:28:58 +00:00
|
|
|
: null,
|
|
|
|
};
|
|
|
|
} );
|
|
|
|
|
2022-04-21 05:10:56 +00:00
|
|
|
const query = getQuery() as { [ key: string ]: string };
|
2022-04-13 23:24:55 +00:00
|
|
|
const isHomescreen =
|
2022-04-21 05:10:56 +00:00
|
|
|
query.page && query.page === 'wc-admin' && ! query.path;
|
|
|
|
const isActiveTaskPage = Boolean( query.wc_onboarding_active_task );
|
2022-04-13 23:24:55 +00:00
|
|
|
|
2022-04-21 19:01:56 +00:00
|
|
|
const isHidden =
|
2022-03-22 15:28:58 +00:00
|
|
|
loading ||
|
|
|
|
taskListHidden ||
|
|
|
|
taskListComplete ||
|
|
|
|
reminderBarHidden ||
|
|
|
|
completedTasksCount === 0 ||
|
2022-04-13 23:24:55 +00:00
|
|
|
isHomescreen ||
|
|
|
|
isActiveTaskPage;
|
2022-03-22 15:28:58 +00:00
|
|
|
|
|
|
|
useEffect( () => {
|
|
|
|
updateBodyMargin();
|
2022-04-21 19:01:56 +00:00
|
|
|
}, [ isHidden, updateBodyMargin ] );
|
|
|
|
|
|
|
|
const tracksProps = {
|
|
|
|
completed: completedTasksCount,
|
2022-04-22 15:04:51 +00:00
|
|
|
is_homescreen: !! isHomescreen,
|
2022-04-21 19:01:56 +00:00
|
|
|
is_active_task_page: isActiveTaskPage,
|
|
|
|
};
|
|
|
|
|
|
|
|
useEffect( () => {
|
|
|
|
if ( loading || isHidden ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
recordEvent( 'tasklist_reminder_bar_view', tracksProps );
|
|
|
|
}, [ isHidden, loading ] );
|
|
|
|
|
|
|
|
const onClose = () => {
|
|
|
|
updateOptions( {
|
|
|
|
[ REMINDER_BAR_HIDDEN_OPTION ]: 'yes',
|
|
|
|
} );
|
|
|
|
recordEvent( 'tasklist_reminder_bar_close', tracksProps );
|
|
|
|
};
|
2022-03-22 15:28:58 +00:00
|
|
|
|
2022-04-21 19:01:56 +00:00
|
|
|
if ( isHidden ) {
|
2022-03-22 15:28:58 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="woocommerce-layout__header-tasks-reminder-bar">
|
2022-04-21 19:01:56 +00:00
|
|
|
<ReminderText
|
|
|
|
remainingCount={ remainingCount }
|
|
|
|
tracksProps={ tracksProps }
|
2022-03-22 15:28:58 +00:00
|
|
|
/>
|
2022-04-21 19:01:56 +00:00
|
|
|
<Button isSmall onClick={ onClose } icon={ closeIcon } />
|
2022-03-22 15:28:58 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|