2022-04-28 17:47:06 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
2022-05-24 03:20:04 +00:00
|
|
|
import { ONBOARDING_STORE_NAME, TaskType } from '@woocommerce/data';
|
2022-04-28 17:47:06 +00:00
|
|
|
import { TaskItem, useSlot } from '@woocommerce/experimental';
|
|
|
|
import { useCallback } from '@wordpress/element';
|
|
|
|
import { useDispatch } from '@wordpress/data';
|
|
|
|
|
|
|
|
import { WooOnboardingTaskListItem } from '@woocommerce/onboarding';
|
|
|
|
import classnames from 'classnames';
|
|
|
|
|
|
|
|
export type TaskListItemProps = {
|
|
|
|
task: TaskType;
|
|
|
|
activeTaskId: string;
|
|
|
|
taskIndex: number;
|
|
|
|
goToTask: () => void;
|
|
|
|
trackClick: () => void;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const TaskListItemTwoColumn: React.FC< TaskListItemProps > = ( {
|
|
|
|
task,
|
|
|
|
activeTaskId,
|
|
|
|
taskIndex,
|
|
|
|
goToTask,
|
|
|
|
trackClick,
|
|
|
|
} ) => {
|
|
|
|
const { createNotice } = useDispatch( 'core/notices' );
|
2022-05-24 03:20:04 +00:00
|
|
|
const { dismissTask, undoDismissTask } = useDispatch(
|
|
|
|
ONBOARDING_STORE_NAME
|
|
|
|
);
|
2022-04-28 17:47:06 +00:00
|
|
|
|
|
|
|
const {
|
|
|
|
id: taskId,
|
|
|
|
title,
|
|
|
|
content,
|
|
|
|
time,
|
|
|
|
actionLabel,
|
|
|
|
isComplete,
|
|
|
|
additionalInfo,
|
|
|
|
isDismissable,
|
|
|
|
} = task;
|
|
|
|
|
|
|
|
const slot = useSlot( `woocommerce_onboarding_task_list_item_${ taskId }` );
|
|
|
|
const hasFills = Boolean( slot?.fills?.length );
|
|
|
|
|
|
|
|
const onDismissTask = ( onDismiss?: () => void ) => {
|
|
|
|
dismissTask( taskId );
|
2022-07-08 10:37:30 +00:00
|
|
|
createNotice( 'success', __( 'Task dismissed', 'woocommerce' ), {
|
2022-04-28 17:47:06 +00:00
|
|
|
actions: [
|
|
|
|
{
|
|
|
|
label: __( 'Undo', 'woocommerce' ),
|
|
|
|
onClick: () => undoDismissTask( taskId ),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
} );
|
|
|
|
|
|
|
|
if ( onDismiss ) {
|
|
|
|
onDismiss();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const DefaultTaskItem = useCallback(
|
|
|
|
( props ) => {
|
|
|
|
const className = classnames(
|
|
|
|
'woocommerce-task-list__item index-' + taskIndex,
|
|
|
|
{
|
|
|
|
complete: isComplete,
|
|
|
|
'is-active': taskId === activeTaskId,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
const onClickActions = () => {
|
|
|
|
if ( props.onClick ) {
|
|
|
|
trackClick();
|
|
|
|
return props.onClick();
|
|
|
|
}
|
|
|
|
goToTask();
|
|
|
|
};
|
|
|
|
return (
|
|
|
|
<TaskItem
|
|
|
|
key={ taskId }
|
|
|
|
className={ className }
|
|
|
|
title={ title }
|
|
|
|
completed={ isComplete }
|
|
|
|
additionalInfo={ additionalInfo }
|
|
|
|
content={ content }
|
2022-04-28 21:37:01 +00:00
|
|
|
onClick={ ( e: React.MouseEvent< HTMLButtonElement > ) => {
|
|
|
|
if ( ( e.target as HTMLElement ).tagName === 'A' ) {
|
2022-04-28 17:47:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
onClickActions();
|
|
|
|
} }
|
|
|
|
onDismiss={
|
|
|
|
isDismissable ? () => onDismissTask() : undefined
|
|
|
|
}
|
|
|
|
action={ () => {} }
|
|
|
|
actionLabel={ actionLabel }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
[ taskId, title, content, time, actionLabel, isComplete, activeTaskId ]
|
|
|
|
);
|
|
|
|
|
|
|
|
return hasFills ? (
|
|
|
|
<WooOnboardingTaskListItem.Slot
|
|
|
|
id={ taskId }
|
|
|
|
fillProps={ {
|
|
|
|
defaultTaskItem: DefaultTaskItem,
|
|
|
|
isComplete,
|
|
|
|
} }
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<DefaultTaskItem />
|
|
|
|
);
|
|
|
|
};
|