2019-10-21 03:11:21 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import { addFilter } from '@wordpress/hooks';
|
|
|
|
import apiFetch from '@wordpress/api-fetch';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* WooCommerce dependencies
|
|
|
|
*/
|
2021-01-27 18:40:02 +00:00
|
|
|
import { Card, CardBody } from '@wordpress/components';
|
2019-10-21 03:11:21 +00:00
|
|
|
import { getHistory, getNewPath } from '@woocommerce/navigation';
|
|
|
|
|
|
|
|
/* global addTaskData */
|
|
|
|
const markTaskComplete = () => {
|
|
|
|
apiFetch( {
|
2019-11-12 18:15:55 +00:00
|
|
|
path: '/wc-admin/options',
|
2019-10-21 03:11:21 +00:00
|
|
|
method: 'POST',
|
|
|
|
data: { woocommerce_admin_add_task_example_complete: true },
|
|
|
|
} )
|
|
|
|
.then( () => {
|
|
|
|
// Set the local `isComplete` to `true` so that task appears complete on the list.
|
|
|
|
addTaskData.isComplete = true;
|
|
|
|
// Redirect back to the root WooCommerce Admin page.
|
|
|
|
getHistory().push( getNewPath( {}, '/', {} ) );
|
|
|
|
} )
|
2020-02-14 02:23:21 +00:00
|
|
|
.catch( ( error ) => {
|
2019-10-21 03:11:21 +00:00
|
|
|
// Something went wrong with our update.
|
|
|
|
console.log( error );
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
|
|
|
const markTaskIncomplete = () => {
|
|
|
|
apiFetch( {
|
2019-11-12 18:15:55 +00:00
|
|
|
path: '/wc-admin/options',
|
2019-10-21 03:11:21 +00:00
|
|
|
method: 'POST',
|
|
|
|
data: { woocommerce_admin_add_task_example_complete: false },
|
|
|
|
} )
|
|
|
|
.then( () => {
|
|
|
|
addTaskData.isComplete = false;
|
|
|
|
getHistory().push( getNewPath( {}, '/', {} ) );
|
|
|
|
} )
|
2020-02-14 02:23:21 +00:00
|
|
|
.catch( ( error ) => {
|
2019-10-21 03:11:21 +00:00
|
|
|
console.log( error );
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
|
|
|
const Task = () => {
|
|
|
|
return (
|
2020-12-21 19:05:29 +00:00
|
|
|
<Card className="woocommerce-task-card">
|
2021-01-27 18:40:02 +00:00
|
|
|
<CardBody>
|
|
|
|
{ __( 'Example task card content.', 'plugin-domain' ) }
|
|
|
|
<br />
|
|
|
|
<br />
|
|
|
|
<div>
|
|
|
|
{ addTaskData.isComplete ? (
|
|
|
|
<button onClick={ markTaskIncomplete }>
|
|
|
|
{ __( 'Mark task incomplete', 'plugin-domain' ) }
|
|
|
|
</button>
|
|
|
|
) : (
|
|
|
|
<button onClick={ markTaskComplete }>
|
|
|
|
{ __( 'Mark task complete', 'plugin-domain' ) }
|
|
|
|
</button>
|
|
|
|
) }
|
|
|
|
</div>
|
|
|
|
</CardBody>
|
2019-10-21 03:11:21 +00:00
|
|
|
</Card>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2019-11-25 16:15:22 +00:00
|
|
|
* Use the 'woocommerce_admin_onboarding_task_list' filter to add a task page.
|
2019-10-21 03:11:21 +00:00
|
|
|
*/
|
2020-02-14 02:23:21 +00:00
|
|
|
addFilter(
|
|
|
|
'woocommerce_admin_onboarding_task_list',
|
|
|
|
'plugin-domain',
|
|
|
|
( tasks ) => {
|
|
|
|
return [
|
|
|
|
...tasks,
|
|
|
|
{
|
|
|
|
key: 'example',
|
|
|
|
title: __( 'Example', 'plugin-domain' ),
|
|
|
|
content: __( 'This is an example task.', 'plugin-domain' ),
|
|
|
|
container: <Task />,
|
|
|
|
completed: addTaskData.isComplete,
|
|
|
|
visible: true,
|
2020-12-03 21:16:04 +00:00
|
|
|
additionalInfo: __( 'Additional info here', 'woocommerce-admin' ),
|
|
|
|
time: __( '2 minutes', 'woocommerce-admin' ),
|
|
|
|
isDismissable: true,
|
2021-03-23 22:10:32 +00:00
|
|
|
onDismiss: () => console.log( 'The task was dismissed' ),
|
2020-02-14 02:23:21 +00:00
|
|
|
},
|
|
|
|
];
|
|
|
|
}
|
|
|
|
);
|