2023-02-27 07:24:43 +00:00
|
|
|
import type { WorkflowStep } from "@prisma/client";
|
|
|
|
import type { Dispatch, SetStateAction } from "react";
|
|
|
|
import { useRef, useState, useEffect } from "react";
|
|
|
|
import type { UseFormReturn } from "react-hook-form";
|
|
|
|
import { Controller } 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-15 21:54:40 +00:00
|
|
|
import { classNames } from "@calcom/lib";
|
2023-07-11 15:48:44 +00:00
|
|
|
import { SENDER_ID, SENDER_NAME } 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";
|
2023-07-19 14:30:37 +00:00
|
|
|
import { getTimeFormatStringFromUserTimeFormat } from "@calcom/lib/timeFormat";
|
2023-05-02 11:44:05 +00:00
|
|
|
import { WorkflowTemplates, TimeUnit, WorkflowActions } from "@calcom/prisma/enums";
|
|
|
|
import { WorkflowTriggerEvents } from "@calcom/prisma/enums";
|
2023-01-23 23:08:01 +00:00
|
|
|
import { trpc } from "@calcom/trpc/react";
|
2023-07-19 14:30:37 +00:00
|
|
|
import type { RouterOutputs } from "@calcom/trpc/react";
|
2022-11-23 02:55:25 +00:00
|
|
|
import {
|
2022-12-15 21:54:40 +00:00
|
|
|
Badge,
|
2022-11-23 02:55:25 +00:00
|
|
|
Button,
|
2023-07-19 19:45:13 +00:00
|
|
|
CheckboxField,
|
2022-11-23 02:55:25 +00:00
|
|
|
Dialog,
|
|
|
|
DialogClose,
|
|
|
|
DialogContent,
|
2023-06-29 07:47:16 +00:00
|
|
|
DialogFooter,
|
2022-11-23 02:55:25 +00:00
|
|
|
Dropdown,
|
|
|
|
DropdownMenuContent,
|
|
|
|
DropdownMenuItem,
|
2023-01-15 11:40:40 +00:00
|
|
|
DropdownItem,
|
2022-11-23 02:55:25 +00:00
|
|
|
DropdownMenuTrigger,
|
|
|
|
EmailField,
|
|
|
|
Label,
|
|
|
|
PhoneInput,
|
|
|
|
Select,
|
|
|
|
showToast,
|
|
|
|
TextArea,
|
|
|
|
TextField,
|
2023-01-09 14:15:11 +00:00
|
|
|
Editor,
|
|
|
|
AddVariablesDropdown,
|
2023-01-18 14:32:39 +00:00
|
|
|
Input,
|
2023-06-11 03:20:13 +00:00
|
|
|
Tooltip,
|
2022-11-23 02:55:25 +00:00
|
|
|
} from "@calcom/ui";
|
2023-04-18 10:08:09 +00:00
|
|
|
import { ArrowDown, MoreHorizontal, Trash2, HelpCircle, Info } from "@calcom/ui/components/icon";
|
2022-07-28 19:58:26 +00:00
|
|
|
|
2023-07-18 20:27:54 +00:00
|
|
|
import {
|
|
|
|
isAttendeeAction,
|
|
|
|
isSMSAction,
|
|
|
|
isSMSOrWhatsappAction,
|
|
|
|
isWhatsappAction,
|
|
|
|
getWhatsappTemplateForAction,
|
2023-08-10 18:52:36 +00:00
|
|
|
isTextMessageToAttendeeAction,
|
2023-07-18 20:27:54 +00:00
|
|
|
} from "../lib/actionHelperFunctions";
|
2023-01-10 02:22:17 +00:00
|
|
|
import { DYNAMIC_TEXT_VARIABLES } from "../lib/constants";
|
2022-12-15 21:54:40 +00:00
|
|
|
import { getWorkflowTemplateOptions, getWorkflowTriggerOptions } from "../lib/getOptions";
|
2023-04-18 10:08:09 +00:00
|
|
|
import emailReminderTemplate from "../lib/reminders/templates/emailReminderTemplate";
|
|
|
|
import smsReminderTemplate from "../lib/reminders/templates/smsReminderTemplate";
|
2023-07-11 15:48:44 +00:00
|
|
|
import { whatsappReminderTemplate } from "../lib/reminders/templates/whatsapp";
|
2022-07-28 19:58:26 +00:00
|
|
|
import type { FormValues } from "../pages/workflow";
|
2022-11-23 02:55:25 +00:00
|
|
|
import { TimeTimeUnitInput } from "./TimeTimeUnitInput";
|
2022-07-14 00:10:45 +00:00
|
|
|
|
2023-07-19 14:30:37 +00:00
|
|
|
type User = RouterOutputs["viewer"]["me"];
|
|
|
|
|
2022-07-14 00:10:45 +00:00
|
|
|
type WorkflowStepProps = {
|
|
|
|
step?: WorkflowStep;
|
2022-07-20 19:48:40 +00:00
|
|
|
form: UseFormReturn<FormValues>;
|
2023-07-19 14:30:37 +00:00
|
|
|
user: User;
|
2022-07-14 00:10:45 +00:00
|
|
|
reload?: boolean;
|
|
|
|
setReload?: Dispatch<SetStateAction<boolean>>;
|
2023-02-27 07:24:43 +00:00
|
|
|
teamId?: number;
|
2023-05-15 13:56:26 +00:00
|
|
|
readOnly: boolean;
|
2023-08-10 18:52:36 +00:00
|
|
|
setKYCVerificationDialogOpen: Dispatch<SetStateAction<boolean>>;
|
2022-07-14 00:10:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default function WorkflowStepContainer(props: WorkflowStepProps) {
|
2023-02-27 07:24:43 +00:00
|
|
|
const { t } = useLocale();
|
2022-12-15 21:54:40 +00:00
|
|
|
const utils = trpc.useContext();
|
2023-01-11 18:41:45 +00:00
|
|
|
|
2023-02-27 07:24:43 +00:00
|
|
|
const { step, form, reload, setReload, teamId } = props;
|
|
|
|
const { data: _verifiedNumbers } = trpc.viewer.workflows.getVerifiedNumbers.useQuery(
|
|
|
|
{ teamId },
|
|
|
|
{ enabled: !!teamId }
|
|
|
|
);
|
2023-07-19 14:30:37 +00:00
|
|
|
|
|
|
|
const timeFormat = getTimeFormatStringFromUserTimeFormat(props.user.timeFormat);
|
|
|
|
|
2023-02-27 07:24:43 +00:00
|
|
|
const verifiedNumbers = _verifiedNumbers?.map((number) => number.phoneNumber) || [];
|
2022-11-23 02:55:25 +00:00
|
|
|
const [isAdditionalInputsDialogOpen, setIsAdditionalInputsDialogOpen] = useState(false);
|
2022-08-03 22:22:38 +00:00
|
|
|
|
2022-12-15 21:54:40 +00:00
|
|
|
const [verificationCode, setVerificationCode] = useState("");
|
|
|
|
|
2023-07-18 20:27:54 +00:00
|
|
|
const action = step?.action;
|
|
|
|
const requirePhoneNumber =
|
|
|
|
WorkflowActions.SMS_NUMBER === action || WorkflowActions.WHATSAPP_NUMBER === action;
|
2023-07-11 15:48:44 +00:00
|
|
|
const [isPhoneNumberNeeded, setIsPhoneNumberNeeded] = useState(requirePhoneNumber);
|
2022-07-14 00:10:45 +00:00
|
|
|
|
2023-04-18 10:08:09 +00:00
|
|
|
const [updateTemplate, setUpdateTemplate] = useState(false);
|
|
|
|
const [firstRender, setFirstRender] = useState(true);
|
|
|
|
|
2023-07-18 20:27:54 +00:00
|
|
|
const senderNeeded =
|
|
|
|
step?.action === WorkflowActions.SMS_NUMBER || step?.action === WorkflowActions.SMS_ATTENDEE;
|
2023-07-11 15:48:44 +00:00
|
|
|
|
|
|
|
const [isSenderIsNeeded, setIsSenderIsNeeded] = useState(senderNeeded);
|
2023-02-27 07:24:43 +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 [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
|
|
|
);
|
2023-08-10 18:52:36 +00:00
|
|
|
|
|
|
|
const [isRequiresConfirmationNeeded, setIsRequiresConfirmationNeeded] = useState(
|
|
|
|
isTextMessageToAttendeeAction(step?.action)
|
|
|
|
);
|
|
|
|
|
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);
|
2023-07-11 15:48:44 +00:00
|
|
|
const templateOptions = getWorkflowTemplateOptions(t, step?.action);
|
2022-07-14 00:10:45 +00:00
|
|
|
|
2023-04-18 10:08:09 +00:00
|
|
|
if (step && form.getValues(`steps.${step.stepNumber - 1}.template`) === WorkflowTemplates.REMINDER) {
|
|
|
|
if (!form.getValues(`steps.${step.stepNumber - 1}.reminderBody`)) {
|
2023-07-11 15:48:44 +00:00
|
|
|
const action = form.getValues(`steps.${step.stepNumber - 1}.action`);
|
|
|
|
if (isSMSAction(action)) {
|
2023-07-19 14:30:37 +00:00
|
|
|
form.setValue(
|
|
|
|
`steps.${step.stepNumber - 1}.reminderBody`,
|
|
|
|
smsReminderTemplate(true, action, timeFormat)
|
|
|
|
);
|
2023-07-11 15:48:44 +00:00
|
|
|
} else if (isWhatsappAction(action)) {
|
2023-07-19 14:30:37 +00:00
|
|
|
form.setValue(
|
|
|
|
`steps.${step.stepNumber - 1}.reminderBody`,
|
|
|
|
whatsappReminderTemplate(true, action, timeFormat)
|
|
|
|
);
|
2023-04-18 10:08:09 +00:00
|
|
|
} else {
|
2023-07-19 14:30:37 +00:00
|
|
|
const reminderBodyTemplate = emailReminderTemplate(true, action, timeFormat).emailBody;
|
2023-04-18 10:08:09 +00:00
|
|
|
form.setValue(`steps.${step.stepNumber - 1}.reminderBody`, reminderBodyTemplate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!form.getValues(`steps.${step.stepNumber - 1}.emailSubject`)) {
|
|
|
|
const subjectTemplate = emailReminderTemplate(
|
|
|
|
true,
|
2023-07-19 14:30:37 +00:00
|
|
|
form.getValues(`steps.${step.stepNumber - 1}.action`),
|
|
|
|
timeFormat
|
2023-04-18 10:08:09 +00:00
|
|
|
).emailSubject;
|
|
|
|
form.setValue(`steps.${step.stepNumber - 1}.emailSubject`, subjectTemplate);
|
|
|
|
}
|
2023-07-11 15:48:44 +00:00
|
|
|
} else if (step && isWhatsappAction(step.action)) {
|
2023-07-19 14:30:37 +00:00
|
|
|
const templateBody = getWhatsappTemplateForAction(step.action, step.template, timeFormat);
|
2023-07-18 20:27:54 +00:00
|
|
|
form.setValue(`steps.${step.stepNumber - 1}.reminderBody`, templateBody);
|
2023-04-18 10:08:09 +00:00
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
2023-07-18 20:27:54 +00:00
|
|
|
const getNumberVerificationStatus = () =>
|
|
|
|
!!step &&
|
|
|
|
!!verifiedNumbers.find(
|
|
|
|
(number: string) => number === form.getValues(`steps.${step.stepNumber - 1}.sendTo`)
|
|
|
|
);
|
2023-07-11 15:48:44 +00:00
|
|
|
|
|
|
|
const [numberVerified, setNumberVerified] = useState(getNumberVerificationStatus());
|
|
|
|
|
|
|
|
useEffect(() => setNumberVerified(getNumberVerificationStatus()), [verifiedNumbers.length]);
|
2022-12-15 21:54:40 +00:00
|
|
|
|
2023-01-09 14:15:11 +00:00
|
|
|
const addVariableBody = (variable: string) => {
|
2022-08-03 22:22:38 +00:00
|
|
|
if (step) {
|
2023-01-09 14:15:11 +00:00
|
|
|
const currentMessageBody = refReminderBody?.current?.value || "";
|
|
|
|
const cursorPosition = refReminderBody?.current?.selectionStart || currentMessageBody.length;
|
|
|
|
const messageWithAddedVariable = `${currentMessageBody.substring(0, cursorPosition)}{${variable
|
|
|
|
.toUpperCase()
|
|
|
|
.replace(/ /g, "_")}}${currentMessageBody.substring(cursorPosition)}`;
|
|
|
|
form.setValue(`steps.${step.stepNumber - 1}.reminderBody`, messageWithAddedVariable);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const addVariableEmailSubject = (variable: string) => {
|
|
|
|
if (step) {
|
|
|
|
const currentEmailSubject = refEmailSubject?.current?.value || "";
|
|
|
|
const cursorPosition = refEmailSubject?.current?.selectionStart || currentEmailSubject.length;
|
|
|
|
const subjectWithAddedVariable = `${currentEmailSubject.substring(0, cursorPosition)}{${variable
|
|
|
|
.toUpperCase()
|
|
|
|
.replace(/ /g, "_")}}${currentEmailSubject.substring(cursorPosition)}`;
|
|
|
|
form.setValue(`steps.${step.stepNumber - 1}.emailSubject`, subjectWithAddedVariable);
|
2022-08-03 22:22:38 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-12-15 21:54:40 +00:00
|
|
|
const sendVerificationCodeMutation = trpc.viewer.workflows.sendVerificationCode.useMutation({
|
|
|
|
onSuccess: async () => {
|
|
|
|
showToast(t("verification_code_sent"), "success");
|
|
|
|
},
|
|
|
|
onError: async (error) => {
|
|
|
|
showToast(error.message, "error");
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const verifyPhoneNumberMutation = trpc.viewer.workflows.verifyPhoneNumber.useMutation({
|
|
|
|
onSuccess: async (isVerified) => {
|
|
|
|
showToast(isVerified ? t("verified_successfully") : t("wrong_code"), "success");
|
|
|
|
setNumberVerified(isVerified);
|
|
|
|
utils.viewer.workflows.getVerifiedNumbers.invalidate();
|
|
|
|
},
|
|
|
|
onError: (err) => {
|
|
|
|
if (err instanceof HttpError) {
|
|
|
|
const message = `${err.statusCode}: ${err.message}`;
|
|
|
|
showToast(message, "error");
|
|
|
|
setNumberVerified(false);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2023-01-12 16:03:30 +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-12-15 21:54:40 +00:00
|
|
|
} else {
|
|
|
|
message = err.message;
|
2022-12-13 21:34:21 +00:00
|
|
|
}
|
|
|
|
}
|
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
|
|
|
},
|
2023-01-12 16:03:30 +00:00
|
|
|
}); */
|
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">
|
2023-07-18 20:27:54 +00:00
|
|
|
<div className="min-w-80 bg-default border-subtle w-full rounded-md border p-7">
|
2022-11-23 02:55:25 +00:00
|
|
|
<div className="flex">
|
2023-04-05 18:14:46 +00:00
|
|
|
<div className="bg-subtle text-default mt-[3px] flex h-5 w-5 items-center justify-center rounded-full p-1 text-xs font-medium ltr:mr-5 rtl:ml-5">
|
2022-11-23 02:55:25 +00:00
|
|
|
1
|
|
|
|
</div>
|
|
|
|
<div>
|
2023-07-18 20:27:54 +00:00
|
|
|
<div className="text-emphasis text-base font-bold">{t("trigger")}</div>
|
|
|
|
<div className="text-default text-sm">{t("when_something_happens")}</div>
|
2022-11-23 02:55:25 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2023-07-18 20:27:54 +00:00
|
|
|
<div className="border-subtle my-7 border-t" />
|
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"
|
2023-07-21 15:36:39 +00:00
|
|
|
id="trigger-select"
|
2023-05-15 13:56:26 +00:00
|
|
|
isDisabled={props.readOnly}
|
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>
|
2023-05-15 13:56:26 +00:00
|
|
|
<TimeTimeUnitInput form={form} disabled={props.readOnly} />
|
|
|
|
{!props.readOnly && (
|
2023-07-18 20:27:54 +00:00
|
|
|
<div className="mt-1 flex text-gray-500">
|
2023-05-15 13:56:26 +00:00
|
|
|
<Info className="mr-1 mt-0.5 h-4 w-4" />
|
|
|
|
<p className="text-sm">{t("testing_workflow_info_message")}</p>
|
|
|
|
</div>
|
|
|
|
)}
|
2022-07-14 00:10:45 +00:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (step && step.action) {
|
2023-07-11 15:48:44 +00:00
|
|
|
const templateValue = form.watch(`steps.${step.stepNumber - 1}.template`);
|
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,
|
2023-01-11 18:41:45 +00:00
|
|
|
needsUpgrade: false,
|
2023-08-10 18:52:36 +00:00
|
|
|
needsVerification: false,
|
|
|
|
verificationAction: () => props.setKYCVerificationDialogOpen(true),
|
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 };
|
|
|
|
|
2023-07-11 15:48:44 +00:00
|
|
|
const canRequirePhoneNumber = (workflowStep: string) => {
|
|
|
|
return (
|
2023-07-18 20:27:54 +00:00
|
|
|
WorkflowActions.SMS_ATTENDEE === workflowStep || WorkflowActions.WHATSAPP_ATTENDEE === workflowStep
|
|
|
|
);
|
|
|
|
};
|
2023-07-11 15:48:44 +00:00
|
|
|
|
2022-07-14 00:10:45 +00:00
|
|
|
return (
|
|
|
|
<>
|
2023-07-18 20:27:54 +00:00
|
|
|
<div className="my-3 flex justify-center">
|
2023-04-12 15:26:31 +00:00
|
|
|
<ArrowDown className="text-subtle stroke-[1.5px] text-3xl" />
|
2022-07-14 00:10:45 +00:00
|
|
|
</div>
|
|
|
|
<div className="flex justify-center">
|
2023-07-18 20:27:54 +00:00
|
|
|
<div className="min-w-80 bg-default border-subtle flex w-full rounded-md border p-7">
|
2022-11-23 02:55:25 +00:00
|
|
|
<div className="w-full">
|
|
|
|
<div className="flex">
|
|
|
|
<div className="w-full">
|
|
|
|
<div className="flex">
|
2023-04-05 18:14:46 +00:00
|
|
|
<div className="bg-subtle text-default mt-[3px] flex h-5 w-5 items-center justify-center rounded-full p-1 text-xs ltr:mr-5 rtl:ml-5">
|
2022-11-23 02:55:25 +00:00
|
|
|
{step.stepNumber + 1}
|
|
|
|
</div>
|
|
|
|
<div>
|
2023-07-18 20:27:54 +00:00
|
|
|
<div className="text-emphasis text-base font-bold">{t("action")}</div>
|
|
|
|
<div className="text-default text-sm">{t("action_is_performed")}</div>
|
2022-11-23 02:55:25 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-05-15 13:56:26 +00:00
|
|
|
{!props.readOnly && (
|
|
|
|
<div>
|
|
|
|
<Dropdown>
|
|
|
|
<DropdownMenuTrigger asChild>
|
|
|
|
<Button type="button" color="minimal" variant="icon" StartIcon={MoreHorizontal} />
|
|
|
|
</DropdownMenuTrigger>
|
|
|
|
<DropdownMenuContent>
|
|
|
|
<DropdownMenuItem>
|
|
|
|
<DropdownItem
|
|
|
|
type="button"
|
|
|
|
StartIcon={Trash2}
|
|
|
|
color="destructive"
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}}>
|
|
|
|
{t("delete")}
|
|
|
|
</DropdownItem>
|
|
|
|
</DropdownMenuItem>
|
|
|
|
</DropdownMenuContent>
|
|
|
|
</Dropdown>
|
|
|
|
</div>
|
|
|
|
)}
|
2022-11-23 02:55:25 +00:00
|
|
|
</div>
|
2023-07-18 20:27:54 +00:00
|
|
|
<div className="border-subtle my-7 border-t" />
|
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"
|
2023-05-15 13:56:26 +00:00
|
|
|
isDisabled={props.readOnly}
|
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`);
|
2023-01-18 14:32:39 +00:00
|
|
|
|
2023-07-18 20:27:54 +00:00
|
|
|
const setNumberRequiredConfigs = (
|
|
|
|
phoneNumberIsNeeded: boolean,
|
|
|
|
senderNeeded = true
|
|
|
|
) => {
|
2023-07-11 15:48:44 +00:00
|
|
|
setIsSenderIsNeeded(senderNeeded);
|
2022-11-23 02:55:25 +00:00
|
|
|
setIsEmailAddressNeeded(false);
|
2023-07-11 15:48:44 +00:00
|
|
|
setIsPhoneNumberNeeded(phoneNumberIsNeeded);
|
|
|
|
setNumberVerified(getNumberVerificationStatus());
|
2023-07-18 20:27:54 +00:00
|
|
|
};
|
2023-07-11 15:48:44 +00:00
|
|
|
|
|
|
|
if (isSMSAction(val.value)) {
|
2023-07-18 20:27:54 +00:00
|
|
|
setNumberRequiredConfigs(val.value === WorkflowActions.SMS_NUMBER);
|
2023-04-18 10:08:09 +00:00
|
|
|
// email action changes to sms action
|
2023-01-18 14:32:39 +00:00
|
|
|
if (!isSMSAction(oldValue)) {
|
2022-11-25 14:34:55 +00:00
|
|
|
form.setValue(`steps.${step.stepNumber - 1}.reminderBody`, "");
|
2023-01-18 14:32:39 +00:00
|
|
|
form.setValue(`steps.${step.stepNumber - 1}.sender`, SENDER_ID);
|
2022-11-25 14:34:55 +00:00
|
|
|
}
|
2023-04-18 10:08:09 +00:00
|
|
|
|
2023-07-11 15:48:44 +00:00
|
|
|
setIsEmailSubjectNeeded(false);
|
|
|
|
} else if (isWhatsappAction(val.value)) {
|
|
|
|
setNumberRequiredConfigs(val.value === WorkflowActions.WHATSAPP_NUMBER, false);
|
|
|
|
|
|
|
|
if (!isWhatsappAction(oldValue)) {
|
|
|
|
form.setValue(`steps.${step.stepNumber - 1}.reminderBody`, "");
|
|
|
|
form.setValue(`steps.${step.stepNumber - 1}.sender`, "");
|
|
|
|
}
|
|
|
|
|
2023-04-18 10:08:09 +00:00
|
|
|
setIsEmailSubjectNeeded(false);
|
2022-07-14 00:10:45 +00:00
|
|
|
} else {
|
|
|
|
setIsPhoneNumberNeeded(false);
|
2023-07-11 15:48:44 +00:00
|
|
|
setIsSenderIsNeeded(false);
|
2022-11-25 14:34:55 +00:00
|
|
|
setIsEmailAddressNeeded(val.value === WorkflowActions.EMAIL_ADDRESS);
|
2023-04-18 10:08:09 +00:00
|
|
|
setIsEmailSubjectNeeded(true);
|
2022-07-14 00:10:45 +00:00
|
|
|
}
|
2022-11-25 14:34:55 +00:00
|
|
|
|
2023-08-10 18:52:36 +00:00
|
|
|
if (isTextMessageToAttendeeAction(val.value)) {
|
|
|
|
setIsRequiresConfirmationNeeded(true);
|
|
|
|
} else {
|
|
|
|
setIsRequiresConfirmationNeeded(false);
|
|
|
|
}
|
|
|
|
|
2022-07-14 00:10:45 +00:00
|
|
|
if (
|
2023-04-18 10:08:09 +00:00
|
|
|
form.getValues(`steps.${step.stepNumber - 1}.template`) ===
|
|
|
|
WorkflowTemplates.REMINDER
|
2022-07-14 00:10:45 +00:00
|
|
|
) {
|
2023-07-11 15:48:44 +00:00
|
|
|
if (isSMSOrWhatsappAction(val.value) === isSMSOrWhatsappAction(oldValue)) {
|
2023-04-18 10:08:09 +00:00
|
|
|
if (isAttendeeAction(oldValue) !== isAttendeeAction(val.value)) {
|
|
|
|
const currentReminderBody =
|
|
|
|
form.getValues(`steps.${step.stepNumber - 1}.reminderBody`) || "";
|
|
|
|
const newReminderBody = currentReminderBody
|
|
|
|
.replaceAll("{ORGANIZER}", "{PLACEHOLDER}")
|
|
|
|
.replaceAll("{ATTENDEE}", "{ORGANIZER}")
|
|
|
|
.replaceAll("{PLACEHOLDER}", "{ATTENDEE}");
|
|
|
|
form.setValue(`steps.${step.stepNumber - 1}.reminderBody`, newReminderBody);
|
|
|
|
|
2023-07-11 15:48:44 +00:00
|
|
|
if (!isSMSOrWhatsappAction(val.value)) {
|
2023-04-18 10:08:09 +00:00
|
|
|
const currentEmailSubject =
|
|
|
|
form.getValues(`steps.${step.stepNumber - 1}.emailSubject`) || "";
|
|
|
|
const newEmailSubject = isAttendeeAction(val.value)
|
|
|
|
? currentEmailSubject.replace("{ORGANIZER}", "{ATTENDEE}")
|
|
|
|
: currentEmailSubject.replace("{ATTENDEE}", "{ORGANIZER}");
|
|
|
|
|
|
|
|
form.setValue(
|
|
|
|
`steps.${step.stepNumber - 1}.emailSubject`,
|
|
|
|
newEmailSubject || ""
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (isSMSAction(val.value)) {
|
|
|
|
form.setValue(
|
|
|
|
`steps.${step.stepNumber - 1}.reminderBody`,
|
2023-07-19 14:30:37 +00:00
|
|
|
smsReminderTemplate(true, val.value, timeFormat)
|
2023-04-18 10:08:09 +00:00
|
|
|
);
|
2023-07-11 15:48:44 +00:00
|
|
|
} else if (isWhatsappAction(val.value)) {
|
|
|
|
form.setValue(
|
|
|
|
`steps.${step.stepNumber - 1}.reminderBody`,
|
2023-07-19 14:30:37 +00:00
|
|
|
whatsappReminderTemplate(true, val.value, timeFormat)
|
2023-07-11 15:48:44 +00:00
|
|
|
);
|
2023-04-18 10:08:09 +00:00
|
|
|
} else {
|
2023-07-19 14:30:37 +00:00
|
|
|
const emailReminderBody = emailReminderTemplate(
|
|
|
|
true,
|
|
|
|
val.value,
|
|
|
|
timeFormat
|
|
|
|
);
|
2023-04-18 10:08:09 +00:00
|
|
|
form.setValue(
|
|
|
|
`steps.${step.stepNumber - 1}.reminderBody`,
|
|
|
|
emailReminderBody.emailBody
|
|
|
|
);
|
|
|
|
form.setValue(
|
|
|
|
`steps.${step.stepNumber - 1}.emailSubject`,
|
|
|
|
emailReminderBody.emailSubject
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2023-07-11 15:48:44 +00:00
|
|
|
} else {
|
|
|
|
const template = isWhatsappAction(val.value) ? "REMINDER" : "CUSTOM";
|
|
|
|
template && form.setValue(`steps.${step.stepNumber - 1}.template`, template);
|
2022-07-14 00:10:45 +00:00
|
|
|
}
|
2023-04-18 10:08:09 +00:00
|
|
|
form.unregister(`steps.${step.stepNumber - 1}.sendTo`);
|
|
|
|
form.clearErrors(`steps.${step.stepNumber - 1}.sendTo`);
|
2022-07-14 00:10:45 +00:00
|
|
|
form.setValue(`steps.${step.stepNumber - 1}.action`, val.value);
|
2023-04-18 10:08:09 +00:00
|
|
|
setUpdateTemplate(!updateTemplate);
|
2022-07-14 00:10:45 +00:00
|
|
|
}
|
|
|
|
}}
|
|
|
|
defaultValue={selectedAction}
|
2023-08-10 18:52:36 +00:00
|
|
|
options={actionOptions?.map((option) => ({
|
|
|
|
...option,
|
|
|
|
verificationAction: () => props.setKYCVerificationDialogOpen(true),
|
|
|
|
}))}
|
2022-12-15 00:11:57 +00:00
|
|
|
isOptionDisabled={(option: {
|
|
|
|
label: string;
|
|
|
|
value: WorkflowActions;
|
2023-01-11 18:41:45 +00:00
|
|
|
needsUpgrade: boolean;
|
2023-08-10 18:52:36 +00:00
|
|
|
needsVerification: boolean;
|
|
|
|
}) => option.needsUpgrade || option.needsVerification}
|
2022-07-14 00:10:45 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
/>
|
2023-08-10 18:52:36 +00:00
|
|
|
{isRequiresConfirmationNeeded ? (
|
|
|
|
<div className="text-attention mb-3 mt-2 flex">
|
|
|
|
<Info className="mr-1 mt-0.5 h-4 w-4" />
|
|
|
|
<p className="text-sm">{t("requires_confirmation_mandatory")}</p>
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<></>
|
|
|
|
)}
|
2022-07-14 00:10:45 +00:00
|
|
|
</div>
|
2023-02-20 17:40:08 +00:00
|
|
|
{isPhoneNumberNeeded && (
|
2023-07-18 20:27:54 +00:00
|
|
|
<div className="bg-muted mt-2 rounded-md p-4 pt-0">
|
2023-02-20 17:40:08 +00:00
|
|
|
<Label className="pt-4">{t("custom_phone_number")}</Label>
|
|
|
|
<div className="block sm:flex">
|
2023-03-02 18:15:28 +00:00
|
|
|
<Controller
|
2023-02-20 17:40:08 +00:00
|
|
|
name={`steps.${step.stepNumber - 1}.sendTo`}
|
2023-03-02 18:15:28 +00:00
|
|
|
render={({ field: { value, onChange } }) => (
|
|
|
|
<PhoneInput
|
|
|
|
placeholder={t("phone_number")}
|
|
|
|
id={`steps.${step.stepNumber - 1}.sendTo`}
|
2023-06-22 22:25:37 +00:00
|
|
|
className="min-w-fit sm:rounded-r-none sm:rounded-bl-md sm:rounded-tl-md"
|
2023-03-02 18:15:28 +00:00
|
|
|
required
|
2023-05-15 13:56:26 +00:00
|
|
|
disabled={props.readOnly}
|
2023-03-02 18:15:28 +00:00
|
|
|
value={value}
|
|
|
|
onChange={(val) => {
|
|
|
|
const isAlreadyVerified = !!verifiedNumbers
|
|
|
|
?.concat([])
|
2023-04-03 09:25:20 +00:00
|
|
|
.find((number) => number.replace(/\s/g, "") === val?.replace(/\s/g, ""));
|
2023-03-02 18:15:28 +00:00
|
|
|
setNumberVerified(isAlreadyVerified);
|
|
|
|
onChange(val);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)}
|
2023-02-20 17:40:08 +00:00
|
|
|
/>
|
|
|
|
<Button
|
|
|
|
color="secondary"
|
2023-05-15 13:56:26 +00:00
|
|
|
disabled={numberVerified || props.readOnly || false}
|
2023-02-20 17:40:08 +00:00
|
|
|
className={classNames(
|
2023-06-22 22:25:37 +00:00
|
|
|
"-ml-[3px] h-[40px] min-w-fit sm:block sm:rounded-bl-none sm:rounded-tl-none",
|
2023-02-20 17:40:08 +00:00
|
|
|
numberVerified ? "hidden" : "mt-3 sm:mt-0"
|
|
|
|
)}
|
|
|
|
onClick={() =>
|
|
|
|
sendVerificationCodeMutation.mutate({
|
|
|
|
phoneNumber: form.getValues(`steps.${step.stepNumber - 1}.sendTo`) || "",
|
|
|
|
})
|
|
|
|
}>
|
|
|
|
{t("send_code")}
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
{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>
|
|
|
|
)}
|
|
|
|
{numberVerified ? (
|
|
|
|
<div className="mt-1">
|
|
|
|
<Badge variant="green">{t("number_verified")}</Badge>
|
|
|
|
</div>
|
|
|
|
) : (
|
2023-05-15 13:56:26 +00:00
|
|
|
!props.readOnly && (
|
|
|
|
<>
|
2023-07-18 20:27:54 +00:00
|
|
|
<div className="mt-3 flex">
|
2023-05-15 13:56:26 +00:00
|
|
|
<TextField
|
|
|
|
className="rounded-r-none border-r-transparent"
|
|
|
|
placeholder="Verification code"
|
|
|
|
disabled={props.readOnly}
|
|
|
|
value={verificationCode}
|
|
|
|
onChange={(e) => {
|
|
|
|
setVerificationCode(e.target.value);
|
|
|
|
}}
|
|
|
|
required
|
|
|
|
/>
|
|
|
|
<Button
|
|
|
|
color="secondary"
|
2023-06-22 22:25:37 +00:00
|
|
|
className="-ml-[3px] h-[38px] min-w-fit sm:block sm:rounded-bl-none sm:rounded-tl-none "
|
2023-05-15 13:56:26 +00:00
|
|
|
disabled={verifyPhoneNumberMutation.isLoading || props.readOnly}
|
|
|
|
onClick={() => {
|
|
|
|
verifyPhoneNumberMutation.mutate({
|
|
|
|
phoneNumber: form.getValues(`steps.${step.stepNumber - 1}.sendTo`) || "",
|
|
|
|
code: verificationCode,
|
|
|
|
teamId,
|
|
|
|
});
|
|
|
|
}}>
|
|
|
|
{t("verify")}
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
{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>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
)
|
2022-11-23 02:55:25 +00:00
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
)}
|
2023-07-18 20:27:54 +00:00
|
|
|
{!isWhatsappAction(form.getValues(`steps.${step.stepNumber - 1}.action`)) && (
|
|
|
|
<div className="bg-muted mt-2 rounded-md p-4 pt-0">
|
|
|
|
{isSenderIsNeeded ? (
|
|
|
|
<>
|
|
|
|
<div className="pt-4">
|
|
|
|
<div className="flex">
|
|
|
|
<Label>{t("sender_id")}</Label>
|
|
|
|
<Tooltip content={t("sender_id_info")}>
|
|
|
|
<Info className="ml-2 mr-1 mt-0.5 h-4 w-4 text-gray-500" />
|
|
|
|
</Tooltip>
|
|
|
|
</div>
|
|
|
|
<Input
|
|
|
|
type="text"
|
|
|
|
placeholder={SENDER_ID}
|
|
|
|
disabled={props.readOnly}
|
|
|
|
maxLength={11}
|
|
|
|
{...form.register(`steps.${step.stepNumber - 1}.sender`)}
|
|
|
|
/>
|
2023-06-11 03:20:13 +00:00
|
|
|
</div>
|
2023-07-18 20:27:54 +00:00
|
|
|
{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>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
<div className="pt-4">
|
|
|
|
<Label>{t("sender_name")}</Label>
|
|
|
|
<Input
|
|
|
|
type="text"
|
|
|
|
disabled={props.readOnly}
|
|
|
|
placeholder={SENDER_NAME}
|
|
|
|
{...form.register(`steps.${step.stepNumber - 1}.senderName`)}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
)}
|
2023-07-11 15:48:44 +00:00
|
|
|
{canRequirePhoneNumber(form.getValues(`steps.${step.stepNumber - 1}.action`)) && (
|
2022-11-23 02:55:25 +00:00
|
|
|
<div className="mt-2">
|
|
|
|
<Controller
|
|
|
|
name={`steps.${step.stepNumber - 1}.numberRequired`}
|
|
|
|
control={form.control}
|
|
|
|
render={() => (
|
2023-07-19 19:45:13 +00:00
|
|
|
<CheckboxField
|
2023-05-15 13:56:26 +00:00
|
|
|
disabled={props.readOnly}
|
2022-11-23 02:55:25 +00:00
|
|
|
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 && (
|
2023-07-18 20:27:54 +00:00
|
|
|
<div className="bg-muted mt-5 rounded-md p-4">
|
2022-11-23 02:55:25 +00:00
|
|
|
<EmailField
|
|
|
|
required
|
2023-05-15 13:56:26 +00:00
|
|
|
disabled={props.readOnly}
|
2022-11-23 02:55:25 +00:00
|
|
|
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}
|
2023-07-11 15:48:44 +00:00
|
|
|
render={({ field }) => {
|
2022-07-14 00:10:45 +00:00
|
|
|
return (
|
|
|
|
<Select
|
|
|
|
isSearchable={false}
|
2022-11-23 02:55:25 +00:00
|
|
|
className="text-sm"
|
2023-05-15 13:56:26 +00:00
|
|
|
isDisabled={props.readOnly}
|
2022-07-14 00:10:45 +00:00
|
|
|
onChange={(val) => {
|
|
|
|
if (val) {
|
2023-07-18 20:27:54 +00:00
|
|
|
const action = form.getValues(`steps.${step.stepNumber - 1}.action`);
|
2023-04-18 10:08:09 +00:00
|
|
|
if (val.value === WorkflowTemplates.REMINDER) {
|
2023-07-11 15:48:44 +00:00
|
|
|
if (isWhatsappAction(action)) {
|
2023-04-18 10:08:09 +00:00
|
|
|
form.setValue(
|
|
|
|
`steps.${step.stepNumber - 1}.reminderBody`,
|
2023-07-19 14:30:37 +00:00
|
|
|
whatsappReminderTemplate(true, action, timeFormat)
|
2023-04-18 10:08:09 +00:00
|
|
|
);
|
2023-07-11 15:48:44 +00:00
|
|
|
} else if (isSMSAction(action)) {
|
|
|
|
form.setValue(
|
|
|
|
`steps.${step.stepNumber - 1}.reminderBody`,
|
2023-07-19 14:30:37 +00:00
|
|
|
smsReminderTemplate(true, action, timeFormat)
|
2023-07-11 15:48:44 +00:00
|
|
|
);
|
2023-04-18 10:08:09 +00:00
|
|
|
} else {
|
|
|
|
form.setValue(
|
|
|
|
`steps.${step.stepNumber - 1}.reminderBody`,
|
2023-07-19 14:30:37 +00:00
|
|
|
emailReminderTemplate(true, action, timeFormat).emailBody
|
2023-04-18 10:08:09 +00:00
|
|
|
);
|
|
|
|
form.setValue(
|
|
|
|
`steps.${step.stepNumber - 1}.emailSubject`,
|
2023-07-19 14:30:37 +00:00
|
|
|
emailReminderTemplate(true, action, timeFormat).emailSubject
|
2023-04-18 10:08:09 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
} else {
|
2023-07-11 15:48:44 +00:00
|
|
|
if (isWhatsappAction(action)) {
|
2023-07-18 20:27:54 +00:00
|
|
|
form.setValue(
|
|
|
|
`steps.${step.stepNumber - 1}.reminderBody`,
|
2023-07-19 14:30:37 +00:00
|
|
|
getWhatsappTemplateForAction(action, val.value, timeFormat)
|
2023-07-18 20:27:54 +00:00
|
|
|
);
|
2023-07-11 15:48:44 +00:00
|
|
|
} else {
|
|
|
|
form.setValue(`steps.${step.stepNumber - 1}.reminderBody`, "");
|
|
|
|
form.setValue(`steps.${step.stepNumber - 1}.emailSubject`, "");
|
|
|
|
}
|
2023-04-18 10:08:09 +00:00
|
|
|
}
|
2023-07-18 20:27:54 +00:00
|
|
|
field.onChange(val.value);
|
2022-07-14 00:10:45 +00:00
|
|
|
form.setValue(`steps.${step.stepNumber - 1}.template`, val.value);
|
2023-04-18 10:08:09 +00:00
|
|
|
setUpdateTemplate(!updateTemplate);
|
2022-07-14 00:10:45 +00:00
|
|
|
}
|
|
|
|
}}
|
|
|
|
defaultValue={selectedTemplate}
|
2023-07-11 15:48:44 +00:00
|
|
|
value={selectedTemplate}
|
2022-07-14 00:10:45 +00:00
|
|
|
options={templateOptions}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
2023-07-18 20:27:54 +00:00
|
|
|
<div className="bg-muted mt-2 rounded-md pt-2 md:p-6 md:pt-4">
|
2023-04-18 10:08:09 +00:00
|
|
|
{isEmailSubjectNeeded && (
|
|
|
|
<div className="mb-6">
|
|
|
|
<div className="flex items-center">
|
2023-05-15 13:56:26 +00:00
|
|
|
<Label className={classNames("flex-none", props.readOnly ? "mb-2" : "mb-0")}>
|
2023-06-08 13:37:54 +00:00
|
|
|
{t("email_subject")}
|
2023-05-15 13:56:26 +00:00
|
|
|
</Label>
|
|
|
|
{!props.readOnly && (
|
|
|
|
<div className="flex-grow text-right">
|
|
|
|
<AddVariablesDropdown
|
|
|
|
addVariable={addVariableEmailSubject}
|
|
|
|
variables={DYNAMIC_TEXT_VARIABLES}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
2022-07-14 00:10:45 +00:00
|
|
|
</div>
|
2023-04-18 10:08:09 +00:00
|
|
|
<TextArea
|
|
|
|
ref={(e) => {
|
|
|
|
emailSubjectFormRef?.(e);
|
|
|
|
refEmailSubject.current = e;
|
|
|
|
}}
|
|
|
|
rows={1}
|
2023-05-15 13:56:26 +00:00
|
|
|
disabled={props.readOnly}
|
2023-04-18 10:08:09 +00:00
|
|
|
className="my-0 focus:ring-transparent"
|
|
|
|
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>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
)}
|
2022-11-25 14:34:55 +00:00
|
|
|
|
2023-04-18 10:08:09 +00:00
|
|
|
{step.action !== WorkflowActions.SMS_ATTENDEE &&
|
|
|
|
step.action !== WorkflowActions.SMS_NUMBER ? (
|
|
|
|
<>
|
|
|
|
<div className="mb-2 flex items-center pb-[1.5px]">
|
2023-07-18 20:27:54 +00:00
|
|
|
<Label className="mb-0 flex-none ">
|
2023-04-18 10:08:09 +00:00
|
|
|
{isEmailSubjectNeeded ? t("email_body") : t("text_message")}
|
|
|
|
</Label>
|
|
|
|
</div>
|
|
|
|
<Editor
|
|
|
|
getText={() => {
|
|
|
|
return props.form.getValues(`steps.${step.stepNumber - 1}.reminderBody`) || "";
|
|
|
|
}}
|
|
|
|
setText={(text: string) => {
|
|
|
|
props.form.setValue(`steps.${step.stepNumber - 1}.reminderBody`, text);
|
|
|
|
props.form.clearErrors();
|
|
|
|
}}
|
|
|
|
variables={DYNAMIC_TEXT_VARIABLES}
|
|
|
|
height="200px"
|
|
|
|
updateTemplate={updateTemplate}
|
|
|
|
firstRender={firstRender}
|
|
|
|
setFirstRender={setFirstRender}
|
2023-07-11 15:48:44 +00:00
|
|
|
editable={!props.readOnly && !isWhatsappAction(step.action)}
|
2023-04-18 10:08:09 +00:00
|
|
|
/>
|
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
<div className="flex items-center">
|
2023-05-15 13:56:26 +00:00
|
|
|
<Label className={classNames("flex-none", props.readOnly ? "mb-2" : "mb-0")}>
|
2023-04-18 10:08:09 +00:00
|
|
|
{isEmailSubjectNeeded ? t("email_body") : t("text_message")}
|
|
|
|
</Label>
|
2023-05-15 13:56:26 +00:00
|
|
|
{!props.readOnly && (
|
|
|
|
<div className="flex-grow text-right">
|
|
|
|
<AddVariablesDropdown
|
|
|
|
addVariable={addVariableBody}
|
|
|
|
variables={DYNAMIC_TEXT_VARIABLES}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
2023-04-18 10:08:09 +00:00
|
|
|
</div>
|
|
|
|
<TextArea
|
|
|
|
ref={(e) => {
|
|
|
|
reminderBodyFormRef?.(e);
|
|
|
|
refReminderBody.current = e;
|
|
|
|
}}
|
2023-07-18 20:27:54 +00:00
|
|
|
className="my-0 h-24"
|
2023-05-15 13:56:26 +00:00
|
|
|
disabled={props.readOnly}
|
2023-04-18 10:08:09 +00:00
|
|
|
required
|
|
|
|
{...restReminderBodyForm}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
{form.formState.errors.steps &&
|
|
|
|
form.formState?.errors?.steps[step.stepNumber - 1]?.reminderBody && (
|
|
|
|
<p className="mt-1 text-sm text-red-500">
|
|
|
|
{form.formState?.errors?.steps[step.stepNumber - 1]?.reminderBody?.message || ""}
|
|
|
|
</p>
|
2022-11-25 14:34:55 +00:00
|
|
|
)}
|
2023-05-15 13:56:26 +00:00
|
|
|
{!props.readOnly && (
|
|
|
|
<div className="mt-3 ">
|
|
|
|
<button type="button" onClick={() => setIsAdditionalInputsDialogOpen(true)}>
|
2023-07-18 20:27:54 +00:00
|
|
|
<div className="text-default mt-2 flex text-sm">
|
2023-05-15 13:56:26 +00:00
|
|
|
<HelpCircle className="mt-[3px] h-3 w-3 ltr:mr-2 rtl:ml-2" />
|
|
|
|
<p className="text-left">{t("using_booking_questions_as_variables")}</p>
|
|
|
|
</div>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
)}
|
2023-04-18 10:08:09 +00:00
|
|
|
</div>
|
|
|
|
|
2023-01-12 16:03:30 +00:00
|
|
|
{/* {form.getValues(`steps.${step.stepNumber - 1}.action`) !== WorkflowActions.SMS_ATTENDEE && (
|
2022-08-26 01:04:44 +00:00
|
|
|
<Button
|
|
|
|
type="button"
|
2023-01-12 16:03:30 +00:00
|
|
|
className="w-full mt-7"
|
2022-08-26 01:04:44 +00:00
|
|
|
onClick={() => {
|
2022-11-23 02:55:25 +00:00
|
|
|
let isEmpty = false;
|
2022-12-15 21:54:40 +00:00
|
|
|
|
2022-11-23 02:55:25 +00:00
|
|
|
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-12-15 21:54:40 +00:00
|
|
|
|
|
|
|
if (!numberVerified && isPhoneNumberNeeded) {
|
|
|
|
form.setError(`steps.${step.stepNumber - 1}.sendTo`, {
|
|
|
|
type: "custom",
|
|
|
|
message: t("not_verified"),
|
|
|
|
});
|
|
|
|
}
|
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({
|
2022-12-15 20:48:22 +00:00
|
|
|
step,
|
2022-11-23 02:55:25 +00:00
|
|
|
emailSubject,
|
|
|
|
reminderBody,
|
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;
|
|
|
|
|
2022-12-15 21:54:40 +00:00
|
|
|
if (isPhoneNumberNeeded && isNumberValid && !isEmpty && numberVerified) {
|
2022-11-23 02:55:25 +00:00
|
|
|
setConfirmationDialogOpen(true);
|
|
|
|
}
|
2022-08-26 01:04:44 +00:00
|
|
|
}
|
|
|
|
}}
|
|
|
|
color="secondary">
|
|
|
|
<div className="w-full">{t("test_action")}</div>
|
|
|
|
</Button>
|
2023-01-12 16:03:30 +00:00
|
|
|
)*/}
|
2022-07-14 00:10:45 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-01-12 16:03:30 +00:00
|
|
|
{/* <Dialog open={confirmationDialogOpen} onOpenChange={setConfirmationDialogOpen}>
|
2022-08-26 01:04:44 +00:00
|
|
|
<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({
|
2022-12-15 20:48:22 +00:00
|
|
|
step,
|
2022-11-23 02:55:25 +00:00
|
|
|
emailSubject: "",
|
|
|
|
reminderBody: reminderBody || "",
|
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>
|
2023-01-12 16:03:30 +00:00
|
|
|
</Dialog> */}
|
2022-11-23 02:55:25 +00:00
|
|
|
<Dialog open={isAdditionalInputsDialogOpen} onOpenChange={setIsAdditionalInputsDialogOpen}>
|
2023-07-21 08:46:16 +00:00
|
|
|
<DialogContent enableOverflow type="creation" className="sm:max-w-[610px]">
|
|
|
|
<div>
|
2023-04-18 10:08:09 +00:00
|
|
|
<h1 className="w-full text-xl font-semibold ">{t("how_booking_questions_as_variables")}</h1>
|
2023-07-18 20:27:54 +00:00
|
|
|
<div className="bg-muted-3 mb-6 rounded-md sm:p-4">
|
|
|
|
<p className="test-sm font-medium">{t("format")}</p>
|
|
|
|
<ul className="text-emphasis ml-5 mt-2 list-disc">
|
2022-11-23 02:55:25 +00:00
|
|
|
<li>{t("uppercase_for_letters")}</li>
|
|
|
|
<li>{t("replace_whitespaces_underscores")}</li>
|
2023-04-18 10:08:09 +00:00
|
|
|
<li>{t("ignore_special_characters_booking_questions")}</li>
|
2022-11-23 02:55:25 +00:00
|
|
|
</ul>
|
2023-06-29 07:47:16 +00:00
|
|
|
<div className="mt-4">
|
2023-07-18 20:27:54 +00:00
|
|
|
<p className="test-sm w-full font-medium">{t("example_1")}</p>
|
|
|
|
<div className="mt-2 grid grid-cols-12">
|
|
|
|
<div className="test-sm text-default col-span-5 ltr:mr-2 rtl:ml-2">
|
2023-04-18 10:08:09 +00:00
|
|
|
{t("booking_question_identifier")}
|
2023-01-04 07:38:45 +00:00
|
|
|
</div>
|
2023-07-18 20:27:54 +00:00
|
|
|
<div className="test-sm text-emphasis col-span-7">{t("company_size")}</div>
|
|
|
|
<div className="test-sm text-default col-span-5 w-full">{t("variable")}</div>
|
2022-11-23 02:55:25 +00:00
|
|
|
|
2023-07-18 20:27:54 +00:00
|
|
|
<div className="test-sm text-emphasis col-span-7 break-words">
|
2022-11-23 02:55:25 +00:00
|
|
|
{" "}
|
|
|
|
{`{${t("company_size")
|
|
|
|
.replace(/[^a-zA-Z0-9 ]/g, "")
|
|
|
|
.trim()
|
|
|
|
.replace(/ /g, "_")
|
|
|
|
.toUpperCase()}}`}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-06-29 07:47:16 +00:00
|
|
|
<div className="mt-4">
|
2023-07-18 20:27:54 +00:00
|
|
|
<p className="test-sm w-full font-medium">{t("example_2")}</p>
|
|
|
|
<div className="mt-2 grid grid-cols-12">
|
|
|
|
<div className="test-sm text-default col-span-5 ltr:mr-2 rtl:ml-2">
|
2023-04-18 10:08:09 +00:00
|
|
|
{t("booking_question_identifier")}
|
2023-01-04 07:38:45 +00:00
|
|
|
</div>
|
2023-07-18 20:27:54 +00:00
|
|
|
<div className="test-sm text-emphasis col-span-7">{t("what_help_needed")}</div>
|
|
|
|
<div className="test-sm text-default col-span-5">{t("variable")}</div>
|
|
|
|
<div className="test-sm text-emphasis col-span-7 break-words">
|
2022-11-23 02:55:25 +00:00
|
|
|
{" "}
|
|
|
|
{`{${t("what_help_needed")
|
|
|
|
.replace(/[^a-zA-Z0-9 ]/g, "")
|
|
|
|
.trim()
|
|
|
|
.replace(/ /g, "_")
|
|
|
|
.toUpperCase()}}`}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-07-21 08:46:16 +00:00
|
|
|
<DialogFooter showDivider>
|
2022-11-28 19:14:38 +00:00
|
|
|
<DialogClose color="primary" />
|
2023-06-29 07:47:16 +00:00
|
|
|
</DialogFooter>
|
2022-11-23 02:55:25 +00:00
|
|
|
</DialogContent>
|
|
|
|
</Dialog>
|
2022-07-14 00:10:45 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return <></>;
|
|
|
|
}
|