Add trash workflow action

[MAILPOET-4540]
This commit is contained in:
Jan Jakes
2022-10-18 09:38:49 +02:00
committed by David Remer
parent fe1a994442
commit 2cb20a8f63
3 changed files with 26 additions and 2 deletions

View File

@@ -1,7 +1,7 @@
import { __ } from '@wordpress/i18n';
import { DropdownMenu } from '@wordpress/components';
import { moreVertical } from '@wordpress/icons';
import { useDuplicateButton } from '../menu';
import { useDuplicateButton, useTrashButton } from '../menu';
import { Workflow } from '../../workflow';
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"
// attribute rather than child components, but we need to render modal confirmation dialogs.
const duplicate = useDuplicateButton(workflow);
const trash = useTrashButton(workflow);
const menuItems = [duplicate].filter((item) => item);
const menuItems = [duplicate, trash].filter((item) => item);
return (
<>

View File

@@ -1 +1,2 @@
export * from './duplicate';
export * from './trash';

View File

@@ -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),
},
};
};