Add trash workflow action
[MAILPOET-4540]
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import { __ } from '@wordpress/i18n';
|
import { __ } from '@wordpress/i18n';
|
||||||
import { DropdownMenu } from '@wordpress/components';
|
import { DropdownMenu } from '@wordpress/components';
|
||||||
import { moreVertical } from '@wordpress/icons';
|
import { moreVertical } from '@wordpress/icons';
|
||||||
import { useDuplicateButton } from '../menu';
|
import { useDuplicateButton, useTrashButton } from '../menu';
|
||||||
import { Workflow } from '../../workflow';
|
import { Workflow } from '../../workflow';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
@@ -12,8 +12,9 @@ export function More({ workflow }: Props): JSX.Element {
|
|||||||
// Menu items are using custom hooks because the "DropdownMenu" component uses the "controls"
|
// Menu items are using custom hooks because the "DropdownMenu" component uses the "controls"
|
||||||
// attribute rather than child components, but we need to render modal confirmation dialogs.
|
// attribute rather than child components, but we need to render modal confirmation dialogs.
|
||||||
const duplicate = useDuplicateButton(workflow);
|
const duplicate = useDuplicateButton(workflow);
|
||||||
|
const trash = useTrashButton(workflow);
|
||||||
|
|
||||||
const menuItems = [duplicate].filter((item) => item);
|
const menuItems = [duplicate, trash].filter((item) => item);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
@@ -1 +1,2 @@
|
|||||||
export * from './duplicate';
|
export * from './duplicate';
|
||||||
|
export * from './trash';
|
||||||
|
@@ -0,0 +1,22 @@
|
|||||||
|
import { useDispatch } from '@wordpress/data';
|
||||||
|
import { __ } from '@wordpress/i18n';
|
||||||
|
import { Item } from './item';
|
||||||
|
import { storeName } from '../../store';
|
||||||
|
import { Workflow, WorkflowStatus } from '../../workflow';
|
||||||
|
|
||||||
|
export const useTrashButton = (workflow: Workflow): Item | undefined => {
|
||||||
|
const { trashWorkflow } = useDispatch(storeName);
|
||||||
|
|
||||||
|
if (workflow.status === WorkflowStatus.TRASH) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
key: 'trash',
|
||||||
|
control: {
|
||||||
|
title: __('Trash', 'mailpoet'),
|
||||||
|
icon: null,
|
||||||
|
onClick: () => trashWorkflow(workflow),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
Reference in New Issue
Block a user