2021-10-12 14:05:43 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { registerPlugin } from '@wordpress/plugins';
|
|
|
|
import { WooOnboardingTask } from '@woocommerce/onboarding';
|
|
|
|
import { useSelect } from '@wordpress/data';
|
2022-06-14 02:23:40 +00:00
|
|
|
import {
|
|
|
|
ONBOARDING_STORE_NAME,
|
|
|
|
TaskType,
|
|
|
|
DeprecatedTaskType,
|
|
|
|
} from '@woocommerce/data';
|
2021-10-12 14:05:43 +00:00
|
|
|
import { useEffect, useState } from '@wordpress/element';
|
|
|
|
|
2022-06-14 02:23:40 +00:00
|
|
|
type MergedTask = TaskType & DeprecatedTaskType;
|
2022-04-21 04:44:19 +00:00
|
|
|
|
2021-10-12 14:05:43 +00:00
|
|
|
const DeprecatedWooOnboardingTaskFills = () => {
|
2022-06-14 02:23:40 +00:00
|
|
|
const [ deprecatedTasks, setDeprecatedTasks ] = useState< MergedTask[] >(
|
|
|
|
[]
|
|
|
|
);
|
2022-04-25 05:49:11 +00:00
|
|
|
const { isResolving, taskLists } = useSelect( ( select ) => {
|
|
|
|
return {
|
|
|
|
isResolving: select( ONBOARDING_STORE_NAME ).isResolving(
|
|
|
|
'getTaskLists'
|
|
|
|
),
|
|
|
|
taskLists: select( ONBOARDING_STORE_NAME ).getTaskLists(),
|
|
|
|
};
|
|
|
|
} );
|
2021-10-12 14:05:43 +00:00
|
|
|
|
|
|
|
useEffect( () => {
|
|
|
|
if ( taskLists && taskLists.length > 0 ) {
|
2022-06-14 02:23:40 +00:00
|
|
|
const deprecatedTasksWithContainer: MergedTask[] = [];
|
2021-10-12 14:05:43 +00:00
|
|
|
for ( const tasklist of taskLists ) {
|
|
|
|
for ( const task of tasklist.tasks ) {
|
2022-04-25 06:16:39 +00:00
|
|
|
if (
|
2022-06-14 02:23:40 +00:00
|
|
|
( task as MergedTask ).isDeprecated &&
|
|
|
|
( task as MergedTask ).container
|
2022-04-25 06:16:39 +00:00
|
|
|
) {
|
2022-06-14 02:23:40 +00:00
|
|
|
deprecatedTasksWithContainer.push( task as MergedTask );
|
2021-10-12 14:05:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-06-14 02:23:40 +00:00
|
|
|
setDeprecatedTasks( deprecatedTasksWithContainer );
|
2021-10-12 14:05:43 +00:00
|
|
|
}
|
|
|
|
}, [ taskLists ] );
|
|
|
|
|
|
|
|
if ( isResolving ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{ deprecatedTasks.map( ( task ) => (
|
|
|
|
<WooOnboardingTask id={ task.id } key={ task.id }>
|
2022-04-21 04:44:19 +00:00
|
|
|
{ () => task.container }
|
2021-10-12 14:05:43 +00:00
|
|
|
</WooOnboardingTask>
|
|
|
|
) ) }
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
registerPlugin( 'wc-admin-deprecated-task-container', {
|
2022-04-21 04:44:19 +00:00
|
|
|
// @ts-expect-error @types/wordpress__plugins need to be updated
|
2021-10-12 14:05:43 +00:00
|
|
|
scope: 'woocommerce-tasks',
|
|
|
|
render: () => <DeprecatedWooOnboardingTaskFills />,
|
|
|
|
} );
|