2021-09-21 19:33:44 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { WooOnboardingTask } from '@woocommerce/onboarding';
|
2021-10-01 19:53:22 +00:00
|
|
|
import { getHistory, getNewPath } from '@woocommerce/navigation';
|
2021-10-06 18:47:41 +00:00
|
|
|
import { ONBOARDING_STORE_NAME, TaskType } from '@woocommerce/data';
|
2021-10-01 19:53:22 +00:00
|
|
|
import { useCallback } from '@wordpress/element';
|
|
|
|
import { useDispatch } from '@wordpress/data';
|
2021-09-21 19:33:44 +00:00
|
|
|
|
2021-09-01 21:28:24 +00:00
|
|
|
export type TaskProps = {
|
|
|
|
query: { task: string };
|
2021-10-06 18:47:41 +00:00
|
|
|
task?: TaskType;
|
2021-09-01 21:28:24 +00:00
|
|
|
};
|
|
|
|
|
2021-10-06 18:47:41 +00:00
|
|
|
export const Task: React.FC< TaskProps > = ( { query, task } ) => {
|
2021-10-01 19:53:22 +00:00
|
|
|
const id = query.task;
|
|
|
|
const {
|
|
|
|
invalidateResolutionForStoreSelector,
|
|
|
|
optimisticallyCompleteTask,
|
|
|
|
} = useDispatch( ONBOARDING_STORE_NAME );
|
|
|
|
|
|
|
|
const onComplete = useCallback( () => {
|
|
|
|
optimisticallyCompleteTask( id );
|
|
|
|
getHistory().push( getNewPath( {}, '/', {} ) );
|
|
|
|
invalidateResolutionForStoreSelector( 'getTaskLists' );
|
|
|
|
}, [ id ] );
|
|
|
|
|
|
|
|
return (
|
|
|
|
<WooOnboardingTask.Slot id={ id } fillProps={ { onComplete, query } } />
|
|
|
|
);
|
|
|
|
};
|