2022-07-14 00:10:45 +00:00
|
|
|
import {
|
|
|
|
TimeUnit,
|
|
|
|
WorkflowActions,
|
2022-07-28 19:58:26 +00:00
|
|
|
WorkflowStep,
|
2022-07-14 00:10:45 +00:00
|
|
|
WorkflowTemplates,
|
2022-07-28 19:58:26 +00:00
|
|
|
WorkflowTriggerEvents,
|
2022-07-14 00:10:45 +00:00
|
|
|
} from "@prisma/client";
|
2022-08-03 22:22:38 +00:00
|
|
|
import { Dispatch, SetStateAction, useRef, useState } from "react";
|
2022-07-14 00:10:45 +00:00
|
|
|
import { Controller, UseFormReturn } from "react-hook-form";
|
2022-07-30 15:49:01 +00:00
|
|
|
import "react-phone-number-input/style.css";
|
2022-07-14 00:10:45 +00:00
|
|
|
|
2022-12-12 11:00:15 +00:00
|
|
|
import { SENDER_ID } from "@calcom/lib/constants";
|
2022-07-20 19:48:40 +00:00
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
2022-08-26 01:04:44 +00:00
|
|
|
import { HttpError } from "@calcom/lib/http-error";
|
2022-12-13 21:34:21 +00:00
|
|
|
import { trpc, TRPCClientError } from "@calcom/trpc/react";
|
2022-11-23 02:55:25 +00:00
|
|
|
import {
|
|
|
|
Button,
|
|
|
|
Checkbox,
|
|
|
|
ConfirmationDialogContent,
|
|
|
|
Dialog,
|
|
|
|
DialogClose,
|
|
|
|
DialogContent,
|
|
|
|
Dropdown,
|
|
|
|
DropdownMenuContent,
|
|
|
|
DropdownMenuItem,
|
|
|
|
DropdownMenuTrigger,
|
|
|
|
EmailField,
|
|
|
|
Icon,
|
|
|
|
Label,
|
|
|
|
PhoneInput,
|
|
|
|
Select,
|
|
|
|
showToast,
|
|
|
|
TextArea,
|
|
|
|
TextField,
|
|
|
|
} from "@calcom/ui";
|
2022-07-28 19:58:26 +00:00
|
|
|
|
2022-08-03 22:22:38 +00:00
|
|
|
import { AddVariablesDropdown } from "../components/AddVariablesDropdown";
|
2022-07-14 00:10:45 +00:00
|
|
|
import {
|
|
|
|
getWorkflowActionOptions,
|
|
|
|
getWorkflowTemplateOptions,
|
|
|
|
getWorkflowTriggerOptions,
|
2022-07-28 19:58:26 +00:00
|
|
|
} from "../lib/getOptions";
|
2022-11-23 02:55:25 +00:00
|
|
|
import { translateVariablesToEnglish } from "../lib/variableTranslations";
|
2022-07-28 19:58:26 +00:00
|
|
|
import type { FormValues } from "../pages/workflow";
|
2022-11-25 14:34:55 +00:00
|
|
|
import Editor from "./TextEditor/Editor";
|
2022-11-23 02:55:25 +00:00
|
|
|
import { TimeTimeUnitInput } from "./TimeTimeUnitInput";
|
2022-07-14 00:10:45 +00:00
|
|
|
|
|
|
|
type WorkflowStepProps = {
|
|
|
|
step?: WorkflowStep;
|
2022-07-20 19:48:40 +00:00
|
|
|
form: UseFormReturn<FormValues>;
|
2022-07-14 00:10:45 +00:00
|
|
|
reload?: boolean;
|
|
|
|
setReload?: Dispatch<SetStateAction<boolean>>;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default function WorkflowStepContainer(props: WorkflowStepProps) {
|
2022-08-03 22:22:38 +00:00
|
|
|
const { t, i18n } = useLocale();
|
2022-11-23 22:42:42 +00:00
|
|
|
const { step, form, reload, setReload } = props;
|
2022-11-23 02:55:25 +00:00
|
|
|
const [isAdditionalInputsDialogOpen, setIsAdditionalInputsDialogOpen] = useState(false);
|
2022-08-26 01:04:44 +00:00
|
|
|
const [confirmationDialogOpen, setConfirmationDialogOpen] = useState(false);
|
2022-08-03 22:22:38 +00:00
|
|
|
|
2022-11-23 02:55:25 +00:00
|
|
|
const [isPhoneNumberNeeded, setIsPhoneNumberNeeded] = useState(
|
|
|
|
step?.action === WorkflowActions.SMS_NUMBER ? true : false
|
2022-08-03 22:22:38 +00:00
|
|
|
);
|
2022-07-14 00:10:45 +00:00
|
|
|
|
2022-11-23 02:55:25 +00:00
|
|
|
const [isSenderIdNeeded, setIsSenderIdNeeded] = useState(
|
|
|
|
step?.action === WorkflowActions.SMS_NUMBER || step?.action === WorkflowActions.SMS_ATTENDEE
|
|
|
|
? true
|
|
|
|
: false
|
2022-08-03 22:22:38 +00:00
|
|
|
);
|
2022-11-23 02:55:25 +00:00
|
|
|
|
|
|
|
const [isEmailAddressNeeded, setIsEmailAddressNeeded] = useState(
|
|
|
|
step?.action === WorkflowActions.EMAIL_ADDRESS ? true : false
|
2022-07-14 00:10:45 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
const [isCustomReminderBodyNeeded, setIsCustomReminderBodyNeeded] = useState(
|
|
|
|
step?.template === WorkflowTemplates.CUSTOM ? true : false
|
|
|
|
);
|
|
|
|
|
|
|
|
const [isEmailSubjectNeeded, setIsEmailSubjectNeeded] = useState(
|
2022-11-23 02:55:25 +00:00
|
|
|
step?.action === WorkflowActions.EMAIL_ATTENDEE ||
|
|
|
|
step?.action === WorkflowActions.EMAIL_HOST ||
|
|
|
|
step?.action === WorkflowActions.EMAIL_ADDRESS
|
2022-07-14 00:10:45 +00:00
|
|
|
? true
|
|
|
|
: false
|
|
|
|
);
|
|
|
|
|
|
|
|
const [showTimeSection, setShowTimeSection] = useState(
|
2022-11-23 02:55:25 +00:00
|
|
|
form.getValues("trigger") === WorkflowTriggerEvents.BEFORE_EVENT ||
|
|
|
|
form.getValues("trigger") === WorkflowTriggerEvents.AFTER_EVENT
|
|
|
|
);
|
|
|
|
|
|
|
|
const [showTimeSectionAfter, setShowTimeSectionAfter] = useState(
|
|
|
|
form.getValues("trigger") === WorkflowTriggerEvents.AFTER_EVENT
|
2022-07-14 00:10:45 +00:00
|
|
|
);
|
2022-12-15 00:11:57 +00:00
|
|
|
const { data: actionOptions } = trpc.viewer.workflows.getWorkflowActionOptions.useQuery();
|
2022-07-14 00:10:45 +00:00
|
|
|
const triggerOptions = getWorkflowTriggerOptions(t);
|
|
|
|
const templateOptions = getWorkflowTemplateOptions(t);
|
|
|
|
|
2022-11-23 02:55:25 +00:00
|
|
|
const { ref: emailSubjectFormRef, ...restEmailSubjectForm } = step
|
|
|
|
? form.register(`steps.${step.stepNumber - 1}.emailSubject`)
|
|
|
|
: { ref: null, name: "" };
|
2022-08-03 22:22:38 +00:00
|
|
|
|
2022-11-23 02:55:25 +00:00
|
|
|
const { ref: reminderBodyFormRef, ...restReminderBodyForm } = step
|
|
|
|
? form.register(`steps.${step.stepNumber - 1}.reminderBody`)
|
|
|
|
: { ref: null, name: "" };
|
2022-08-03 22:22:38 +00:00
|
|
|
|
|
|
|
const refEmailSubject = useRef<HTMLTextAreaElement | null>(null);
|
|
|
|
|
|
|
|
const refReminderBody = useRef<HTMLTextAreaElement | null>(null);
|
|
|
|
|
2022-11-25 14:34:55 +00:00
|
|
|
const addVariable = (variable: string, isEmailSubject?: boolean) => {
|
2022-08-03 22:22:38 +00:00
|
|
|
if (step) {
|
|
|
|
if (isEmailSubject) {
|
|
|
|
const currentEmailSubject = refEmailSubject?.current?.value || "";
|
|
|
|
const cursorPosition = refEmailSubject?.current?.selectionStart || currentEmailSubject.length;
|
|
|
|
const subjectWithAddedVariable = `${currentEmailSubject.substring(0, cursorPosition)}{${variable
|
|
|
|
.toUpperCase()
|
2022-11-23 02:55:25 +00:00
|
|
|
.replace(/ /g, "_")}}${currentEmailSubject.substring(cursorPosition)}`;
|
|
|
|
form.setValue(`steps.${step.stepNumber - 1}.emailSubject`, subjectWithAddedVariable);
|
2022-08-03 22:22:38 +00:00
|
|
|
} else {
|
|
|
|
const currentMessageBody = refReminderBody?.current?.value || "";
|
|
|
|
const cursorPosition = refReminderBody?.current?.selectionStart || currentMessageBody.length;
|
|
|
|
const messageWithAddedVariable = `${currentMessageBody.substring(0, cursorPosition)}{${variable
|
|
|
|
.toUpperCase()
|
2022-11-23 02:55:25 +00:00
|
|
|
.replace(/ /g, "_")}}${currentMessageBody.substring(cursorPosition)}`;
|
|
|
|
form.setValue(`steps.${step.stepNumber - 1}.reminderBody`, messageWithAddedVariable);
|
2022-08-03 22:22:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-11-10 23:40:01 +00:00
|
|
|
const testActionMutation = trpc.viewer.workflows.testAction.useMutation({
|
2022-08-26 01:04:44 +00:00
|
|
|
onSuccess: async () => {
|
|
|
|
showToast(t("notification_sent"), "success");
|
|
|
|
},
|
|
|
|
onError: (err) => {
|
2022-12-13 21:34:21 +00:00
|
|
|
let message = t("unexpected_error_try_again");
|
|
|
|
if (err instanceof TRPCClientError) {
|
|
|
|
if (err.message === "rate-limit-exceeded") {
|
|
|
|
message = t("rate_limit_exceeded");
|
|
|
|
}
|
|
|
|
}
|
2022-08-26 01:04:44 +00:00
|
|
|
if (err instanceof HttpError) {
|
2022-12-13 21:34:21 +00:00
|
|
|
message = `${err.statusCode}: ${err.message}`;
|
2022-08-26 01:04:44 +00:00
|
|
|
}
|
2022-12-13 21:34:21 +00:00
|
|
|
showToast(message, "error");
|
2022-08-26 01:04:44 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2022-07-14 00:10:45 +00:00
|
|
|
//trigger
|
|
|
|
if (!step) {
|
|
|
|
const trigger = form.getValues("trigger");
|
2022-11-23 02:55:25 +00:00
|
|
|
const triggerString = t(`${trigger.toLowerCase()}_trigger`);
|
2022-07-14 00:10:45 +00:00
|
|
|
|
2022-11-23 02:55:25 +00:00
|
|
|
const selectedTrigger = {
|
|
|
|
label: triggerString.charAt(0).toUpperCase() + triggerString.slice(1),
|
|
|
|
value: trigger,
|
|
|
|
};
|
2022-07-14 00:10:45 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div className="flex justify-center">
|
2022-11-23 02:55:25 +00:00
|
|
|
<div className="min-w-80 w-full rounded-md border border-gray-200 bg-white p-7">
|
|
|
|
<div className="flex">
|
|
|
|
<div className="mt-[3px] mr-5 flex h-5 w-5 items-center justify-center rounded-full bg-gray-100 p-1 text-xs font-medium">
|
|
|
|
1
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<div className="text-base font-bold">{t("trigger")}</div>
|
|
|
|
<div className="text-sm text-gray-600">{t("when_something_happens")}</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-08-26 01:04:44 +00:00
|
|
|
<div className="my-7 border-t border-gray-200" />
|
2022-11-23 02:55:25 +00:00
|
|
|
<Label>{t("when")}</Label>
|
2022-07-14 00:10:45 +00:00
|
|
|
<Controller
|
|
|
|
name="trigger"
|
|
|
|
control={form.control}
|
|
|
|
render={() => {
|
|
|
|
return (
|
|
|
|
<Select
|
|
|
|
isSearchable={false}
|
2022-11-23 02:55:25 +00:00
|
|
|
className="text-sm"
|
2022-07-14 00:10:45 +00:00
|
|
|
onChange={(val) => {
|
|
|
|
if (val) {
|
|
|
|
form.setValue("trigger", val.value);
|
2022-11-23 02:55:25 +00:00
|
|
|
if (
|
|
|
|
val.value === WorkflowTriggerEvents.BEFORE_EVENT ||
|
|
|
|
val.value === WorkflowTriggerEvents.AFTER_EVENT
|
|
|
|
) {
|
2022-07-14 00:10:45 +00:00
|
|
|
setShowTimeSection(true);
|
2022-11-23 02:55:25 +00:00
|
|
|
if (val.value === WorkflowTriggerEvents.AFTER_EVENT) {
|
|
|
|
setShowTimeSectionAfter(true);
|
|
|
|
} else {
|
|
|
|
setShowTimeSectionAfter(false);
|
|
|
|
}
|
2022-07-14 00:10:45 +00:00
|
|
|
form.setValue("time", 24);
|
|
|
|
form.setValue("timeUnit", TimeUnit.HOUR);
|
|
|
|
} else {
|
|
|
|
setShowTimeSection(false);
|
2022-11-23 02:55:25 +00:00
|
|
|
setShowTimeSectionAfter(false);
|
2022-07-14 00:10:45 +00:00
|
|
|
form.unregister("time");
|
|
|
|
form.unregister("timeUnit");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
defaultValue={selectedTrigger}
|
|
|
|
options={triggerOptions}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
{showTimeSection && (
|
2022-11-23 02:55:25 +00:00
|
|
|
<div className="mt-5">
|
|
|
|
<Label>{showTimeSectionAfter ? t("how_long_after") : t("how_long_before")}</Label>
|
|
|
|
<TimeTimeUnitInput form={form} />
|
2022-07-14 00:10:45 +00:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (step && step.action) {
|
2022-11-23 02:55:25 +00:00
|
|
|
const actionString = t(`${step.action.toLowerCase()}_action`);
|
|
|
|
|
|
|
|
const selectedAction = {
|
|
|
|
label: actionString.charAt(0).toUpperCase() + actionString.slice(1),
|
|
|
|
value: step.action,
|
2022-12-15 00:11:57 +00:00
|
|
|
disabled: false,
|
2022-11-23 02:55:25 +00:00
|
|
|
};
|
|
|
|
|
2022-07-14 00:10:45 +00:00
|
|
|
const selectedTemplate = { label: t(`${step.template.toLowerCase()}`), value: step.template };
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2022-11-23 02:55:25 +00:00
|
|
|
<div className="my-3 flex justify-center">
|
|
|
|
<Icon.FiArrowDown className="stroke-[1.5px] text-3xl text-gray-500" />
|
2022-07-14 00:10:45 +00:00
|
|
|
</div>
|
|
|
|
<div className="flex justify-center">
|
2022-11-23 02:55:25 +00:00
|
|
|
<div className="min-w-80 flex w-full rounded-md border border-gray-200 bg-white p-7">
|
|
|
|
<div className="w-full">
|
|
|
|
<div className="flex">
|
|
|
|
<div className="w-full">
|
|
|
|
<div className="flex">
|
|
|
|
<div className="mt-[3px] mr-5 flex h-5 w-5 items-center justify-center rounded-full bg-gray-100 p-1 text-xs">
|
|
|
|
{step.stepNumber + 1}
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<div className="text-base font-bold">{t("action")}</div>
|
|
|
|
<div className="text-sm text-gray-600">{t("action_is_performed")}</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<Dropdown>
|
|
|
|
<DropdownMenuTrigger asChild>
|
|
|
|
<Button type="button" color="minimal" size="icon" StartIcon={Icon.FiMoreHorizontal} />
|
|
|
|
</DropdownMenuTrigger>
|
|
|
|
<DropdownMenuContent>
|
|
|
|
<DropdownMenuItem>
|
|
|
|
<Button
|
|
|
|
onClick={() => {
|
|
|
|
const steps = form.getValues("steps");
|
|
|
|
const updatedSteps = steps
|
|
|
|
?.filter((currStep) => currStep.id !== step.id)
|
|
|
|
.map((s) => {
|
|
|
|
const updatedStep = s;
|
|
|
|
if (step.stepNumber < updatedStep.stepNumber) {
|
|
|
|
updatedStep.stepNumber = updatedStep.stepNumber - 1;
|
|
|
|
}
|
|
|
|
return updatedStep;
|
|
|
|
});
|
|
|
|
form.setValue("steps", updatedSteps);
|
|
|
|
if (setReload) {
|
|
|
|
setReload(!reload);
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
color="secondary"
|
|
|
|
size="base"
|
|
|
|
StartIcon={Icon.FiTrash2}
|
|
|
|
className="w-full rounded-none">
|
|
|
|
{t("delete")}
|
|
|
|
</Button>
|
|
|
|
</DropdownMenuItem>
|
|
|
|
</DropdownMenuContent>
|
|
|
|
</Dropdown>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-08-26 01:04:44 +00:00
|
|
|
<div className="my-7 border-t border-gray-200" />
|
2022-07-14 00:10:45 +00:00
|
|
|
<div>
|
2022-11-23 02:55:25 +00:00
|
|
|
<Label>{t("do_this")}</Label>
|
2022-07-14 00:10:45 +00:00
|
|
|
<Controller
|
|
|
|
name={`steps.${step.stepNumber - 1}.action`}
|
|
|
|
control={form.control}
|
|
|
|
render={() => {
|
|
|
|
return (
|
|
|
|
<Select
|
|
|
|
isSearchable={false}
|
2022-11-23 02:55:25 +00:00
|
|
|
className="text-sm"
|
2022-07-14 00:10:45 +00:00
|
|
|
onChange={(val) => {
|
|
|
|
if (val) {
|
2022-11-25 14:34:55 +00:00
|
|
|
const oldValue = form.getValues(`steps.${step.stepNumber - 1}.action`);
|
|
|
|
const wasSMSAction =
|
|
|
|
oldValue === WorkflowActions.SMS_ATTENDEE ||
|
|
|
|
oldValue === WorkflowActions.SMS_NUMBER;
|
|
|
|
const isSMSAction =
|
|
|
|
val.value === WorkflowActions.SMS_ATTENDEE ||
|
|
|
|
val.value === WorkflowActions.SMS_NUMBER;
|
|
|
|
|
|
|
|
if (isSMSAction) {
|
2022-11-23 02:55:25 +00:00
|
|
|
setIsSenderIdNeeded(true);
|
|
|
|
setIsEmailAddressNeeded(false);
|
2022-11-25 14:34:55 +00:00
|
|
|
setIsPhoneNumberNeeded(val.value === WorkflowActions.SMS_NUMBER);
|
|
|
|
|
|
|
|
if (!wasSMSAction) {
|
|
|
|
form.setValue(`steps.${step.stepNumber - 1}.reminderBody`, "");
|
|
|
|
}
|
2022-07-14 00:10:45 +00:00
|
|
|
} else {
|
|
|
|
setIsPhoneNumberNeeded(false);
|
2022-11-23 02:55:25 +00:00
|
|
|
setIsSenderIdNeeded(false);
|
2022-11-25 14:34:55 +00:00
|
|
|
setIsEmailAddressNeeded(val.value === WorkflowActions.EMAIL_ADDRESS);
|
|
|
|
|
|
|
|
if (wasSMSAction) {
|
|
|
|
form.setValue(`steps.${step.stepNumber - 1}.reminderBody`, "");
|
|
|
|
}
|
2022-07-14 00:10:45 +00:00
|
|
|
}
|
2022-11-25 14:34:55 +00:00
|
|
|
|
2022-11-23 02:55:25 +00:00
|
|
|
form.unregister(`steps.${step.stepNumber - 1}.sendTo`);
|
|
|
|
form.clearErrors(`steps.${step.stepNumber - 1}.sendTo`);
|
2022-07-14 00:10:45 +00:00
|
|
|
if (
|
|
|
|
val.value === WorkflowActions.EMAIL_ATTENDEE ||
|
2022-11-23 02:55:25 +00:00
|
|
|
val.value === WorkflowActions.EMAIL_HOST ||
|
|
|
|
val.value === WorkflowActions.EMAIL_ADDRESS
|
2022-07-14 00:10:45 +00:00
|
|
|
) {
|
|
|
|
setIsEmailSubjectNeeded(true);
|
|
|
|
} else {
|
|
|
|
setIsEmailSubjectNeeded(false);
|
|
|
|
}
|
|
|
|
form.setValue(`steps.${step.stepNumber - 1}.action`, val.value);
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
defaultValue={selectedAction}
|
2022-11-23 22:42:42 +00:00
|
|
|
options={actionOptions}
|
2022-12-15 00:11:57 +00:00
|
|
|
isOptionDisabled={(option: {
|
|
|
|
label: string;
|
|
|
|
value: WorkflowActions;
|
|
|
|
disabled: boolean;
|
|
|
|
}) => option.disabled}
|
2022-07-14 00:10:45 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
2022-11-23 02:55:25 +00:00
|
|
|
{(isPhoneNumberNeeded || isSenderIdNeeded) && (
|
|
|
|
<div className="mt-2 rounded-md bg-gray-50 p-4 pt-0">
|
|
|
|
{isPhoneNumberNeeded && (
|
|
|
|
<>
|
|
|
|
<Label className="pt-4">{t("custom_phone_number")}</Label>
|
|
|
|
<PhoneInput<FormValues>
|
|
|
|
control={form.control}
|
|
|
|
name={`steps.${step.stepNumber - 1}.sendTo`}
|
|
|
|
placeholder={t("phone_number")}
|
|
|
|
id={`steps.${step.stepNumber - 1}.sendTo`}
|
|
|
|
className="w-full rounded-md"
|
2022-07-14 00:10:45 +00:00
|
|
|
required
|
2022-11-23 02:55:25 +00:00
|
|
|
/>
|
|
|
|
{form.formState.errors.steps &&
|
|
|
|
form.formState?.errors?.steps[step.stepNumber - 1]?.sendTo && (
|
|
|
|
<p className="mt-1 text-xs text-red-500">
|
|
|
|
{form.formState?.errors?.steps[step.stepNumber - 1]?.sendTo?.message || ""}
|
|
|
|
</p>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
{isSenderIdNeeded && (
|
|
|
|
<>
|
|
|
|
<div className="pt-4">
|
|
|
|
<TextField
|
|
|
|
label={t("sender_id")}
|
|
|
|
type="text"
|
2022-12-12 11:00:15 +00:00
|
|
|
placeholder={SENDER_ID}
|
2022-11-23 02:55:25 +00:00
|
|
|
maxLength={11}
|
|
|
|
{...form.register(`steps.${step.stepNumber - 1}.sender`)}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
{form.formState.errors.steps &&
|
|
|
|
form.formState?.errors?.steps[step.stepNumber - 1]?.sender && (
|
|
|
|
<p className="mt-1 text-xs text-red-500">{t("sender_id_error_message")}</p>
|
2022-07-14 00:10:45 +00:00
|
|
|
)}
|
2022-11-23 02:55:25 +00:00
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{form.getValues(`steps.${step.stepNumber - 1}.action`) === WorkflowActions.SMS_ATTENDEE && (
|
|
|
|
<div className="mt-2">
|
|
|
|
<Controller
|
|
|
|
name={`steps.${step.stepNumber - 1}.numberRequired`}
|
|
|
|
control={form.control}
|
|
|
|
render={() => (
|
|
|
|
<Checkbox
|
|
|
|
defaultChecked={
|
|
|
|
form.getValues(`steps.${step.stepNumber - 1}.numberRequired`) || false
|
|
|
|
}
|
|
|
|
description={t("make_phone_number_required")}
|
|
|
|
onChange={(e) =>
|
|
|
|
form.setValue(`steps.${step.stepNumber - 1}.numberRequired`, e.target.checked)
|
|
|
|
}
|
2022-07-14 00:10:45 +00:00
|
|
|
/>
|
|
|
|
)}
|
2022-11-23 02:55:25 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{isEmailAddressNeeded && (
|
|
|
|
<div className="mt-5 rounded-md bg-gray-50 p-4">
|
|
|
|
<EmailField
|
|
|
|
required
|
|
|
|
label={t("email_address")}
|
|
|
|
{...form.register(`steps.${step.stepNumber - 1}.sendTo`)}
|
|
|
|
/>
|
|
|
|
</div>
|
2022-07-14 00:10:45 +00:00
|
|
|
)}
|
|
|
|
<div className="mt-5">
|
2022-11-23 02:55:25 +00:00
|
|
|
<Label>{t("message_template")}</Label>
|
2022-07-14 00:10:45 +00:00
|
|
|
<Controller
|
|
|
|
name={`steps.${step.stepNumber - 1}.template`}
|
|
|
|
control={form.control}
|
|
|
|
render={() => {
|
|
|
|
return (
|
|
|
|
<Select
|
|
|
|
isSearchable={false}
|
2022-11-23 02:55:25 +00:00
|
|
|
className="text-sm"
|
2022-07-14 00:10:45 +00:00
|
|
|
onChange={(val) => {
|
|
|
|
if (val) {
|
|
|
|
form.setValue(`steps.${step.stepNumber - 1}.template`, val.value);
|
|
|
|
const isCustomTemplate = val.value === WorkflowTemplates.CUSTOM;
|
|
|
|
setIsCustomReminderBodyNeeded(isCustomTemplate);
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
defaultValue={selectedTemplate}
|
|
|
|
options={templateOptions}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
{isCustomReminderBodyNeeded && (
|
2022-11-23 02:55:25 +00:00
|
|
|
<div className="mt-2 rounded-md bg-gray-50 p-4 pt-2 md:p-6 md:pt-4">
|
2022-07-14 00:10:45 +00:00
|
|
|
{isEmailSubjectNeeded && (
|
2022-11-25 14:34:55 +00:00
|
|
|
<div className="mb-6">
|
|
|
|
<div className="flex items-center">
|
2022-11-23 02:55:25 +00:00
|
|
|
<Label className="mb-0 flex-none">{t("subject")}</Label>
|
|
|
|
<div className="flex-grow text-right">
|
|
|
|
<AddVariablesDropdown addVariable={addVariable} isEmailSubject={true} />
|
|
|
|
</div>
|
2022-08-03 22:22:38 +00:00
|
|
|
</div>
|
2022-11-23 02:55:25 +00:00
|
|
|
<TextArea
|
|
|
|
ref={(e) => {
|
|
|
|
emailSubjectFormRef?.(e);
|
|
|
|
refEmailSubject.current = e;
|
|
|
|
}}
|
2022-11-25 14:34:55 +00:00
|
|
|
rows={1}
|
|
|
|
className="my-0 focus:ring-transparent"
|
2022-11-23 02:55:25 +00:00
|
|
|
required
|
|
|
|
{...restEmailSubjectForm}
|
|
|
|
/>
|
|
|
|
{form.formState.errors.steps &&
|
|
|
|
form.formState?.errors?.steps[step.stepNumber - 1]?.emailSubject && (
|
|
|
|
<p className="mt-1 text-xs text-red-500">
|
|
|
|
{form.formState?.errors?.steps[step.stepNumber - 1]?.emailSubject?.message || ""}
|
|
|
|
</p>
|
|
|
|
)}
|
2022-07-14 00:10:45 +00:00
|
|
|
</div>
|
|
|
|
)}
|
2022-11-25 14:34:55 +00:00
|
|
|
|
|
|
|
{step.action !== WorkflowActions.SMS_ATTENDEE &&
|
|
|
|
step.action !== WorkflowActions.SMS_NUMBER ? (
|
|
|
|
<>
|
|
|
|
<div className="mb-2 flex items-center pb-[1.5px]">
|
|
|
|
<Label className="mb-0 flex-none ">
|
|
|
|
{isEmailSubjectNeeded ? t("email_body") : t("text_message")}
|
|
|
|
</Label>
|
|
|
|
</div>
|
|
|
|
<Editor form={form} stepNumber={step.stepNumber} />
|
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
<div className="flex items-center">
|
|
|
|
<Label className="mb-0 flex-none">
|
|
|
|
{isEmailSubjectNeeded ? t("email_body") : t("text_message")}
|
|
|
|
</Label>
|
|
|
|
<div className="flex-grow text-right">
|
|
|
|
<AddVariablesDropdown addVariable={addVariable} isEmailSubject={false} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<TextArea
|
|
|
|
ref={(e) => {
|
|
|
|
reminderBodyFormRef?.(e);
|
|
|
|
refReminderBody.current = e;
|
|
|
|
}}
|
|
|
|
className="my-0 h-24"
|
|
|
|
required
|
|
|
|
{...restReminderBodyForm}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
)}
|
2022-11-23 02:55:25 +00:00
|
|
|
{form.formState.errors.steps &&
|
|
|
|
form.formState?.errors?.steps[step.stepNumber - 1]?.reminderBody && (
|
2022-11-25 14:34:55 +00:00
|
|
|
<p className="mt-1 text-sm text-red-500">
|
2022-11-23 02:55:25 +00:00
|
|
|
{form.formState?.errors?.steps[step.stepNumber - 1]?.reminderBody?.message || ""}
|
|
|
|
</p>
|
2022-07-14 00:10:45 +00:00
|
|
|
)}
|
2022-11-23 02:55:25 +00:00
|
|
|
<div className="mt-3 ">
|
|
|
|
<button type="button" onClick={() => setIsAdditionalInputsDialogOpen(true)}>
|
|
|
|
<div className="mt-2 flex text-sm text-gray-600">
|
|
|
|
<Icon.FiHelpCircle className="mt-[3px] mr-2 h-3 w-3" />
|
|
|
|
<p className="text-left">{t("using_additional_inputs_as_variables")}</p>
|
|
|
|
</div>
|
|
|
|
</button>
|
2022-08-03 22:22:38 +00:00
|
|
|
</div>
|
2022-11-23 02:55:25 +00:00
|
|
|
</div>
|
2022-07-14 00:10:45 +00:00
|
|
|
)}
|
2022-08-26 01:04:44 +00:00
|
|
|
{form.getValues(`steps.${step.stepNumber - 1}.action`) !== WorkflowActions.SMS_ATTENDEE && (
|
|
|
|
<Button
|
|
|
|
type="button"
|
|
|
|
className="mt-7 w-full"
|
|
|
|
onClick={() => {
|
2022-11-23 02:55:25 +00:00
|
|
|
let isEmpty = false;
|
|
|
|
if (!form.getValues(`steps.${step.stepNumber - 1}.sendTo`) && isPhoneNumberNeeded) {
|
|
|
|
form.setError(`steps.${step.stepNumber - 1}.sendTo`, {
|
|
|
|
type: "custom",
|
|
|
|
message: t("no_input"),
|
|
|
|
});
|
|
|
|
isEmpty = true;
|
|
|
|
}
|
2022-08-26 01:04:44 +00:00
|
|
|
if (
|
2022-11-23 02:55:25 +00:00
|
|
|
form.getValues(`steps.${step.stepNumber - 1}.template`) === WorkflowTemplates.CUSTOM
|
2022-08-26 01:04:44 +00:00
|
|
|
) {
|
2022-11-23 02:55:25 +00:00
|
|
|
if (!form.getValues(`steps.${step.stepNumber - 1}.reminderBody`)) {
|
|
|
|
form.setError(`steps.${step.stepNumber - 1}.reminderBody`, {
|
|
|
|
type: "custom",
|
|
|
|
message: t("no_input"),
|
|
|
|
});
|
|
|
|
isEmpty = true;
|
|
|
|
} else if (
|
|
|
|
isEmailSubjectNeeded &&
|
|
|
|
!form.getValues(`steps.${step.stepNumber - 1}.emailSubject`)
|
|
|
|
) {
|
|
|
|
form.setError(`steps.${step.stepNumber - 1}.emailSubject`, {
|
|
|
|
type: "custom",
|
|
|
|
message: t("no_input"),
|
|
|
|
});
|
|
|
|
isEmpty = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isPhoneNumberNeeded && !isEmpty) {
|
|
|
|
//translate body and reminder to english
|
|
|
|
const emailSubject = translateVariablesToEnglish(
|
|
|
|
form.getValues(`steps.${step.stepNumber - 1}.emailSubject`) || "",
|
|
|
|
{ locale: i18n.language, t }
|
|
|
|
);
|
|
|
|
const reminderBody = translateVariablesToEnglish(
|
|
|
|
form.getValues(`steps.${step.stepNumber - 1}.reminderBody`) || "",
|
|
|
|
{ locale: i18n.language, t }
|
|
|
|
);
|
|
|
|
|
2022-08-26 01:04:44 +00:00
|
|
|
testActionMutation.mutate({
|
|
|
|
action: step.action,
|
2022-11-23 02:55:25 +00:00
|
|
|
emailSubject,
|
|
|
|
reminderBody,
|
2022-08-26 01:04:44 +00:00
|
|
|
template: step.template,
|
2022-12-12 11:00:15 +00:00
|
|
|
sender: step.sender || SENDER_ID,
|
2022-08-26 01:04:44 +00:00
|
|
|
});
|
|
|
|
} else {
|
2022-11-23 02:55:25 +00:00
|
|
|
const isNumberValid =
|
|
|
|
form.formState.errors.steps &&
|
|
|
|
form.formState?.errors?.steps[step.stepNumber - 1]?.sendTo
|
|
|
|
? false
|
|
|
|
: true;
|
|
|
|
|
|
|
|
if (isPhoneNumberNeeded && isNumberValid && !isEmpty) {
|
|
|
|
setConfirmationDialogOpen(true);
|
|
|
|
}
|
2022-08-26 01:04:44 +00:00
|
|
|
}
|
|
|
|
}}
|
|
|
|
color="secondary">
|
|
|
|
<div className="w-full">{t("test_action")}</div>
|
|
|
|
</Button>
|
|
|
|
)}
|
2022-07-14 00:10:45 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-08-26 01:04:44 +00:00
|
|
|
<Dialog open={confirmationDialogOpen} onOpenChange={setConfirmationDialogOpen}>
|
|
|
|
<ConfirmationDialogContent
|
|
|
|
variety="warning"
|
|
|
|
title={t("test_workflow_action")}
|
|
|
|
confirmBtnText={t("send_sms")}
|
|
|
|
onConfirm={(e) => {
|
|
|
|
e.preventDefault();
|
2022-11-23 02:55:25 +00:00
|
|
|
const reminderBody = translateVariablesToEnglish(
|
|
|
|
form.getValues(`steps.${step.stepNumber - 1}.reminderBody`) || "",
|
|
|
|
{ locale: i18n.language, t }
|
|
|
|
);
|
|
|
|
|
2022-08-26 01:04:44 +00:00
|
|
|
testActionMutation.mutate({
|
|
|
|
action: step.action,
|
2022-11-23 02:55:25 +00:00
|
|
|
emailSubject: "",
|
|
|
|
reminderBody: reminderBody || "",
|
2022-08-26 01:04:44 +00:00
|
|
|
template: step.template,
|
|
|
|
sendTo: step.sendTo || "",
|
2022-12-12 11:00:15 +00:00
|
|
|
sender: step.sender || SENDER_ID,
|
2022-08-26 01:04:44 +00:00
|
|
|
});
|
|
|
|
setConfirmationDialogOpen(false);
|
|
|
|
}}>
|
2022-11-23 02:55:25 +00:00
|
|
|
{t("send_sms_to_number", { number: form.getValues(`steps.${step.stepNumber - 1}.sendTo`) })}
|
2022-08-26 01:04:44 +00:00
|
|
|
</ConfirmationDialogContent>
|
|
|
|
</Dialog>
|
2022-11-23 02:55:25 +00:00
|
|
|
<Dialog open={isAdditionalInputsDialogOpen} onOpenChange={setIsAdditionalInputsDialogOpen}>
|
2022-11-28 19:14:38 +00:00
|
|
|
<DialogContent type="creation" className="sm:max-w-[610px] md:h-[570px]">
|
2022-11-23 02:55:25 +00:00
|
|
|
<div className="-m-3 h-[430px] overflow-x-hidden overflow-y-scroll sm:m-0">
|
|
|
|
<h1 className="w-full text-xl font-semibold ">{t("how_additional_inputs_as_variables")}</h1>
|
|
|
|
<div className="mb-7 mt-7 rounded-md bg-gray-50 p-3 sm:p-4">
|
|
|
|
<p className="test-sm font-medium">{t("format")}</p>
|
|
|
|
<ul className="mt-2 ml-5 list-disc text-gray-900">
|
|
|
|
<li>{t("uppercase_for_letters")}</li>
|
|
|
|
<li>{t("replace_whitespaces_underscores")}</li>
|
|
|
|
<li>{t("ignore_special_characters")}</li>
|
|
|
|
</ul>
|
|
|
|
<div className="mt-6">
|
|
|
|
<p className="test-sm w-full font-medium">{t("example_1")}</p>
|
|
|
|
<div className="mt-2 grid grid-cols-12">
|
|
|
|
<div className="test-sm col-span-5 mr-2 text-gray-600">{t("additional_input_label")}</div>
|
|
|
|
<div className="test-sm col-span-7 text-gray-900">{t("company_size")}</div>
|
|
|
|
<div className="test-sm col-span-5 w-full text-gray-600">{t("variable")}</div>
|
|
|
|
|
|
|
|
<div className="test-sm col-span-7 break-words text-gray-900">
|
|
|
|
{" "}
|
|
|
|
{`{${t("company_size")
|
|
|
|
.replace(/[^a-zA-Z0-9 ]/g, "")
|
|
|
|
.trim()
|
|
|
|
.replace(/ /g, "_")
|
|
|
|
.toUpperCase()}}`}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="mt-6">
|
|
|
|
<p className="test-sm w-full font-medium">{t("example_2")}</p>
|
|
|
|
<div className="mt-2 grid grid-cols-12">
|
|
|
|
<div className="test-sm col-span-5 mr-2 text-gray-600">{t("additional_input_label")}</div>
|
|
|
|
<div className="test-sm col-span-7 text-gray-900">{t("what_help_needed")}</div>
|
|
|
|
<div className="test-sm col-span-5 text-gray-600">{t("variable")}</div>
|
|
|
|
<div className="test-sm col-span-7 break-words text-gray-900">
|
|
|
|
{" "}
|
|
|
|
{`{${t("what_help_needed")
|
|
|
|
.replace(/[^a-zA-Z0-9 ]/g, "")
|
|
|
|
.trim()
|
|
|
|
.replace(/ /g, "_")
|
|
|
|
.toUpperCase()}}`}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="flex flex-row-reverse">
|
2022-11-28 19:14:38 +00:00
|
|
|
<DialogClose color="primary" />
|
2022-11-23 02:55:25 +00:00
|
|
|
</div>
|
|
|
|
</DialogContent>
|
|
|
|
</Dialog>
|
2022-07-14 00:10:45 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return <></>;
|
|
|
|
}
|