Allow editing workflow templates (#8028)

* add event end time as variable

* add timezone as new variable

* add first version of template prefill

* set template body when template is updated

* set reminder template body and subject when creating workflow

* set email subject when changes templates

* save emailBody and emailsubject for all templates + fix duplicate template text

* add more flexibility for templates

* remove console.log

* fix {ORAGANIZER} and {ATTENDEE} variable

* make sure to always send reminder body and not default template

* fix import

* remove email body text and match variables in templates

* handle translations of formatted variables

* fix email reminder template

* add cancel and reschedule link as variable

* add cancel and reschedule link for scheduled emails/sms

* make sure empty empty body and subject are set for reminder template

* add info message for testing workflow

* fix typo

* add sms template

* add migration to remove reminderBody and emailSubject

* add branding

* code clean up

* add hide branding everywhere

* fix sms reminder template

* set sms reminder template if sms body is empty

* fix custom inputs variables everywhere

* fix variable translations + other small fixes

* fix some type errors

* fix more type errors

* fix everything missing around cron job scheduling

* make sure to always use custom template for sms messages

* fix type error

* code clean up

* rename link to url

* Add debug logs

* Update handleNewBooking.ts

* Add debug logs

* removed unneded responses

* fix booking questions + UI improvements

* remove html email body when changing to sms action

* code clean up + comments

* code clean up

* code clean up

* remove comment

* more clear info message for timezone variable

---------

Co-authored-by: CarinaWolli <[email protected]>
Co-authored-by: Hariom Balhara <[email protected]>
Co-authored-by: zomars <[email protected]>
Co-authored-by: alannnc <[email protected]>
This commit is contained in:
authored and GitHub committed 2023-04-18 11:08:09 +01:00
1 parent c0bda6257e
commit 0aca769d06
26 files changed
+724 -365

No files matched your search

+7
View File
@@ -10,6 +10,7 @@ import { MarkdownShortcutPlugin } from "@lexical/react/LexicalMarkdownShortcutPl
import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin";
import { HeadingNode, QuoteNode } from "@lexical/rich-text";
import { TableCellNode, TableNode, TableRowNode } from "@lexical/table";
import type { Dispatch, SetStateAction } from "react";
import { classNames } from "@calcom/lib";
@@ -33,6 +34,9 @@ export type TextEditorProps = {
height?: string;
placeholder?: string;
disableLists?: boolean;
updateTemplate?: boolean;
firstRender?: boolean;
setFirstRender?: Dispatch<SetStateAction<boolean>>;
editable?: boolean;
};
@@ -69,6 +73,9 @@ export const Editor = (props: TextEditorProps) => {
editable={editable}
excludedToolbarItems={props.excludedToolbarItems}
variables={props.variables}
updateTemplate={props.updateTemplate}
firstRender={props.firstRender}
setFirstRender={props.setFirstRender}
/>
<div
className={classNames("editor-inner scroll-bar", !editable && "bg-muted")}
@@ -32,29 +32,31 @@ export const AddVariablesDropdown = (props: IAddVariablesDropdown) => {
)}
</div>
</DropdownMenuTrigger>
<DropdownMenuContent className="h-40 overflow-scroll">
<DropdownMenuContent>
<div className="pt-4 pb-1">
<div className="text-subtle mb-2 px-4 text-left text-xs">
{t("add_dynamic_variables").toLocaleUpperCase()}
</div>
{props.variables.map((variable) => (
<DropdownMenuItem key={variable} className="hover:ring-0">
<button
key={variable}
type="button"
className="w-full px-4 py-2"
onClick={() => props.addVariable(t(`${variable}_variable`))}>
<div className="sm:grid sm:grid-cols-2">
<div className="mr-3 text-left md:col-span-1">
{`{${t(`${variable}_variable`).toUpperCase().replace(/ /g, "_")}}`}
<div className="h-64 overflow-scroll md:h-80">
{props.variables.map((variable) => (
<DropdownMenuItem key={variable} className="hover:ring-0">
<button
key={variable}
type="button"
className="w-full px-4 py-2"
onClick={() => props.addVariable(t(`${variable}_variable`))}>
<div className="sm:grid sm:grid-cols-2">
<div className="mr-3 text-left md:col-span-1">
{`{${t(`${variable}_variable`).toUpperCase().replace(/ /g, "_")}}`}
</div>
<div className="text-default hidden text-left sm:col-span-1 sm:flex">
{t(`${variable}_info`)}
</div>
</div>
<div className="text-default hidden text-left sm:col-span-1 sm:flex">
{t(`${variable}_info`)}
</div>
</div>
</button>
</DropdownMenuItem>
))}
</button>
</DropdownMenuItem>
))}
</div>
</div>
</DropdownMenuContent>
</Dropdown>
@@ -340,23 +340,47 @@ export default function ToolbarPlugin(props: TextEditorProps) {
};
useEffect(() => {
editor.update(() => {
const parser = new DOMParser();
const dom = parser.parseFromString(props.getText(), "text/html");
if (!props.firstRender) {
editor.update(() => {
const root = $getRoot();
if (root) {
editor.update(() => {
const parser = new DOMParser();
// Create a new TextNode
const dom = parser.parseFromString(props.getText(), "text/html");
const nodes = $generateNodesFromDOM(editor, dom);
$getRoot().select();
$insertNodes(nodes);
editor.registerUpdateListener(({ editorState, prevEditorState }) => {
editorState.read(() => {
const textInHtml = $generateHtmlFromNodes(editor).replace(/&lt;/g, "<").replace(/&gt;/g, ">");
props.setText(textInHtml);
});
if (!prevEditorState._selection) editor.blur();
const nodes = $generateNodesFromDOM(editor, dom);
const paragraph = $createParagraphNode();
root.clear().append(paragraph);
paragraph.select();
$insertNodes(nodes);
});
}
});
});
}
}, [props.updateTemplate]);
useEffect(() => {
if (props.setFirstRender) {
props.setFirstRender(false);
editor.update(() => {
const parser = new DOMParser();
const dom = parser.parseFromString(props.getText(), "text/html");
const nodes = $generateNodesFromDOM(editor, dom);
$getRoot().select();
$insertNodes(nodes);
editor.registerUpdateListener(({ editorState, prevEditorState }) => {
editorState.read(() => {
const textInHtml = $generateHtmlFromNodes(editor).replace(/&lt;/g, "<").replace(/&gt;/g, ">");
props.setText(textInHtml);
});
if (!prevEditorState._selection) editor.blur();
});
});
}
}, []);
useEffect(() => {