2021-04-27 15:23:34 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import { Icon, check } from '@wordpress/icons';
|
2021-05-05 17:43:46 +00:00
|
|
|
import { Button, Tooltip } from '@wordpress/components';
|
2021-04-27 15:23:34 +00:00
|
|
|
import { Text } from '@woocommerce/experimental';
|
|
|
|
import { __experimentalListItem as ListItem } from '@woocommerce/components';
|
2021-05-05 17:43:46 +00:00
|
|
|
import NoticeOutline from 'gridicons/dist/notice-outline';
|
2021-04-27 15:23:34 +00:00
|
|
|
import classnames from 'classnames';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import './task-item.scss';
|
|
|
|
import sanitizeHTML from '../lib/sanitize-html';
|
|
|
|
|
2021-05-05 17:43:46 +00:00
|
|
|
type TaskLevel = 1 | 2 | 3;
|
|
|
|
|
2021-04-27 15:23:34 +00:00
|
|
|
type TaskItemProps = {
|
|
|
|
title: string;
|
|
|
|
completed: boolean;
|
|
|
|
onClick: () => void;
|
|
|
|
isDismissable?: boolean;
|
|
|
|
onDismiss?: () => void;
|
|
|
|
additionalInfo?: string;
|
|
|
|
time?: string;
|
|
|
|
content?: string;
|
|
|
|
expanded?: boolean;
|
2021-05-05 17:43:46 +00:00
|
|
|
level?: TaskLevel;
|
|
|
|
};
|
|
|
|
|
|
|
|
const OptionalTaskTooltip: React.FC< {
|
|
|
|
level: TaskLevel;
|
|
|
|
completed: boolean;
|
|
|
|
children: JSX.Element;
|
|
|
|
} > = ( { level, completed, children } ) => {
|
|
|
|
let tooltip = '';
|
|
|
|
if ( level === 1 && ! completed ) {
|
|
|
|
tooltip = __(
|
|
|
|
'This task is required to keep your store running',
|
|
|
|
'woocommerce-admin'
|
|
|
|
);
|
|
|
|
} else if ( level === 2 && ! completed ) {
|
|
|
|
tooltip = __(
|
|
|
|
'This task is required to set up your extension',
|
|
|
|
'woocommerce-admin'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if ( tooltip === '' ) {
|
|
|
|
return children;
|
|
|
|
}
|
|
|
|
return <Tooltip text={ tooltip }>{ children }</Tooltip>;
|
2021-04-27 15:23:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const TaskItem: React.FC< TaskItemProps > = ( {
|
|
|
|
completed,
|
|
|
|
title,
|
|
|
|
isDismissable,
|
|
|
|
onDismiss,
|
|
|
|
onClick,
|
|
|
|
additionalInfo,
|
|
|
|
time,
|
|
|
|
content,
|
|
|
|
expanded = false,
|
2021-05-05 17:43:46 +00:00
|
|
|
level = 3,
|
2021-04-27 15:23:34 +00:00
|
|
|
} ) => {
|
|
|
|
const className = classnames( 'woocommerce-task-list__item', {
|
2021-05-05 17:43:46 +00:00
|
|
|
complete: completed,
|
|
|
|
'level-2': level === 2 && ! completed,
|
|
|
|
'level-1': level === 1 && ! completed,
|
2021-04-27 15:23:34 +00:00
|
|
|
} );
|
2021-05-05 17:43:46 +00:00
|
|
|
|
2021-04-27 15:23:34 +00:00
|
|
|
return (
|
|
|
|
<ListItem
|
2021-05-05 17:43:46 +00:00
|
|
|
disableGutters
|
2021-04-27 15:23:34 +00:00
|
|
|
className={ className }
|
|
|
|
onClick={ onClick }
|
|
|
|
animation="slide-right"
|
|
|
|
>
|
2021-05-05 17:43:46 +00:00
|
|
|
<OptionalTaskTooltip level={ level } completed={ completed }>
|
|
|
|
<div className="woocommerce-task-list__item-before">
|
|
|
|
{ level === 1 && ! completed ? (
|
|
|
|
<NoticeOutline size={ 36 } />
|
|
|
|
) : (
|
|
|
|
<div className="woocommerce-task__icon">
|
|
|
|
{ completed && <Icon icon={ check } /> }
|
|
|
|
</div>
|
|
|
|
) }
|
2021-04-27 15:23:34 +00:00
|
|
|
</div>
|
2021-05-05 17:43:46 +00:00
|
|
|
</OptionalTaskTooltip>
|
2021-04-27 15:23:34 +00:00
|
|
|
<div className="woocommerce-task-list__item-text">
|
|
|
|
<span className="woocommerce-task-list__item-title">
|
|
|
|
<Text
|
|
|
|
as="div"
|
|
|
|
variant={ completed ? 'body.small' : 'button' }
|
|
|
|
>
|
|
|
|
{ title }
|
|
|
|
{ additionalInfo && (
|
|
|
|
<div
|
|
|
|
className="woocommerce-task__additional-info"
|
|
|
|
dangerouslySetInnerHTML={ sanitizeHTML(
|
|
|
|
additionalInfo
|
|
|
|
) }
|
|
|
|
></div>
|
|
|
|
) }
|
|
|
|
{ expanded && content && (
|
|
|
|
<div className="woocommerce-task-list__item-content">
|
|
|
|
{ content }
|
|
|
|
</div>
|
|
|
|
) }
|
|
|
|
{ time && ! completed && (
|
|
|
|
<div className="woocommerce-task__estimated-time">
|
|
|
|
{ time }
|
|
|
|
</div>
|
|
|
|
) }
|
|
|
|
</Text>
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
{ onDismiss && isDismissable && ! completed && (
|
|
|
|
<div className="woocommerce-task-list__item-after">
|
|
|
|
<Button
|
|
|
|
data-testid={ `dismiss-button` }
|
|
|
|
isTertiary
|
|
|
|
onClick={ (
|
|
|
|
event: React.MouseEvent | React.KeyboardEvent
|
|
|
|
) => {
|
|
|
|
event.stopPropagation();
|
|
|
|
onDismiss();
|
|
|
|
} }
|
|
|
|
>
|
|
|
|
{ __( 'Dismiss', 'woocommerce-admin' ) }
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
) }
|
|
|
|
</ListItem>
|
|
|
|
);
|
|
|
|
};
|