From f2a207942dbd67bf56aef215c57d5bf3f1de375a Mon Sep 17 00:00:00 2001 From: Jan Jakes Date: Thu, 25 Aug 2022 13:51:08 +0200 Subject: [PATCH] Implement add trigger placeholder & button [PREMIUM-194] [MAILPOET-4585] --- .../_add-trigger.scss | 19 ++++++++++++ .../css/src/mailpoet-automation-editor.scss | 1 + .../components/workflow/add-trigger.tsx | 30 +++++++++++++++++++ .../editor/components/workflow/index.tsx | 13 +++++--- mailpoet/assets/js/src/automation/testing.tsx | 22 +++++++++++--- 5 files changed, 77 insertions(+), 8 deletions(-) create mode 100644 mailpoet/assets/css/src/components-automation-editor/_add-trigger.scss create mode 100644 mailpoet/assets/js/src/automation/editor/components/workflow/add-trigger.tsx diff --git a/mailpoet/assets/css/src/components-automation-editor/_add-trigger.scss b/mailpoet/assets/css/src/components-automation-editor/_add-trigger.scss new file mode 100644 index 0000000000..c57a2d7ab2 --- /dev/null +++ b/mailpoet/assets/css/src/components-automation-editor/_add-trigger.scss @@ -0,0 +1,19 @@ +.mailpoet-automation-workflow-add-trigger { + align-items: center; + border: 1px dashed #c3c4c7; + border-radius: 4px; + color: #757575; + cursor: pointer; + display: flex; + fill: #757575; + height: 73px; + justify-content: center; + margin: 4px auto; + padding: 20px 32px; + + &:focus { + box-shadow: + 0 0 0 1px #fbfbfb, // space + 0 0 0 calc(var(--wp-admin-border-width-focus) + 1px) var(--wp-admin-theme-color), // focus ring + } +} diff --git a/mailpoet/assets/css/src/mailpoet-automation-editor.scss b/mailpoet/assets/css/src/mailpoet-automation-editor.scss index c949d9e28e..8b4ddd56af 100644 --- a/mailpoet/assets/css/src/mailpoet-automation-editor.scss +++ b/mailpoet/assets/css/src/mailpoet-automation-editor.scss @@ -4,6 +4,7 @@ @import '../../../node_modules/@wordpress/block-editor/build-style/style'; // for inserter styles @import 'settings/colors'; @import './components-automation-editor/add-step-button'; +@import './components-automation-editor/add-trigger'; @import './components-automation-editor/block-icon'; @import './components-automation-editor/dropdown'; @import './components-automation-editor/empty-workflow'; diff --git a/mailpoet/assets/js/src/automation/editor/components/workflow/add-trigger.tsx b/mailpoet/assets/js/src/automation/editor/components/workflow/add-trigger.tsx new file mode 100644 index 0000000000..96d7e6a81c --- /dev/null +++ b/mailpoet/assets/js/src/automation/editor/components/workflow/add-trigger.tsx @@ -0,0 +1,30 @@ +import { useContext } from 'react'; +import { __unstableCompositeItem as CompositeItem } from '@wordpress/components'; +import { Icon, plus } from '@wordpress/icons'; +import { __ } from '@wordpress/i18n'; +import { useDispatch } from '@wordpress/data'; +import { WorkflowCompositeContext } from './context'; +import { store } from '../../store'; + +export function AddTrigger(): JSX.Element { + const compositeState = useContext(WorkflowCompositeContext); + const { setInserterPopoverAnchor } = useDispatch(store); + + return ( + { + event.stopPropagation(); + setInserterPopoverAnchor( + (event.target as HTMLElement).closest('button'), + ); + }} + > + + {__('Add trigger', 'mailpoet')} + + ); +} diff --git a/mailpoet/assets/js/src/automation/editor/components/workflow/index.tsx b/mailpoet/assets/js/src/automation/editor/components/workflow/index.tsx index 6e03603521..0eebfaff2d 100644 --- a/mailpoet/assets/js/src/automation/editor/components/workflow/index.tsx +++ b/mailpoet/assets/js/src/automation/editor/components/workflow/index.tsx @@ -12,6 +12,7 @@ import { Separator } from './separator'; import { Step } from './step'; import { InserterPopover } from '../inserter-popover'; import { store } from '../../store'; +import { AddTrigger } from './add-trigger'; export function Workflow(): JSX.Element { const { workflowData, selectedStep } = useSelect( @@ -75,10 +76,14 @@ export function Workflow(): JSX.Element {
{steps.map((step) => ( - + {step.type === 'trigger' && step.key === 'core:empty' ? ( + + ) : ( + + )} ))} diff --git a/mailpoet/assets/js/src/automation/testing.tsx b/mailpoet/assets/js/src/automation/testing.tsx index 20054a1ffe..4ddb833032 100644 --- a/mailpoet/assets/js/src/automation/testing.tsx +++ b/mailpoet/assets/js/src/automation/testing.tsx @@ -1,10 +1,24 @@ import { ReactNode } from 'react'; import { useMutation } from './api'; +import { id } from './id'; -const createWorkflow = () => ({ - name: 'Empty workflow', - steps: {}, -}); +export const createEmptyTrigger = () => + ({ + id: id(), + type: 'trigger', + key: 'core:empty', + args: {}, + } as const); + +const createWorkflow = () => { + const emptyTrigger = createEmptyTrigger(); + return { + name: 'Empty workflow', + steps: { + [emptyTrigger.id]: emptyTrigger, + }, + }; +}; export function CreateEmptyWorkflowButton(): JSX.Element { const [createSchema, { loading, error }] = useMutation('workflows', {