Feedback of reusable wysiwyg editor (#6357)

* make text editor reusable

* use dropdown component for block type

* remove ring when clicking on block type

* allow excluding items in toolbar

* refactor code

* make AddVariableDropdown reusable

* fixed missed translations

* fixes variable translation issue

* change missed translation variables

* make AddVariablesDropdown reusable

* reorder block types in dropdown

* remove not needed prop

* code clean up

* center add variable dropwdown icon

* remove rounded borders in dropwdown on hover and active

* center icons

* fix tool bar items dropdown

* add constant for dynamic text variables

* remove not needed variables (added from merge)

Co-authored-by: CarinaWolli <[email protected]>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: Peer Richelsen <[email protected]>
Co-authored-by: alannnc <[email protected]>
This commit is contained in:
authored and GitHub committed 2023-01-09 19:22:17 -07:00
1 parent 62713940b0
commit 430430e0cd
6 files changed
+30 -38

No files matched your search

@@ -38,6 +38,7 @@ import {
AddVariablesDropdown,
} from "@calcom/ui";
import { DYNAMIC_TEXT_VARIABLES } from "../lib/constants";
import { getWorkflowTemplateOptions, getWorkflowTriggerOptions } from "../lib/getOptions";
import { translateVariablesToEnglish } from "../lib/variableTranslations";
import type { FormValues } from "../pages/workflow";
@@ -50,18 +51,6 @@ type WorkflowStepProps = {
setReload?: Dispatch<SetStateAction<boolean>>;
};
const dynamicTextVariables = [
"event_name",
"event_date",
"event_time",
"location",
"organizer_name",
"attendee_name",
"attendee_email",
"additional_notes",
"meeting_url",
];
export default function WorkflowStepContainer(props: WorkflowStepProps) {
const { t, i18n } = useLocale();
const utils = trpc.useContext();
@@ -557,7 +546,7 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
<div className="flex-grow text-right">
<AddVariablesDropdown
addVariable={addVariableEmailSubject}
variables={dynamicTextVariables}
variables={DYNAMIC_TEXT_VARIABLES}
/>
</div>
</div>
@@ -596,7 +585,7 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
props.form.setValue(`steps.${step.stepNumber - 1}.reminderBody`, text);
props.form.clearErrors();
}}
variables={dynamicTextVariables}
variables={DYNAMIC_TEXT_VARIABLES}
/>
</>
) : (
@@ -608,7 +597,7 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
<div className="flex-grow text-right">
<AddVariablesDropdown
addVariable={addVariableBody}
variables={dynamicTextVariables}
variables={DYNAMIC_TEXT_VARIABLES}
/>
</div>
</div>
@@ -19,3 +19,15 @@ export const WORKFLOW_ACTIONS = [
export const TIME_UNIT = [TimeUnit.DAY, TimeUnit.HOUR, TimeUnit.MINUTE] as const;
export const WORKFLOW_TEMPLATES = [WorkflowTemplates.CUSTOM, WorkflowTemplates.REMINDER] as const;
export const DYNAMIC_TEXT_VARIABLES = [
"event_name",
"event_date",
"event_time",
"location",
"organizer_name",
"attendee_name",
"attendee_email",
"additional_notes",
"meeting_url",
];
@@ -1,16 +1,6 @@
import { TFunction } from "next-i18next";
const originalVariables = [
"event_name_variable",
"organizer_name_variable",
"attendee_name_variable",
"event_date_variable",
"event_time_variable",
"location_variable",
"additional_notes_variable",
"attendee_email_variable",
"meeting_url_variable",
];
import { DYNAMIC_TEXT_VARIABLES } from "./constants";
export function getTranslatedText(text: string, language: { locale: string; t: TFunction }) {
let translatedText = text;
@@ -22,9 +12,9 @@ export function getTranslatedText(text: string, language: { locale: string; t: T
variables?.forEach((variable) => {
const regex = new RegExp(`{${variable}}`, "g"); // .replaceAll is not available here for some reason
const translatedVariable = originalVariables.includes(variable.toLowerCase().concat("_variable"))
const translatedVariable = DYNAMIC_TEXT_VARIABLES.includes(variable.toLowerCase())
? language.t(variable.toLowerCase().concat("_variable")).replace(/ /g, "_").toLocaleUpperCase()
: originalVariables.includes(variable.toLowerCase().concat("_name_variable")) //for the old variables names (ORGANIZER_NAME, ATTENDEE_NAME)
: DYNAMIC_TEXT_VARIABLES.includes(variable.toLowerCase().concat("_name")) //for the old variables names (ORGANIZER_NAME, ATTENDEE_NAME)
? language.t(variable.toLowerCase().concat("_name_variable")).replace(/ /g, "_").toLocaleUpperCase()
: variable;
@@ -44,8 +34,9 @@ export function translateVariablesToEnglish(text: string, language: { locale: st
});
variables?.forEach((variable) => {
originalVariables.forEach((originalVariable) => {
DYNAMIC_TEXT_VARIABLES.forEach((originalVar) => {
const newVariableName = variable.replace("_NAME", "");
const originalVariable = `${originalVar}_variable`;
if (
language.t(originalVariable).replace(/ /g, "_").toUpperCase() === variable ||
language.t(originalVariable).replace(/ /g, "_").toUpperCase() === newVariableName