The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Allow raw HTML blocks in workflow email bodies (#26528)
neo77388ff3f863453
diff --git a/packages/twenty-front/src/modules/advanced-text-editor/components/FormAdvancedTextFieldInput.tsx b/packages/twenty-front/src/modules/advanced-text-editor/components/FormAdvancedTextFieldInput.tsxindex 5d78e7da56d..d86e810dde0 100644--- a/packages/twenty-front/src/modules/advanced-text-editor/components/FormAdvancedTextFieldInput.tsx+++ b/packages/twenty-front/src/modules/advanced-text-editor/components/FormAdvancedTextFieldInput.tsx@@ -189,7 +189,14 @@ export const FormAdvancedTextFieldInput = ({);}- editor.commands.insertVariableTag(variableName);+ const focusedHtmlEditor = editor.storage.html?.focusedHtmlEditor;++ const variableTargetEditor =+ isDefined(focusedHtmlEditor) && !focusedHtmlEditor.isDestroyed+ ? focusedHtmlEditor+ : editor;++ variableTargetEditor.commands.insertVariableTag(variableName);};const defaultBreadcrumbs: BreadcrumbProps['links'] = [diff --git a/packages/twenty-front/src/modules/advanced-text-editor/extensions/blocks/HtmlNode.ts b/packages/twenty-front/src/modules/advanced-text-editor/extensions/blocks/HtmlNode.tsindex 6b6ce444c72..b4aafe2eaaf 100644--- a/packages/twenty-front/src/modules/advanced-text-editor/extensions/blocks/HtmlNode.ts+++ b/packages/twenty-front/src/modules/advanced-text-editor/extensions/blocks/HtmlNode.ts@@ -1,21 +1,55 @@-import { Node } from '@tiptap/core';+import { type Editor, Node } from '@tiptap/core';import { ReactNodeViewRenderer } from '@tiptap/react';import { TIPTAP_NODE_TYPES } from 'twenty-shared/utils';import { HtmlNodeView } from '@/advanced-text-editor/extensions/blocks/HtmlNodeView';-const DEFAULT_HTML_BLOCK =- '<p style="margin: 0;">Edit this HTML in the block settings panel.</p>';+type HtmlNodeOptions = {+ isInlineEditable: boolean;+ defaultHtml: string;+};-export const HtmlNode = Node.create({+type HtmlNodeStorage = {+ focusedHtmlEditor: Editor | null;+};++declare module '@tiptap/core' {+ interface Storage {+ html?: HtmlNodeStorage;+ }+}++export const HtmlNode = Node.create<HtmlNodeOptions, HtmlNodeStorage>({name: TIPTAP_NODE_TYPES.HTML,group: 'block',atom: true,+ selectable() {+ return !this.options.isInlineEditable;+ },++ addOptions() {+ return {+ isInlineEditable: false,+ defaultHtml:+ '<p style="margin: 0;">Edit this HTML in the block settings panel.</p>',+ };+ },++ addStorage() {+ return {+ focusedHtmlEditor: null,+ };+ },++ onFocus() {+ this.storage.focusedHtmlEditor = null;+ },+addAttributes() {return {html: {- default: DEFAULT_HTML_BLOCK,+ default: this.options.defaultHtml,parseHTML: (element) => element.getAttribute('data-html'),renderHTML: (attributes) => ({ 'data-html': attributes.html }),},diff --git a/packages/twenty-front/src/modules/advanced-text-editor/extensions/blocks/HtmlNodeInlineEditor.tsx b/packages/twenty-front/src/modules/advanced-text-editor/extensions/blocks/HtmlNodeInlineEditor.tsxnew file mode 100644index 00000000000..cbea82f5ec3--- /dev/null+++ b/packages/twenty-front/src/modules/advanced-text-editor/extensions/blocks/HtmlNodeInlineEditor.tsx@@ -0,0 +1,61 @@+import { styled } from '@linaria/react';+import { t } from '@lingui/core/macro';+import { EditorContent, type Editor } from '@tiptap/react';+import { isDefined } from 'twenty-shared/utils';+import { themeCssVariables } from 'twenty-ui/theme-constants';++import { useTextVariableEditor } from '@/object-record/record-field/ui/form-types/hooks/useTextVariableEditor';+import { FORM_FIELD_PLACEHOLDER_STYLES } from '@/ui/input/constants/FormFieldPlaceholderStyles';++type HtmlNodeInlineEditorProps = {+ html: string;+ onChange: (html: string) => void;+ onFocus: (htmlEditor: Editor) => void;+};++const StyledHtmlEditor = styled.div`+ .tiptap {+ color: ${themeCssVariables.font.color.primary};+ font-family: ${themeCssVariables.code.font.family};+ font-size: ${themeCssVariables.font.size.sm};+ outline: none;+ overflow-wrap: anywhere;+ white-space: pre-wrap;++ p {+ margin: 0;+ }++ p.is-editor-empty:first-of-type::before {+ ${FORM_FIELD_PLACEHOLDER_STYLES}+ content: attr(data-placeholder);+ float: left;+ height: 0;+ pointer-events: none;+ }+ }+`;++export const HtmlNodeInlineEditor = ({+ html,+ onChange,+ onFocus,+}: HtmlNodeInlineEditorProps) => {+ const htmlEditor = useTextVariableEditor({+ placeholder: t`Paste or write your HTML here`,+ multiline: true,+ readonly: false,+ defaultValue: html,+ onUpdate: (editor) => onChange(editor.getText()),+ });++ if (!isDefined(htmlEditor)) {+ return null;+ }++ return (+ <StyledHtmlEditor onFocus={() => onFocus(htmlEditor)}>+ <EditorContent editor={htmlEditor} />+ </StyledHtmlEditor>+ );+};diff --git a/packages/twenty-front/src/modules/advanced-text-editor/extensions/blocks/HtmlNodeView.tsx b/packages/twenty-front/src/modules/advanced-text-editor/extensions/blocks/HtmlNodeView.tsxindex 824b5ea48bc..c482a0fdd56 100644--- a/packages/twenty-front/src/modules/advanced-text-editor/extensions/blocks/HtmlNodeView.tsx+++ b/packages/twenty-front/src/modules/advanced-text-editor/extensions/blocks/HtmlNodeView.tsx@@ -1,10 +1,15 @@import { styled } from '@linaria/react';import { NodeViewWrapper, type NodeViewProps } from '@tiptap/react';+import { isDefined } from 'twenty-shared/utils';import { themeCssVariables } from 'twenty-ui/theme-constants';+import { HtmlNodeInlineEditor } from '@/advanced-text-editor/extensions/blocks/HtmlNodeInlineEditor';import { sanitizeHtmlPreview } from '@/advanced-text-editor/utils/sanitizeHtmlPreview';-type HtmlNodeViewProps = Pick<NodeViewProps, 'node'>;+type HtmlNodeViewProps = Pick<+ NodeViewProps,+ 'node' | 'editor' | 'extension' | 'updateAttributes'+>;const StyledPreview = styled.div`border-radius: ${themeCssVariables.border.radius.sm};@@ -16,9 +21,30 @@ const StyledPreview = styled.div`}`;-export const HtmlNodeView = ({ node }: HtmlNodeViewProps) => {+export const HtmlNodeView = ({+ node,+ editor,+ extension,+ updateAttributes,+}: HtmlNodeViewProps) => {const html = typeof node.attrs.html === 'string' ? node.attrs.html : '';+ if (extension.options.isInlineEditable === true && editor.isEditable) {+ return (+ <NodeViewWrapper>+ <HtmlNodeInlineEditor+ html={html}+ onChange={(value) => updateAttributes({ html: value })}+ onFocus={(htmlEditor) => {+ if (isDefined(editor.storage.html)) {+ editor.storage.html.focusedHtmlEditor = htmlEditor;+ }+ }}+ />+ </NodeViewWrapper>+ );+ }+return (<NodeViewWrapper><StyledPreviewdiff --git a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/constants/WorkflowEmailBodyEditorProfile.ts b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/constants/WorkflowEmailBodyEditorProfile.tsindex 26f2b579ff3..d7563fbe93e 100644--- a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/constants/WorkflowEmailBodyEditorProfile.ts+++ b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/constants/WorkflowEmailBodyEditorProfile.ts@@ -1,3 +1,4 @@+import { HtmlNode } from '@/advanced-text-editor/extensions/blocks/HtmlNode';import { type AdvancedTextEditorProfile } from '@/advanced-text-editor/types/AdvancedTextEditorProfile';import { buildFullRichTextExtensions } from '@/advanced-text-editor/utils/buildFullRichTextExtensions';import { parseLegacyWorkflowEmailBodyDocument } from '@/workflow/workflow-steps/workflow-actions/utils/parseLegacyWorkflowEmailBodyDocument';@@ -11,5 +12,6 @@ export const WORKFLOW_EMAIL_BODY_EDITOR_PROFILE = {buildExtensions: (context) => [...buildFullRichTextExtensions(context),WorkflowVariableTag,+ HtmlNode.configure({ isInlineEditable: true, defaultHtml: '' }),],} satisfies AdvancedTextEditorProfile;