Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Text editor for custom workflow templates #5654

Merged
merged 53 commits into from
Nov 25, 2022
Merged

Conversation

CarinaWolli
Copy link
Member

@CarinaWolli CarinaWolli commented Nov 23, 2022

What does this PR do?

Adds a text editor to create better custom email bodies.

Uses facebook/lexical instead of Draft.js (old PR) for text editor because Draft.js is not maintained anymore (facebookarchive/draft-js#3136 (comment))

Lexical Rich Text Example was used as a basis

Fixes #5599

Loom: https://www.loom.com/share/4648ba5faace4378acf940ef38994b7b

Environment: Staging(main branch)

Type of change

  • New feature (non-breaking change which adds functionality)

How should this be tested?

  • Create a new workflow with an email action
  • Test the custom email template

@vercel
Copy link

vercel bot commented Nov 23, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
cal ✅ Ready (Inspect) Visit Preview Nov 25, 2022 at 10:03AM (UTC)

@@ -143,7 +148,7 @@ function WorkflowPage() {
form.setValue("activeOn", activeOn || []);
setIsAllDataLoaded(true);
}
}, [workflow]);
}, [isLoading]);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixes issue that data was always reset after leaving tab

step.template === WorkflowTemplates.CUSTOM &&
!isSMSAction &&
convert(step.reminderBody).length <= 1;
if (isBodyEmpty) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For custom email bodies it needs to be checked if it is not empty. For all other input fields, the browser form validation is used

{isEmailSubjectNeeded ? t("email_body") : t("text_message")}
</Label>
</div>
<Editor form={form} stepNumber={step.stepNumber} />
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New editor is only used for email body

setIsPhoneNumberNeeded(val.value === WorkflowActions.SMS_NUMBER);

if (!wasSMSAction) {
form.setValue(`steps.${step.stepNumber - 1}.reminderBody`, "");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decided to remove input text if action is changed from SMS to Email or the other way around as SMS actions don't use the new editor

@@ -0,0 +1,430 @@

.editor a {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

css classes mainly come from here: https://codesandbox.io/s/lexical-rich-text-example-5tncvy?file=/src/styles.css but adapted them and removed everything that was not needed

editor.registerUpdateListener(({ editorState }) => {
editorState.read(() => {
const textInHtml = $generateHtmlFromNodes(editor);
props.form.setValue(`steps.${props.stepNumber - 1}.reminderBody`, textInHtml);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set reminderBody in html format when editor updates

}
}, [editor]);

const addVariable = (variable: string) => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function to add dynamic variables with editor.update

@CarinaWolli CarinaWolli marked this pull request as ready for review November 23, 2022 16:20
@CarinaWolli CarinaWolli requested review from a team and alannnc November 23, 2022 16:20
apps/web/package.json Outdated Show resolved Hide resolved
Copy link
Member

@zomars zomars left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Impressive work @CarinaWolli 🙏🏽

Just one minor detail. Can we do something about the "Add variable" button on mobile?

image

@CarinaWolli
Copy link
Member Author

Just one minor detail. Can we do something about the "Add variable" button on mobile?

Good catch @zomars! I changed the mobile view. That's how it looks now:
Screenshot 2022-11-24 at 11 15 47

Copy link
Member

@zomars zomars left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again @CarinaWolli LGTM!

Ship it

@zomars zomars merged commit 2de3e7f into main Nov 25, 2022
@zomars zomars deleted the feat/lexical-text-editor branch November 25, 2022 14:34
@PeerRich PeerRich added the core area: core, team members only label Jul 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core area: core, team members only
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CAL-405] Text editor for custom workflow templates
3 participants