import { DotsHorizontalIcon, TrashIcon } from "@heroicons/react/solid"; import { TimeUnit, WorkflowStep, WorkflowTriggerEvents, WorkflowActions, WorkflowTemplates, } from "@prisma/client"; import { isValidPhoneNumber } from "libphonenumber-js"; import { Dispatch, SetStateAction, useState } from "react"; import { Controller, UseFormReturn } from "react-hook-form"; import PhoneInput from "react-phone-number-input"; import { Button } from "@calcom/ui"; import Dropdown, { DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@calcom/ui/Dropdown"; import Select from "@calcom/ui/form/Select"; import { TextField, TextArea } from "@calcom/ui/form/fields"; import { getWorkflowActionOptions, getWorkflowTemplateOptions, getWorkflowTimeUnitOptions, getWorkflowTriggerOptions, } from "@ee/lib/workflows/getOptions"; import { FormValues } from "@ee/pages/workflows/[workflow]"; import classNames from "@lib/classNames"; import { useLocale } from "@lib/hooks/useLocale"; type WorkflowStepProps = { step?: WorkflowStep; form: UseFormReturn; reload?: boolean; setReload?: Dispatch>; editCounter: number; setEditCounter: Dispatch>; }; export default function WorkflowStepContainer(props: WorkflowStepProps) { const { t } = useLocale(); const { step, form, reload, setReload, editCounter, setEditCounter } = props; const [editNumberMode, setEditNumberMode] = useState( step?.action === WorkflowActions.SMS_NUMBER && !step?.sendTo ? true : false ); const [editEmailBodyMode, setEditEmailBodyMode] = useState(false); const [sendTo, setSendTo] = useState(step?.sendTo || ""); const [errorMessageNumber, setErrorMessageNumber] = useState(""); const [errorMessageCustomInput, setErrorMessageCustomInput] = useState(""); const [isPhoneNumberNeeded, setIsPhoneNumberNeeded] = useState( step?.action === WorkflowActions.SMS_NUMBER ? true : false ); const [isCustomReminderBodyNeeded, setIsCustomReminderBodyNeeded] = useState( step?.template === WorkflowTemplates.CUSTOM ? true : false ); const [isEmailSubjectNeeded, setIsEmailSubjectNeeded] = useState( step?.action === WorkflowActions.EMAIL_ATTENDEE || step?.action === WorkflowActions.EMAIL_HOST ? true : false ); const [showTimeSection, setShowTimeSection] = useState( form.getValues("trigger") === WorkflowTriggerEvents.BEFORE_EVENT ? true : false ); const actionOptions = getWorkflowActionOptions(t); const triggerOptions = getWorkflowTriggerOptions(t); const timeUnitOptions = getWorkflowTimeUnitOptions(t); const templateOptions = getWorkflowTemplateOptions(t); //trigger if (!step) { const trigger = form.getValues("trigger"); const timeUnit = form.getValues("timeUnit"); const selectedTrigger = { label: t(`${trigger.toLowerCase()}_trigger`), value: trigger }; const selectedTimeUnit = timeUnit ? { label: t(`${timeUnit.toLowerCase()}_timeUnit`), value: timeUnit } : undefined; return ( <>
{t("triggers")}:
{ return (
{ return ( { if (val) { if (val.value === WorkflowActions.SMS_NUMBER) { setIsPhoneNumberNeeded(true); setEditNumberMode(true); setEditCounter(editCounter + 1); } else { setIsPhoneNumberNeeded(false); setEditNumberMode(false); setEditCounter(editCounter - 1); } if ( val.value === WorkflowActions.EMAIL_ATTENDEE || val.value === WorkflowActions.EMAIL_HOST ) { setIsEmailSubjectNeeded(true); if (!form.getValues(`steps.${step.stepNumber - 1}.emailSubject`)) { setEditEmailBodyMode(true); setEditCounter(editCounter + 1); } } else { setIsEmailSubjectNeeded(false); } form.setValue(`steps.${step.stepNumber - 1}.action`, val.value); setErrorMessageNumber(""); setErrorMessageCustomInput(""); } }} defaultValue={selectedAction} options={actionOptions} /> ); }} /> {form.getValues(`steps.${step.stepNumber - 1}.action`) === WorkflowActions.SMS_ATTENDEE && (

{t("not_triggering_existing_bookings")}

)}
{isPhoneNumberNeeded && ( <>
{ if (newValue) { setSendTo(newValue); setErrorMessageNumber(""); } }} placeholder={t("enter_phone_number")} id="sendTo" disabled={!editNumberMode} required countrySelectProps={{ className: "text-black" }} numberInputProps={{ className: "border-0 text-sm focus:ring-0 dark:bg-gray-700" }} className={classNames( "border-1 focus-within:border-brand block w-full rounded-sm border border-gray-300 py-px pl-3 shadow-sm ring-black focus-within:ring-1 disabled:text-gray-500 disabled:opacity-50 dark:border-gray-900 dark:bg-gray-700 dark:text-white dark:selection:bg-green-500 disabled:dark:text-gray-500", !editNumberMode ? "text-gray-500 dark:text-gray-500" : "" )} />
{!editNumberMode ? ( ) : ( )}
{errorMessageNumber &&

{errorMessageNumber}

} )}
{ return (