2023-05-18 03:21:53 +00:00
/* eslint-disable @wordpress/i18n-text-domain */
2019-10-21 03:11:21 +00:00
/ * *
* External dependencies
* /
2023-05-18 03:21:53 +00:00
import { createElement } from '@wordpress/element' ;
2019-10-21 03:11:21 +00:00
import { _ _ } from '@wordpress/i18n' ;
2021-01-27 18:40:02 +00:00
import { Card , CardBody } from '@wordpress/components' ;
2021-10-27 19:03:27 +00:00
import { ONBOARDING _STORE _NAME } from '@woocommerce/data' ;
import { registerPlugin } from '@wordpress/plugins' ;
import { useDispatch } from '@wordpress/data' ;
2023-05-18 03:21:53 +00:00
import {
WooOnboardingTask ,
WooOnboardingTaskListItem ,
} from '@woocommerce/onboarding' ;
2019-10-21 03:11:21 +00:00
2021-10-27 19:03:27 +00:00
const Task = ( { onComplete , task } ) => {
const { actionTask } = useDispatch ( ONBOARDING _STORE _NAME ) ;
const { isActioned } = task ;
2019-10-21 03:11:21 +00:00
return (
2020-12-21 19:05:29 +00:00
< Card className = "woocommerce-task-card" >
2021-01-27 18:40:02 +00:00
< CardBody >
2021-10-27 19:03:27 +00:00
{ _ _ (
"This task's completion status is dependent on being actioned. The action button below will action this task, while the complete button will optimistically complete the task in the task list and redirect back to the task list. Note that in this example, the task must be actioned for completion to persist." ,
'plugin-domain'
) } { ' ' }
< br / >
< br / >
{ _ _ ( 'Task actioned status: ' , 'plugin-domain' ) } { ' ' }
{ isActioned ? 'actioned' : 'not actioned' }
2021-01-27 18:40:02 +00:00
< br / >
< br / >
< div >
2021-10-27 19:03:27 +00:00
< button
onClick = { ( ) => {
actionTask ( 'my-task' ) ;
} }
>
{ _ _ ( 'Action task' , 'plugin-domain' ) }
< / b u t t o n >
< button onClick = { onComplete } >
{ _ _ ( 'Complete' , 'plugin-domain' ) }
< / b u t t o n >
2021-01-27 18:40:02 +00:00
< / d i v >
< / C a r d B o d y >
2019-10-21 03:11:21 +00:00
< / C a r d >
) ;
} ;
2021-10-27 19:03:27 +00:00
registerPlugin ( 'add-task-content' , {
render : ( ) => (
< WooOnboardingTask id = "my-task" >
2023-05-18 03:21:53 +00:00
{ ( {
onComplete ,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
query ,
task ,
} ) => < Task onComplete = { onComplete } task = { task } / > }
2021-10-27 19:03:27 +00:00
< / W o o O n b o a r d i n g T a s k >
) ,
scope : 'woocommerce-tasks' ,
} ) ;
2023-05-18 03:21:53 +00:00
registerPlugin ( 'my-task-list-item-plugin' , {
scope : 'woocommerce-tasks' ,
render : ( ) => (
< WooOnboardingTaskListItem id = "my-task" >
{ ( { defaultTaskItem : DefaultTaskItem } ) => (
// Add a custom wrapper around the default task item.
< div
className = "woocommerce-custom-tasklist-item"
style = { {
border : '1px solid red' ,
} }
>
< DefaultTaskItem / >
< / d i v >
) }
< / W o o O n b o a r d i n g T a s k L i s t I t e m >
) ,
} ) ;