Added email note support
This commit adds email note support
This commit is contained in:
parent
abddff5034
commit
9cc8326de2
|
@ -6,6 +6,11 @@ register_woocommerce_admin_test_helper_rest_route(
|
||||||
'admin_notes_add_note'
|
'admin_notes_add_note'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
register_woocommerce_admin_test_helper_rest_route(
|
||||||
|
'/admin-notes/add-email-note/v1',
|
||||||
|
'admin_notes_add_email_note'
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
function admin_notes_add_note( $request ) {
|
function admin_notes_add_note( $request ) {
|
||||||
$note = new Note();
|
$note = new Note();
|
||||||
|
@ -17,3 +22,28 @@ function admin_notes_add_note( $request ) {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function admin_notes_add_email_note( $request ) {
|
||||||
|
$note = new Note();
|
||||||
|
|
||||||
|
$additional_data = array(
|
||||||
|
'role' => 'administrator',
|
||||||
|
);
|
||||||
|
$action_name = sprintf(
|
||||||
|
'test-action-%s',
|
||||||
|
$request->get_param( 'name' )
|
||||||
|
);
|
||||||
|
|
||||||
|
$content = $request->get_param( 'content' ) ?? 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud.';
|
||||||
|
|
||||||
|
$note->set_name( $request->get_param( 'name' ) );
|
||||||
|
$note->set_title( $request->get_param( 'title' ) );
|
||||||
|
$note->set_type( 'email' );
|
||||||
|
$note->set_content( $content );
|
||||||
|
$note->set_content_data( (object) $additional_data );
|
||||||
|
$note->add_action( $action_name, 'Test action', wc_admin_url() );
|
||||||
|
|
||||||
|
$note->save();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,82 @@
|
||||||
|
/**
|
||||||
|
* External dependencies.
|
||||||
|
*/
|
||||||
|
import { useState } from '@wordpress/element';
|
||||||
|
import { Button } from '@wordpress/components';
|
||||||
|
import apiFetch from '@wordpress/api-fetch';
|
||||||
|
|
||||||
|
export const AddEmailNote = () => {
|
||||||
|
const [isAdding, setIsAdding] = useState(false);
|
||||||
|
const [hasAdded, setHasAdded] = useState(false);
|
||||||
|
const [errorMessage, setErrorMessage] = useState(false);
|
||||||
|
|
||||||
|
async function triggerAddEmailNote() {
|
||||||
|
setIsAdding(true);
|
||||||
|
setHasAdded(false);
|
||||||
|
setErrorMessage(false);
|
||||||
|
|
||||||
|
const name = prompt('Enter the note name');
|
||||||
|
if (!name) {
|
||||||
|
setIsAdding(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const title = prompt('Enter the note title');
|
||||||
|
if (!title) {
|
||||||
|
setIsAdding(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await apiFetch({
|
||||||
|
path: '/wc-admin-test-helper/admin-notes/add-email-note/v1',
|
||||||
|
method: 'POST',
|
||||||
|
data: {
|
||||||
|
name,
|
||||||
|
title,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
setHasAdded(true);
|
||||||
|
} catch (ex) {
|
||||||
|
setErrorMessage(ex.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
setIsAdding(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<p>
|
||||||
|
<strong>
|
||||||
|
Add an <u>email</u> note
|
||||||
|
</strong>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
This will add a new <strong>email</strong> note. Enable email
|
||||||
|
insights{' '}
|
||||||
|
<a href="/wp-admin/admin.php?page=wc-settings&tab=email">
|
||||||
|
here
|
||||||
|
</a>{' '}
|
||||||
|
and run the cron to send the note by email.
|
||||||
|
<br />
|
||||||
|
<Button
|
||||||
|
onClick={triggerAddEmailNote}
|
||||||
|
disabled={isAdding}
|
||||||
|
isPrimary
|
||||||
|
>
|
||||||
|
Add email note
|
||||||
|
</Button>
|
||||||
|
<br />
|
||||||
|
<span className="woocommerce-admin-test-helper__action-status">
|
||||||
|
{isAdding && 'Adding, please wait'}
|
||||||
|
{hasAdded && 'Email note added'}
|
||||||
|
{errorMessage && (
|
||||||
|
<>
|
||||||
|
<strong>Error:</strong> {errorMessage}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
|
</p>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
|
@ -3,6 +3,7 @@
|
||||||
*/
|
*/
|
||||||
import { DeleteAllNotes } from './delete-all-notes';
|
import { DeleteAllNotes } from './delete-all-notes';
|
||||||
import { AddNote } from './add-note';
|
import { AddNote } from './add-note';
|
||||||
|
import { AddEmailNote } from './add-email-note';
|
||||||
|
|
||||||
export const AdminNotes = () => {
|
export const AdminNotes = () => {
|
||||||
return (
|
return (
|
||||||
|
@ -10,6 +11,7 @@ export const AdminNotes = () => {
|
||||||
<h2>Admin notes</h2>
|
<h2>Admin notes</h2>
|
||||||
<p>This section contains tools for managing admin notes.</p>
|
<p>This section contains tools for managing admin notes.</p>
|
||||||
<AddNote />
|
<AddNote />
|
||||||
|
<AddEmailNote />
|
||||||
<DeleteAllNotes />
|
<DeleteAllNotes />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue