Variables for custom templates in workflows (#3602)
* improve functionality to update a step * remove console logs * fix issue with active event types * allow null value for time and timeUnit * sort steps asc step number * add action to workflow (frontend) * add phone number input for SMS to specific number * use PhoneInput for number input + input validation * improve invalid input for phone number * improve UI of phoneInput * Improve design and validation * fix undefined error * set default action when adding action * include all team event types * fix phone number input for editing steps * fix update muation to add steps * remove console logs * fix order of steps * functionality to delete steps * add trigger when event is cancelled * add custom email body * sms and email reminder updates * add custom emails * add custom email subject * send reminder email to all attendees * update migration * fix default value for time and timeUnit * save email reminders to database * clean code * add custom template to SMS actions * schedule emails with sendgrid * clean code * add workflow templates * keep custom template saved when changing templates * create reminder template for email * add dot at the end of sentace for email template * fix merge error * fix issue that template was not saved * include sending emails for when event is cancelled * fix bug that email was always sent * add templates to sms reminders * add info that sending sms to attendees won't trigger for already exisitng bookings * only schedule sms for attendees when smsReminderNumber exists * only schedule sms for attendees when smsReminderNumber exists * set scheduled of workflow reminder to false when longer than 72 hours * add cron for email scheduling + fixes for for sms an email scheduling * adjust step number when deleting a step * cast to boolean with !! * update cron job for email reminders * update sms template * send reminder email not to guests * remove sendTo from workflow reminder * fixes sending sms without name + removing sendTo everywhere * fix undefined name in sms template * set user name to undefined for sending sms to a specific number * fix singular and plural for time unit * set to edit mode when changing action and custom template is selected * delete reminders when booking cancelled or not active anymore * fix type errors * fix error that deleted reminders twice * create booking reminders for existing bookings when eventType is set active * improve email and sms templates * use BookingInfo type instead of calendarEvent for reminder emails * schedule emails for already existing bookings * add and remove reminders for new active event types and cancelled events * connect add action button with last step * fix step container width for mobile view * helper functions that return options for select * fix typo and remove comment * clean code * add/improve error messages for forms * fix typo * clean code * improve email template * clean code * fix missing prop * save reference id when scheduling reminder * fix step not added because of changed id for new steps * small fixes + code cleanup * code cleanup * show error message when number is invalid * fix typo * fix phone number input when location is already phone * set multi select checkbox to read only * change email scheduling in cron job from 7 days to 72 hours * show active event types in workflow list * fix trigger information for workflow list * improve layout for small screens in workflow list * remove optional from zod type for workflow name * order workflows by id * use link icon to show active event types * fix plural and add translation for showing nr of active eventtypes * fix text for sms reminder template * add reminders for added steps * remove optional for activeOn * improve reminder templates * improve design of custom input fields * set edit mode to false when phone number isn't needed anymore * set sendTo in workflow step only for SMS_NUMBER action * set email body and subject only when custom template * only delete reminders that belong to workflow steps * improve text for new event book trigger * move reminders folder to workflows * fix issue that save button was sometimes enabled in edit mode * fix form issues for send to * delete all scheduled reminders when workflow is deleted * use enum for method * fix imports for workflow methods * add missing import * fix edit mode * create reminders when event is confirmed * add reminderScheduler to reduce duplicate code * make workflow enterprise and pro only feature * move all files to /ee/ folder * move package.json change to /ee/ folder * add pro badge to shell * set to edit mode to true if email subject is missing when action changes * fix loading bug * add migration * fix old imports * don't schedule reminders for opt-ins * fix style of email body * code clean up * Update yarn.lock * fix isLoading for active on dropdown * update import for prisma Co-authored-by: Omar López <zomars@me.com> * update imports * remove console * use session to check if user has valid license * use defaultHandler * clean up code * Create db-staging-snapshot.yml * move LisenceRequired inside shell * update import for FormValues * fix phone input design * fix disabled save button for edit mode * squah all migration into a single one * use isAfter and isBefore instead of isBetween * import dayjs from @calcom * validate phone number for sms reminders when booking event * Allows auto approvals for crowdin * add dropdown for adding dynamic variables to string * use lighter text colour for disabled button * change textarea for email subject to one row only * add function to create custom template with dynamic variables * add location to dynamic variables * add missing locations to custom template * add variables at cursor position * remove second curly brakets from variables * code cleanup * fix names for attendee and organizer * enable internationaliztion for custom reminders * disabled add workflow button when mutation is loading * fix translation keys * internationalize dates * code clean up * add translation for email subject * skip translation for english * remove language from BookingInfo type * add additional notes as variable * add custom inputs as variables * add information for custom inputs * add translation * Add formated variables in additional input information * fix type errors * code clean up * Update AddVariablesDropdown.tsx * Update variableTranslations.ts * Update variableTranslations.ts * Formatting * Update [workflow].tsx Co-authored-by: CarinaWolli <wollencarina@gmail.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> Co-authored-by: zomars <zomars@me.com>
This commit is contained in:
14 files changed
+505
-33
No files matched your search
@@ -945,5 +945,12 @@
|
||||
"new_seat_subject": "Neuer Teilnehmer {{name}} beim {{eventType}} am {{date}}",
|
||||
"new_seat_title": "Jemand hat sich zu einem Ereignis hinzugefügt",
|
||||
"app_upgrade_description": "Um diese Funktion nutzen zu können, müssen Sie ein Upgrade auf einen Pro-Account durchführen.",
|
||||
"invalid_number": "Ungültige Telefonnummer"
|
||||
"invalid_number": "Ungültige Telefonnummer",
|
||||
"event_name_workflow": "Event Name",
|
||||
"organizer_name_workflow": "Organisator Name",
|
||||
"attendee_name_workflow": "Teilnehmer Name",
|
||||
"event_date_workflow": "Event Datum",
|
||||
"event_time_workflow": "Event Zeit",
|
||||
"location_workflow": "Ort",
|
||||
"additional_notes_workflow": "Zusätzliche Notizen"
|
||||
}
|
||||
@@ -1000,6 +1000,14 @@
|
||||
"no_active_event_types": "No active event types",
|
||||
"new_seat_subject": "New Attendee {{name}} on {{eventType}} at {{date}}",
|
||||
"new_seat_title": "Someone has added themselves to an event",
|
||||
"variable": "Variable",
|
||||
"event_name_workflow": "Event name",
|
||||
"organizer_name_workflow": "Organizer name",
|
||||
"attendee_name_workflow": "Attendee name",
|
||||
"event_date_workflow": "Event date",
|
||||
"event_time_workflow": "Event time",
|
||||
"location_workflow": "Location",
|
||||
"additional_notes_workflow": "Additional notes",
|
||||
"app_upgrade_description": "In order to use this feature, you need to upgrade to a Pro account.",
|
||||
"invalid_number": "Invalid phone number",
|
||||
"navigate": "Navigate",
|
||||
@@ -1010,5 +1018,13 @@
|
||||
"embed": "Embed",
|
||||
"new_username": "New username",
|
||||
"current_username": "Current username",
|
||||
"example_1": "Example 1",
|
||||
"example_2": "Example 2",
|
||||
"additonal_input_label": "Additonal input label",
|
||||
"company_size": "Company size",
|
||||
"what_help_needed": "What do you need help with?",
|
||||
"variable_format": "Variable format",
|
||||
"custom_input_as_variable_info": "Ignore all special characters of the additonal input label (use only letters and numbers), use uppercase for all letters and replace whitespaces with underscores.",
|
||||
"using_additional_inputs_as_variables": "How to use additional inputs as variables?",
|
||||
"missing_connected_calendar": "No calendar connected"
|
||||
}
|
||||
@@ -20,6 +20,32 @@ dayjs.extend(timeZone);
|
||||
dayjs.extend(toArray);
|
||||
dayjs.extend(utc);
|
||||
|
||||
require('dayjs/locale/ar');
|
||||
require('dayjs/locale/bg');
|
||||
require('dayjs/locale/cs');
|
||||
require('dayjs/locale/de');
|
||||
require('dayjs/locale/es');
|
||||
require('dayjs/locale/es-mx');
|
||||
require('dayjs/locale/fr');
|
||||
require('dayjs/locale/he');
|
||||
require('dayjs/locale/hu');
|
||||
require('dayjs/locale/it');
|
||||
require('dayjs/locale/ja');
|
||||
require('dayjs/locale/ko');
|
||||
require('dayjs/locale/nl');
|
||||
require('dayjs/locale/pl');
|
||||
require('dayjs/locale/pt');
|
||||
require('dayjs/locale/pt-br');
|
||||
require('dayjs/locale/ro');
|
||||
require('dayjs/locale/ru');
|
||||
require('dayjs/locale/sr');
|
||||
require('dayjs/locale/sv');
|
||||
require('dayjs/locale/tr');
|
||||
require('dayjs/locale/uk');
|
||||
require('dayjs/locale/vi');
|
||||
require('dayjs/locale/zh-tw');
|
||||
require('dayjs/locale/zh-cn');
|
||||
|
||||
export type Dayjs = dayjs.Dayjs;
|
||||
|
||||
export type { ConfigType } from "dayjs";
|
||||
|
||||
@@ -8,6 +8,7 @@ import dayjs from "@calcom/dayjs";
|
||||
import { defaultHandler } from "@calcom/lib/server";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import customTemplate, { VariablesType } from "../lib/reminders/templates/customTemplate";
|
||||
import emailReminderTemplate from "../lib/reminders/templates/emailReminderTemplate";
|
||||
|
||||
const sendgridAPIKey = process.env.SENDGRID_API_KEY as string;
|
||||
@@ -103,6 +104,30 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
name || ""
|
||||
);
|
||||
break;
|
||||
case WorkflowTemplates.CUSTOM:
|
||||
const variables: VariablesType = {
|
||||
eventName: reminder.booking?.eventType?.title || "",
|
||||
organizerName: reminder.booking?.user?.name || "",
|
||||
attendeeName: reminder.booking?.attendees[0].name,
|
||||
eventDate: dayjs(reminder.booking?.startTime).tz(timeZone),
|
||||
eventTime: dayjs(reminder.booking?.startTime).tz(timeZone),
|
||||
timeZone: timeZone,
|
||||
location: reminder.booking?.location || "",
|
||||
additionalNotes: reminder.booking?.description,
|
||||
customInputs: reminder.booking?.customInputs,
|
||||
};
|
||||
const emailSubject = await customTemplate(
|
||||
reminder.workflowStep.emailSubject || "",
|
||||
variables,
|
||||
reminder.booking?.user?.locale || ""
|
||||
);
|
||||
emailContent.emailSubject = emailSubject.text;
|
||||
emailContent.emailBody = await customTemplate(
|
||||
reminder.workflowStep.reminderBody || "",
|
||||
variables,
|
||||
reminder.booking?.user?.locale || ""
|
||||
);
|
||||
break;
|
||||
}
|
||||
if (emailContent.emailSubject.length > 0 && emailContent.emailBody.text.length > 0 && sendTo) {
|
||||
const batchIdResponse = await client.request({
|
||||
|
||||
@@ -7,6 +7,7 @@ import { defaultHandler } from "@calcom/lib/server";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import * as twilio from "../lib/reminders/smsProviders/twilioProvider";
|
||||
import customTemplate, { VariablesType } from "../lib/reminders/templates/customTemplate";
|
||||
import smsReminderTemplate from "../lib/reminders/templates/smsReminderTemplate";
|
||||
|
||||
async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
@@ -82,6 +83,25 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
userName
|
||||
);
|
||||
break;
|
||||
case WorkflowTemplates.CUSTOM:
|
||||
const variables: VariablesType = {
|
||||
eventName: reminder.booking?.eventType?.title,
|
||||
organizerName: reminder.booking?.user?.name || "",
|
||||
attendeeName: reminder.booking?.attendees[0].name,
|
||||
eventDate: dayjs(reminder.booking?.startTime).tz(timeZone),
|
||||
eventTime: dayjs(reminder.booking?.startTime).tz(timeZone),
|
||||
timeZone: timeZone,
|
||||
location: reminder.booking?.location || "",
|
||||
additionalNotes: reminder.booking?.description,
|
||||
customInputs: reminder.booking?.customInputs,
|
||||
};
|
||||
const customMessage = await customTemplate(
|
||||
reminder.workflowStep.reminderBody || "",
|
||||
variables,
|
||||
reminder.booking?.user?.locale || ""
|
||||
);
|
||||
message = customMessage.text;
|
||||
break;
|
||||
}
|
||||
if (message?.length && message?.length > 0 && sendTo) {
|
||||
const scheduledSMS = await twilio.scheduleSMS(sendTo, message, reminder.scheduledDate);
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
import classNames from "@calcom/lib/classNames";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { Dropdown, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@calcom/ui/Dropdown";
|
||||
|
||||
interface IAddVariablesDropdown {
|
||||
addVariable: (isEmailSubject: boolean, variable: string) => void;
|
||||
disabled: boolean;
|
||||
isEmailSubject: boolean;
|
||||
}
|
||||
|
||||
const variables = [
|
||||
"event_name_workflow",
|
||||
"organizer_name_workflow",
|
||||
"attendee_name_workflow",
|
||||
"event_date_workflow",
|
||||
"event_time_workflow",
|
||||
"location_workflow",
|
||||
"additional_notes_workflow",
|
||||
];
|
||||
|
||||
export const AddVariablesDropdown = (props: IAddVariablesDropdown) => {
|
||||
const { t } = useLocale();
|
||||
|
||||
return (
|
||||
<Dropdown>
|
||||
<DropdownMenuTrigger
|
||||
disabled={props.disabled}
|
||||
className={classNames(
|
||||
"border-1 m-2 rounded-sm border border-gray-300 bg-gray-50 text-xs hover:border-gray-400 hover:bg-gray-100 focus:ring-0",
|
||||
props.disabled ? "text-gray-300" : "text-gray-600"
|
||||
)}>
|
||||
<span className="-m-1">+ {t("variable")}</span>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent className="h-40 overflow-scroll">
|
||||
{variables.map((variable) => (
|
||||
<DropdownMenuItem key={variable}>
|
||||
<button
|
||||
key={variable}
|
||||
type="button"
|
||||
className="px-5 py-1"
|
||||
onClick={() => props.addVariable(props.isEmailSubject, variable)}>
|
||||
{t(variable)}
|
||||
</button>
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
</DropdownMenuContent>
|
||||
</Dropdown>
|
||||
);
|
||||
};
|
||||
@@ -232,7 +232,9 @@ export function NewWorkflowButton() {
|
||||
)}
|
||||
</>
|
||||
<div className="mt-8 flex flex-row-reverse gap-x-2">
|
||||
<Button type="submit">{t("continue")}</Button>
|
||||
<Button type="submit" disabled={createMutation.isLoading}>
|
||||
{t("continue")}
|
||||
</Button>
|
||||
<DialogClose asChild>
|
||||
<Button
|
||||
color="secondary"
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
WorkflowTriggerEvents,
|
||||
} from "@prisma/client";
|
||||
import { isValidPhoneNumber } from "libphonenumber-js";
|
||||
import { Dispatch, SetStateAction, useState } from "react";
|
||||
import { Dispatch, SetStateAction, useRef, useState } from "react";
|
||||
import { Controller, UseFormReturn } from "react-hook-form";
|
||||
import PhoneInput from "react-phone-number-input";
|
||||
import "react-phone-number-input/style.css";
|
||||
@@ -17,14 +17,16 @@ import { Button } from "@calcom/ui";
|
||||
import Dropdown, { DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@calcom/ui/Dropdown";
|
||||
import { Icon } from "@calcom/ui/Icon";
|
||||
import Select from "@calcom/ui/form/Select";
|
||||
import { TextArea, TextField } from "@calcom/ui/form/fields";
|
||||
import { TextArea } from "@calcom/ui/form/fields";
|
||||
|
||||
import { AddVariablesDropdown } from "../components/AddVariablesDropdown";
|
||||
import {
|
||||
getWorkflowActionOptions,
|
||||
getWorkflowTemplateOptions,
|
||||
getWorkflowTimeUnitOptions,
|
||||
getWorkflowTriggerOptions,
|
||||
} from "../lib/getOptions";
|
||||
import { getTranslatedText, translateVariablesToEnglish } from "../lib/variableTranslations";
|
||||
import type { FormValues } from "../pages/workflow";
|
||||
|
||||
type WorkflowStepProps = {
|
||||
@@ -37,9 +39,8 @@ type WorkflowStepProps = {
|
||||
};
|
||||
|
||||
export default function WorkflowStepContainer(props: WorkflowStepProps) {
|
||||
const { t } = useLocale();
|
||||
const { t, i18n } = useLocale();
|
||||
const { step, form, reload, setReload, editCounter, setEditCounter } = props;
|
||||
|
||||
const [editNumberMode, setEditNumberMode] = useState(
|
||||
step?.action === WorkflowActions.SMS_NUMBER && !step?.sendTo ? true : false
|
||||
);
|
||||
@@ -47,7 +48,21 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
|
||||
const [sendTo, setSendTo] = useState(step?.sendTo || "");
|
||||
const [errorMessageNumber, setErrorMessageNumber] = useState("");
|
||||
const [errorMessageCustomInput, setErrorMessageCustomInput] = useState("");
|
||||
const [isInfoParagraphOpen, setIsInfoParagraphOpen] = useState(false);
|
||||
|
||||
const [translatedReminderBody, setTranslatedReminderBody] = useState(
|
||||
getTranslatedText((step ? form.getValues(`steps.${step.stepNumber - 1}.reminderBody`) : "") || "", {
|
||||
locale: i18n.language,
|
||||
t,
|
||||
})
|
||||
);
|
||||
|
||||
const [translatedSubject, setTranslatedSubject] = useState(
|
||||
getTranslatedText((step ? form.getValues(`steps.${step.stepNumber - 1}.emailSubject`) : "") || "", {
|
||||
locale: i18n.language,
|
||||
t,
|
||||
})
|
||||
);
|
||||
const [isPhoneNumberNeeded, setIsPhoneNumberNeeded] = useState(
|
||||
step?.action === WorkflowActions.SMS_NUMBER ? true : false
|
||||
);
|
||||
@@ -71,6 +86,34 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
|
||||
const timeUnitOptions = getWorkflowTimeUnitOptions(t);
|
||||
const templateOptions = getWorkflowTemplateOptions(t);
|
||||
|
||||
const { ref: emailSubjectFormRef } = form.register(`steps.${step ? step.stepNumber - 1 : 0}.emailSubject`);
|
||||
|
||||
const { ref: reminderBodyFormRef } = form.register(`steps.${step ? step.stepNumber - 1 : 0}.reminderBody`);
|
||||
|
||||
const refEmailSubject = useRef<HTMLTextAreaElement | null>(null);
|
||||
|
||||
const refReminderBody = useRef<HTMLTextAreaElement | null>(null);
|
||||
|
||||
const addVariable = (isEmailSubject: boolean, variable: string) => {
|
||||
if (step) {
|
||||
if (isEmailSubject) {
|
||||
const currentEmailSubject = refEmailSubject?.current?.value || "";
|
||||
const cursorPosition = refEmailSubject?.current?.selectionStart || currentEmailSubject.length;
|
||||
const subjectWithAddedVariable = `${currentEmailSubject.substring(0, cursorPosition)}{${variable
|
||||
.toUpperCase()
|
||||
.replace(" ", "_")}}${currentEmailSubject.substring(cursorPosition)}`;
|
||||
setTranslatedSubject(subjectWithAddedVariable);
|
||||
} else {
|
||||
const currentMessageBody = refReminderBody?.current?.value || "";
|
||||
const cursorPosition = refReminderBody?.current?.selectionStart || currentMessageBody.length;
|
||||
const messageWithAddedVariable = `${currentMessageBody.substring(0, cursorPosition)}{${variable
|
||||
.toUpperCase()
|
||||
.replace(" ", "_")}}${currentMessageBody.substring(cursorPosition)}`;
|
||||
setTranslatedReminderBody(messageWithAddedVariable);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//trigger
|
||||
if (!step) {
|
||||
const trigger = form.getValues("trigger");
|
||||
@@ -323,31 +366,102 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
|
||||
{isCustomReminderBodyNeeded && (
|
||||
<>
|
||||
{isEmailSubjectNeeded && (
|
||||
<div className="mt-5 mb-2">
|
||||
<TextField
|
||||
label={t("subject")}
|
||||
type="text"
|
||||
disabled={!editEmailBodyMode}
|
||||
className={classNames(
|
||||
"border-1 focus-within:border-brand block w-full rounded-sm border border-gray-300 px-2 font-sans text-sm ring-black focus-within:ring-1 dark:border-black dark:bg-black dark:text-white",
|
||||
!editEmailBodyMode ? "text-gray-500 dark:text-gray-500" : ""
|
||||
)}
|
||||
{...form.register(`steps.${step.stepNumber - 1}.emailSubject`)}
|
||||
/>
|
||||
<div className="mt-5 mb-2 ">
|
||||
<label className="block mt-3 mb-1 text-sm font-medium text-gray-700">
|
||||
{t("subject")}
|
||||
</label>
|
||||
<div className="bg-white border border-gray-300 rounded-sm mtext-sm border-1 focus-within:border-1 focus-within:border-black">
|
||||
<AddVariablesDropdown
|
||||
disabled={!editEmailBodyMode}
|
||||
addVariable={addVariable}
|
||||
isEmailSubject={true}
|
||||
/>
|
||||
<TextArea
|
||||
name="emailSubject"
|
||||
disabled={!editEmailBodyMode}
|
||||
ref={(e) => {
|
||||
emailSubjectFormRef(e);
|
||||
refEmailSubject.current = e;
|
||||
}}
|
||||
value={translatedSubject}
|
||||
onChange={(e) => {
|
||||
setTranslatedSubject(e.target.value);
|
||||
}}
|
||||
rows={1}
|
||||
className={classNames(
|
||||
"block w-full rounded-sm border-0 p-2 text-sm focus:border-0 focus:ring-0 dark:border-black dark:bg-black dark:text-white",
|
||||
!editEmailBodyMode ? "text-gray-500 dark:text-gray-500" : ""
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<label className="block mt-3 mb-1 text-sm font-medium text-gray-700 dark:text-white">
|
||||
{isEmailSubjectNeeded ? t("email_body") : t("text_message")}
|
||||
</label>
|
||||
<TextArea
|
||||
className={classNames(
|
||||
"border-1 focus-within:border-brand mb-2 block w-full rounded-sm border border-gray-300 p-2 text-sm ring-black focus-within:ring-1 dark:border-black dark:bg-black dark:text-white",
|
||||
!editEmailBodyMode ? "text-gray-500 dark:text-gray-500" : ""
|
||||
<div className="mb-2 text-sm bg-white border border-gray-300 rounded-sm border-1 focus-within:border-1 focus-within:border-black">
|
||||
<AddVariablesDropdown
|
||||
disabled={!editEmailBodyMode}
|
||||
addVariable={addVariable}
|
||||
isEmailSubject={false}
|
||||
/>
|
||||
<TextArea
|
||||
name="reminderBody"
|
||||
disabled={!editEmailBodyMode}
|
||||
ref={(e) => {
|
||||
reminderBodyFormRef(e);
|
||||
refReminderBody.current = e;
|
||||
}}
|
||||
value={translatedReminderBody}
|
||||
onChange={(e) => {
|
||||
setTranslatedReminderBody(e.target.value);
|
||||
}}
|
||||
rows={5}
|
||||
className={classNames(
|
||||
"block w-full rounded-sm border-0 p-2 text-sm focus:border-0 focus:ring-0 dark:border-black dark:bg-black dark:text-white",
|
||||
!editEmailBodyMode ? "text-gray-500 dark:text-gray-500" : ""
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
<div className="mt-3 mb-5 ">
|
||||
<button
|
||||
className="flex"
|
||||
type="button"
|
||||
onClick={() => setIsInfoParagraphOpen(!isInfoParagraphOpen)}>
|
||||
{isInfoParagraphOpen ? (
|
||||
<Icon.FiChevronDown className="h-5 text-gray-700 w5" />
|
||||
) : (
|
||||
<Icon.FiChevronRight className="h-5 text-gray-700 w5" />
|
||||
)}
|
||||
<span className="text-sm">{t("using_additional_inputs_as_variables")}</span>
|
||||
</button>
|
||||
{isInfoParagraphOpen && (
|
||||
<div className="w-full pr-6 mt-4 ml-6 text-sm">
|
||||
<div className="lg:flex">
|
||||
<div className="lg:w-1/2">
|
||||
<p className="font-medium">{t("example_1")}:</p>
|
||||
<p>{`${t("additonal_input_label")}: ${t("company_size")}`}</p>
|
||||
<p>{`${t("variable")}: {${t("company_size")
|
||||
.replace(/[^a-zA-Z0-9 ]/g, "")
|
||||
.trim()
|
||||
.replace(/ /g, "_")
|
||||
.toUpperCase()}}`}</p>
|
||||
</div>
|
||||
<div className="mt-3 lg:mt-0 lg:w-1/2">
|
||||
<p className="font-medium">{t("example_2")}:</p>
|
||||
<p>{`${t("additonal_input_label")}: ${t("what_help_needed")}`}</p>
|
||||
<p>{`${t("variable")}: {${t("what_help_needed")
|
||||
.replace(/[^a-zA-Z0-9 ]/g, "")
|
||||
.trim()
|
||||
.replace(/ /g, "_")
|
||||
.toUpperCase()}}`}</p>
|
||||
</div>
|
||||
</div>
|
||||
<p className="mt-4 font-medium">{t("variable_format")}:</p>
|
||||
<p>{t("custom_input_as_variable_info")}</p>
|
||||
</div>
|
||||
)}
|
||||
rows={5}
|
||||
disabled={!editEmailBodyMode}
|
||||
{...form.register(`steps.${step.stepNumber - 1}.reminderBody`)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{errorMessageCustomInput && (
|
||||
<p className="mb-3 text-sm text-red-500">{errorMessageCustomInput}</p>
|
||||
@@ -374,15 +488,22 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
|
||||
let errorMessage = "";
|
||||
|
||||
if (isEmailSubjectNeeded) {
|
||||
if (!reminderBody || !emailSubject) {
|
||||
if (!translatedReminderBody || !translatedSubject) {
|
||||
isEmpty = true;
|
||||
errorMessage = "Email body or subject is empty";
|
||||
}
|
||||
} else if (!reminderBody) {
|
||||
} else if (!translatedReminderBody) {
|
||||
isEmpty = true;
|
||||
errorMessage = "Text message is empty";
|
||||
}
|
||||
|
||||
form.setValue(
|
||||
`steps.${step.stepNumber - 1}.reminderBody`,
|
||||
translateVariablesToEnglish(translatedReminderBody, { locale: i18n.language, t })
|
||||
);
|
||||
form.setValue(
|
||||
`steps.${step.stepNumber - 1}.emailSubject`,
|
||||
translateVariablesToEnglish(translatedSubject, { locale: i18n.language, t })
|
||||
);
|
||||
if (!isEmpty) {
|
||||
setEditEmailBodyMode(false);
|
||||
setEditCounter(editCounter - 1);
|
||||
|
||||
@@ -12,6 +12,7 @@ import dayjs from "@calcom/dayjs";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { BookingInfo, timeUnitLowerCase } from "./smsReminderManager";
|
||||
import customTemplate, { VariablesType } from "./templates/customTemplate";
|
||||
import emailReminderTemplate from "./templates/emailReminderTemplate";
|
||||
|
||||
let sendgridAPIKey, senderEmail: string;
|
||||
@@ -72,6 +73,27 @@ export const scheduleEmailReminder = async (
|
||||
case WorkflowTemplates.REMINDER:
|
||||
emailContent = emailReminderTemplate(startTime, evt.title, timeZone, attendeeName, name);
|
||||
break;
|
||||
case WorkflowTemplates.CUSTOM:
|
||||
const variables: VariablesType = {
|
||||
eventName: evt.title || "",
|
||||
organizerName: evt.organizer.name,
|
||||
attendeeName: evt.attendees[0].name,
|
||||
eventDate: dayjs(startTime).tz(timeZone),
|
||||
eventTime: dayjs(startTime).tz(timeZone),
|
||||
timeZone: timeZone,
|
||||
location: evt.location,
|
||||
additionalNotes: evt.additionalNotes,
|
||||
customInputs: evt.customInputs,
|
||||
};
|
||||
|
||||
const emailSubjectTemplate = await customTemplate(
|
||||
emailSubject,
|
||||
variables,
|
||||
evt.organizer.language.locale
|
||||
);
|
||||
emailContent.emailSubject = emailSubjectTemplate.text;
|
||||
emailContent.emailBody = await customTemplate(emailBody, variables, evt.organizer.language.locale);
|
||||
break;
|
||||
}
|
||||
|
||||
if (
|
||||
|
||||
@@ -8,8 +8,10 @@ import {
|
||||
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Prisma } from "@calcom/prisma/client";
|
||||
|
||||
import * as twilio from "./smsProviders/twilioProvider";
|
||||
import customTemplate, { VariablesType } from "./templates/customTemplate";
|
||||
import smsReminderTemplate from "./templates/smsReminderTemplate";
|
||||
|
||||
export enum timeUnitLowerCase {
|
||||
@@ -21,9 +23,17 @@ export enum timeUnitLowerCase {
|
||||
export type BookingInfo = {
|
||||
uid?: string | null;
|
||||
attendees: { name: string; email: string; timeZone: string }[];
|
||||
organizer: { name: string; email: string; timeZone: string };
|
||||
organizer: {
|
||||
language: { locale: string };
|
||||
name: string;
|
||||
email: string;
|
||||
timeZone: string;
|
||||
};
|
||||
startTime: string;
|
||||
title: string;
|
||||
location?: string | null;
|
||||
additionalNotes?: string | null;
|
||||
customInputs?: Prisma.JsonValue;
|
||||
};
|
||||
|
||||
export const scheduleSMSReminder = async (
|
||||
@@ -56,6 +66,21 @@ export const scheduleSMSReminder = async (
|
||||
case WorkflowTemplates.REMINDER:
|
||||
message = smsReminderTemplate(evt.startTime, evt.title, timeZone, attendeeName, name) || message;
|
||||
break;
|
||||
case WorkflowTemplates.CUSTOM:
|
||||
const variables: VariablesType = {
|
||||
eventName: evt.title,
|
||||
organizerName: evt.organizer.name,
|
||||
attendeeName: evt.attendees[0].name,
|
||||
eventDate: dayjs(evt.startTime).tz(timeZone),
|
||||
eventTime: dayjs(evt.startTime).tz(timeZone),
|
||||
timeZone: timeZone,
|
||||
location: evt.location,
|
||||
additionalNotes: evt.additionalNotes,
|
||||
customInputs: evt.customInputs,
|
||||
};
|
||||
const customMessage = await customTemplate(message, variables, evt.organizer.language.locale);
|
||||
message = customMessage.text;
|
||||
break;
|
||||
}
|
||||
|
||||
if (message.length > 0 && reminderPhone) {
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
import { Dayjs } from "@calcom/dayjs";
|
||||
import { Prisma } from "@calcom/prisma/client";
|
||||
|
||||
export type VariablesType = {
|
||||
eventName?: string;
|
||||
organizerName?: string;
|
||||
attendeeName?: string;
|
||||
eventDate?: Dayjs;
|
||||
eventTime?: Dayjs;
|
||||
timeZone?: string;
|
||||
location?: string | null;
|
||||
additionalNotes?: string | null;
|
||||
customInputs?: Prisma.JsonValue;
|
||||
};
|
||||
|
||||
const customTemplate = async (text: string, variables: VariablesType, locale: string) => {
|
||||
const timeWithTimeZone = `${variables.eventTime?.locale(locale).format("HH:mm")} (${variables.timeZone})`;
|
||||
let locationString = variables.location || "";
|
||||
|
||||
if (text.includes("{LOCATION}")) {
|
||||
switch (variables.location) {
|
||||
case "integrations:google:meet":
|
||||
locationString = "Google Meet";
|
||||
break;
|
||||
case "integrations:daily":
|
||||
locationString = "Cal Video";
|
||||
break;
|
||||
case "integrations:zoom":
|
||||
locationString = "Zoom";
|
||||
break;
|
||||
case "integrations:huddle01":
|
||||
locationString = "Huddle01";
|
||||
break;
|
||||
case "integrations:tandem":
|
||||
locationString = "Tandem";
|
||||
break;
|
||||
case "integrations:office365_video":
|
||||
locationString = "MS Teams";
|
||||
break;
|
||||
case "integrations:jitsi":
|
||||
locationString = "Jitsi";
|
||||
break;
|
||||
case "integrations:whereby_video":
|
||||
locationString = "Whereby";
|
||||
break;
|
||||
case "integrations:around_video":
|
||||
locationString = "Around";
|
||||
break;
|
||||
case "integrations:riverside_video":
|
||||
locationString = "Riverside";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
let dynamicText = text
|
||||
.replaceAll("{EVENT_NAME}", variables.eventName || "")
|
||||
.replaceAll("{ORGANIZER_NAME}", variables.organizerName || "")
|
||||
.replaceAll("{ATTENDEE_NAME}", variables.attendeeName || "")
|
||||
.replaceAll("{EVENT_DATE}", variables.eventDate?.locale(locale).format("dddd, MMMM D, YYYY") || "")
|
||||
.replaceAll("{EVENT_TIME}", timeWithTimeZone)
|
||||
.replaceAll("{LOCATION}", locationString)
|
||||
.replaceAll("{ADDITIONAL_NOTES}", variables.additionalNotes || "");
|
||||
|
||||
const customInputvariables = dynamicText.match(/\{(.+?)}/g)?.map((variable) => {
|
||||
return variable.replace("{", "").replace("}", "");
|
||||
});
|
||||
|
||||
customInputvariables?.forEach((variable) => {
|
||||
if (variables.customInputs) {
|
||||
Object.keys(variables.customInputs).forEach((customInput) => {
|
||||
const formatedToVariable = customInput
|
||||
.replace(/[^a-zA-Z0-9 ]/g, "")
|
||||
.trim()
|
||||
.replaceAll(" ", "_")
|
||||
.toUpperCase();
|
||||
if (variable === formatedToVariable && variables.customInputs) {
|
||||
dynamicText = dynamicText.replace(
|
||||
`{${variable}}`,
|
||||
variables.customInputs[customInput as keyof typeof variables.customInputs]
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
dynamicText = dynamicText.replace(`{${variable}}`, "");
|
||||
});
|
||||
|
||||
const textHtml = `<body style="white-space: pre-wrap;">${dynamicText}</body>`;
|
||||
return { text: dynamicText, html: textHtml };
|
||||
};
|
||||
|
||||
export default customTemplate;
|
||||
@@ -0,0 +1,57 @@
|
||||
import { TFunction } from "next-i18next";
|
||||
|
||||
const originalVariables = [
|
||||
"event_name_workflow",
|
||||
"organizer_name_workflow",
|
||||
"attendee_name_workflow",
|
||||
"event_date_workflow",
|
||||
"event_time_workflow",
|
||||
"location_workflow",
|
||||
"additional_notes_workflow",
|
||||
];
|
||||
|
||||
export function getTranslatedText(text: string, language: { locale: string; t: TFunction }) {
|
||||
let translatedText = text;
|
||||
|
||||
if (language.locale !== "en") {
|
||||
const variables = text.match(/\{(.+?)}/g)?.map((variable) => {
|
||||
return variable.replace("{", "").replace("}", "");
|
||||
});
|
||||
|
||||
variables?.forEach((variable) => {
|
||||
const regex = new RegExp(variable, "g"); // .replaceAll is not available here for some reason
|
||||
translatedText = translatedText.replace(
|
||||
regex,
|
||||
originalVariables.includes(variable.toLowerCase().concat("_workflow"))
|
||||
? language.t(variable.toLowerCase().concat("_workflow")).replace(/ /g, "_").toLocaleUpperCase()
|
||||
: variable
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
return translatedText;
|
||||
}
|
||||
|
||||
export function translateVariablesToEnglish(text: string, language: { locale: string; t: TFunction }) {
|
||||
let newText = text;
|
||||
|
||||
if (language.locale !== "en") {
|
||||
const variables = text.match(/\{(.+?)}/g)?.map((variable) => {
|
||||
return variable.replace("{", "").replace("}", "");
|
||||
});
|
||||
|
||||
variables?.forEach((variable) => {
|
||||
originalVariables.forEach((originalVariable) => {
|
||||
if (language.t(originalVariable).replace(/ /, "_").toUpperCase() === variable) {
|
||||
newText = newText.replace(
|
||||
variable,
|
||||
language.t(originalVariable, { lng: "en" }).replace(" ", "_").toUpperCase()
|
||||
);
|
||||
return;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return newText;
|
||||
}
|
||||
@@ -341,13 +341,15 @@ export const workflowsRouter = createProtectedRouter()
|
||||
}),
|
||||
organizer: booking.user
|
||||
? {
|
||||
language: { locale: booking.user.locale || "" },
|
||||
name: booking.user.name || "",
|
||||
email: booking.user.email,
|
||||
timeZone: booking.user.timeZone,
|
||||
}
|
||||
: { name: "", email: "", timeZone: "" },
|
||||
: { name: "", email: "", timeZone: "", language: { locale: "" } },
|
||||
startTime: booking.startTime.toISOString(),
|
||||
title: booking.title,
|
||||
language: { locale: booking?.user?.locale || "" },
|
||||
};
|
||||
if (
|
||||
step.action === WorkflowActions.EMAIL_HOST ||
|
||||
@@ -496,13 +498,15 @@ export const workflowsRouter = createProtectedRouter()
|
||||
}),
|
||||
organizer: booking.user
|
||||
? {
|
||||
language: { locale: booking.user.locale || "" },
|
||||
name: booking.user.name || "",
|
||||
email: booking.user.email,
|
||||
timeZone: booking.user.timeZone,
|
||||
}
|
||||
: { name: "", email: "", timeZone: "" },
|
||||
: { name: "", email: "", timeZone: "", language: { locale: "" } },
|
||||
startTime: booking.startTime.toISOString(),
|
||||
title: booking.title,
|
||||
language: { locale: booking?.user?.locale || "" },
|
||||
};
|
||||
if (
|
||||
newStep.action === WorkflowActions.EMAIL_HOST ||
|
||||
@@ -596,10 +600,12 @@ export const workflowsRouter = createProtectedRouter()
|
||||
name: booking.user.name || "",
|
||||
email: booking.user.email,
|
||||
timeZone: booking.user.timeZone,
|
||||
language: { locale: booking.user.locale || "" },
|
||||
}
|
||||
: { name: "", email: "", timeZone: "" },
|
||||
: { name: "", email: "", timeZone: "", language: { locale: "" } },
|
||||
startTime: booking.startTime.toISOString(),
|
||||
title: booking.title,
|
||||
language: { locale: booking?.user?.locale || "" },
|
||||
};
|
||||
|
||||
if (
|
||||
|
||||
@@ -2,6 +2,8 @@ import { CheckCircleIcon } from "@heroicons/react/outline";
|
||||
import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu";
|
||||
import { ComponentProps, forwardRef } from "react";
|
||||
|
||||
import classNames from "@calcom/lib/classNames";
|
||||
|
||||
export const Dropdown = DropdownMenuPrimitive.Root;
|
||||
|
||||
type DropdownMenuTriggerProps = ComponentProps<typeof DropdownMenuPrimitive["Trigger"]>;
|
||||
@@ -29,7 +31,10 @@ export const DropdownMenuContent = forwardRef<HTMLDivElement, DropdownMenuConten
|
||||
<DropdownMenuPrimitive.Content
|
||||
portalled={props.portalled}
|
||||
{...props}
|
||||
className="slideInTop w-50 relative z-10 mt-1 -ml-0 origin-top-right rounded-sm bg-white text-sm shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none"
|
||||
className={classNames(
|
||||
`slideInTop w-50 relative z-10 mt-1 -ml-0 origin-top-right rounded-sm bg-white text-sm shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none`,
|
||||
props.className
|
||||
)}
|
||||
ref={forwardedRef}>
|
||||
{children}
|
||||
</DropdownMenuPrimitive.Content>
|
||||
|
||||
Reference in new issue
Block a user