Fix Launch Your Store task item should not be clickable once completed (#46361)

* Fix Launch Your Store task item should not be clickable once completed

* Add changefile(s) from automation for the following project(s): @woocommerce/experimental, woocommerce

---------

Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
Chi-Hsuan Huang 2024-04-10 20:32:15 +08:00 committed by GitHub
parent 0387404d7f
commit 95b36650d7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 49 additions and 9 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Fix Launch Your Store task item should not be clickable once completed

View File

@ -39,7 +39,7 @@ type ActionArgs = {
type TaskItemProps = { type TaskItemProps = {
title: string; title: string;
completed: boolean; completed: boolean;
onClick: React.MouseEventHandler< HTMLElement >; onClick?: React.MouseEventHandler< HTMLElement >;
onCollapse?: () => void; onCollapse?: () => void;
onDelete?: () => void; onDelete?: () => void;
onDismiss?: () => void; onDismiss?: () => void;

View File

@ -9,6 +9,7 @@ import './appearance';
import './tax'; import './tax';
import './woocommerce-payments'; import './woocommerce-payments';
import './deprecated-tasks'; import './deprecated-tasks';
import './launch-your-store';
const possiblyImportProductTask = async () => { const possiblyImportProductTask = async () => {
if ( isImportProduct() ) { if ( isImportProduct() ) {

View File

@ -0,0 +1,30 @@
/**
* External dependencies
*/
import { registerPlugin } from '@wordpress/plugins';
import { WooOnboardingTaskListItem } from '@woocommerce/onboarding';
const LaunchYourStoreTaskItem = () => {
return (
<WooOnboardingTaskListItem id="launch-your-store">
{ ( {
defaultTaskItem: DefaultTaskItem,
isComplete,
}: {
defaultTaskItem: ( props: {
isClickable: boolean;
} ) => JSX.Element;
onClick: () => void;
isComplete: boolean;
} ) => {
return <DefaultTaskItem isClickable={ ! isComplete } />;
} }
</WooOnboardingTaskListItem>
);
};
registerPlugin( 'woocommerce-admin-task-launch-your-store', {
// @ts-expect-error scope is not defined in the type definition but it is a valid property
scope: 'woocommerce-tasks',
render: LaunchYourStoreTaskItem,
} );

View File

@ -62,7 +62,7 @@ export const TaskListItem: React.FC< TaskListItemProps > = ( {
}; };
const DefaultTaskItem = useCallback( const DefaultTaskItem = useCallback(
( props ) => { ( props: { onClick?: () => void; isClickable?: boolean } ) => {
const className = classnames( const className = classnames(
'woocommerce-task-list__item index-' + taskIndex, 'woocommerce-task-list__item index-' + taskIndex,
{ {
@ -71,13 +71,17 @@ export const TaskListItem: React.FC< TaskListItemProps > = ( {
} }
); );
const onClickActions = () => { const onClick = ( e: React.MouseEvent< HTMLButtonElement > ) => {
if ( ( e.target as HTMLElement ).tagName === 'A' ) {
return;
}
if ( props.onClick ) { if ( props.onClick ) {
trackClick(); trackClick();
return props.onClick(); return props.onClick();
} }
goToTask(); goToTask();
}; };
return ( return (
<TaskItem <TaskItem
key={ taskId } key={ taskId }
@ -87,12 +91,9 @@ export const TaskListItem: React.FC< TaskListItemProps > = ( {
completed={ isComplete } completed={ isComplete }
additionalInfo={ additionalInfo } additionalInfo={ additionalInfo }
content={ content } content={ content }
onClick={ ( e: React.MouseEvent< HTMLButtonElement > ) => { onClick={
if ( ( e.target as HTMLElement ).tagName === 'A' ) { props.isClickable === false ? undefined : onClick
return; }
}
onClickActions();
} }
onDismiss={ onDismiss={
isDismissable ? () => onDismissTask() : undefined isDismissable ? () => onDismissTask() : undefined
} }

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Fix Launch Your Store task item should not be clickable once completed