🧹 One calcom/ui import to rule them all (#5561)
* Removed emptyscreen component v1 version, migrated pages that still used it to v2, and removed v1 of workflow pages and components. * updated workflow pages imports to remove v2 from path. * Deleted v1 switch component, deleted v1 api-keys components, deleted old web integrations components that were unused. * Removed v1 list component. * Fixed event workflows tab path. * Fixed import path for button in sandbox page. * Cleanup and type fixes * Making explicit indexes * UI import migrations * More import fixes * More import fixes * Submodule sync * Type fixes * Build fixes Co-authored-by: zomars <[email protected]>
This commit is contained in:
1 parent
a36b46bd81
commit
ccc2bdd25e
325 files changed
+2152
-5271
No files matched your search
@@ -1,8 +1,3 @@
|
||||
/**
|
||||
* @deprecated file
|
||||
* All new changes should be made to the V2 file in
|
||||
* `/packages/features/ee/workflows/components/v2/AddActionDialog.tsx`
|
||||
*/
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { WorkflowActions } from "@prisma/client";
|
||||
import { isValidPhoneNumber } from "libphonenumber-js";
|
||||
@@ -11,72 +6,127 @@ import { Controller, useForm } from "react-hook-form";
|
||||
import { z } from "zod";
|
||||
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import Button from "@calcom/ui/Button";
|
||||
import { Dialog, DialogClose, DialogContent, DialogFooter, DialogHeader } from "@calcom/ui/Dialog";
|
||||
import PhoneInput from "@calcom/ui/form/PhoneInputLazy";
|
||||
import Select from "@calcom/ui/form/Select";
|
||||
import { Form } from "@calcom/ui/form/fields";
|
||||
import {
|
||||
Button,
|
||||
Checkbox,
|
||||
Dialog,
|
||||
DialogClose,
|
||||
DialogContent,
|
||||
DialogFooter,
|
||||
EmailField,
|
||||
Form,
|
||||
Label,
|
||||
PhoneInput,
|
||||
Select,
|
||||
TextField,
|
||||
} from "@calcom/ui";
|
||||
|
||||
import { WORKFLOW_ACTIONS } from "../lib/constants";
|
||||
import { getWorkflowActionOptions } from "../lib/getOptions";
|
||||
import { onlyLettersNumbersSpaces } from "../pages/workflow";
|
||||
|
||||
interface IAddActionDialog {
|
||||
isOpenDialog: boolean;
|
||||
setIsOpenDialog: Dispatch<SetStateAction<boolean>>;
|
||||
addAction: (action: WorkflowActions, sendTo?: string) => void;
|
||||
addAction: (action: WorkflowActions, sendTo?: string, numberRequired?: boolean, sender?: string) => void;
|
||||
isFreeUser: boolean;
|
||||
}
|
||||
|
||||
interface ISelectActionOption {
|
||||
label: string;
|
||||
value: WorkflowActions;
|
||||
}
|
||||
|
||||
type AddActionFormValues = {
|
||||
action: WorkflowActions;
|
||||
sendTo?: string;
|
||||
numberRequired?: boolean;
|
||||
sender?: string;
|
||||
};
|
||||
|
||||
const cleanUpActionsForFreeUser = (actions: ISelectActionOption[]) => {
|
||||
return actions.filter(
|
||||
(item) => item.value !== WorkflowActions.SMS_ATTENDEE && item.value !== WorkflowActions.SMS_NUMBER
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* @deprecated file
|
||||
* All new changes should be made to the V2 file in
|
||||
* `/packages/features/ee/workflows/components/v2/AddActionDialog.tsx`
|
||||
*/
|
||||
export const AddActionDialog = (props: IAddActionDialog) => {
|
||||
const { t } = useLocale();
|
||||
const { isOpenDialog, setIsOpenDialog, addAction } = props;
|
||||
const { isOpenDialog, setIsOpenDialog, addAction, isFreeUser } = props;
|
||||
const [isPhoneNumberNeeded, setIsPhoneNumberNeeded] = useState(false);
|
||||
const actionOptions = getWorkflowActionOptions(t);
|
||||
const [isSenderIdNeeded, setIsSenderIdNeeded] = useState(false);
|
||||
const [isEmailAddressNeeded, setIsEmailAddressNeeded] = useState(false);
|
||||
const workflowActions = getWorkflowActionOptions(t);
|
||||
const actionOptions = isFreeUser ? cleanUpActionsForFreeUser(workflowActions) : workflowActions;
|
||||
|
||||
const formSchema = z.object({
|
||||
action: z.enum(WORKFLOW_ACTIONS),
|
||||
sendTo: z
|
||||
.string()
|
||||
.refine((val) => isValidPhoneNumber(val))
|
||||
.refine((val) => isValidPhoneNumber(val) || val.includes("@"))
|
||||
.optional(),
|
||||
numberRequired: z.boolean().optional(),
|
||||
sender: z
|
||||
.string()
|
||||
.refine((val) => onlyLettersNumbersSpaces(val))
|
||||
.nullable(),
|
||||
});
|
||||
|
||||
const form = useForm<AddActionFormValues>({
|
||||
mode: "onSubmit",
|
||||
defaultValues: {
|
||||
action: WorkflowActions.EMAIL_HOST,
|
||||
sender: "Cal",
|
||||
},
|
||||
resolver: zodResolver(formSchema),
|
||||
});
|
||||
|
||||
const handleSelectAction = (newValue: ISelectActionOption | null) => {
|
||||
if (newValue) {
|
||||
form.setValue("action", newValue.value);
|
||||
if (newValue.value === WorkflowActions.SMS_NUMBER) {
|
||||
setIsPhoneNumberNeeded(true);
|
||||
setIsSenderIdNeeded(true);
|
||||
setIsEmailAddressNeeded(false);
|
||||
} else if (newValue.value === WorkflowActions.EMAIL_ADDRESS) {
|
||||
setIsEmailAddressNeeded(true);
|
||||
setIsSenderIdNeeded(false);
|
||||
setIsPhoneNumberNeeded(false);
|
||||
} else if (newValue.value === WorkflowActions.SMS_ATTENDEE) {
|
||||
setIsSenderIdNeeded(true);
|
||||
setIsEmailAddressNeeded(false);
|
||||
setIsPhoneNumberNeeded(false);
|
||||
} else {
|
||||
setIsSenderIdNeeded(false);
|
||||
setIsEmailAddressNeeded(false);
|
||||
setIsPhoneNumberNeeded(false);
|
||||
}
|
||||
form.unregister("sendTo");
|
||||
form.unregister("numberRequired");
|
||||
form.clearErrors("action");
|
||||
form.clearErrors("sendTo");
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={isOpenDialog} onOpenChange={setIsOpenDialog}>
|
||||
<DialogContent>
|
||||
<DialogContent type="creation" useOwnActionButtons={true} title={t("add_action")}>
|
||||
<div className="space-x-3 ">
|
||||
<div className="pt-1">
|
||||
<DialogHeader title={t("add_action")} />
|
||||
<Form
|
||||
form={form}
|
||||
handleSubmit={(values) => {
|
||||
addAction(values.action, values.sendTo);
|
||||
addAction(values.action, values.sendTo, values.numberRequired, values.sender);
|
||||
form.unregister("sendTo");
|
||||
form.unregister("action");
|
||||
form.unregister("numberRequired");
|
||||
setIsOpenDialog(false);
|
||||
setIsPhoneNumberNeeded(false);
|
||||
setIsEmailAddressNeeded(false);
|
||||
setIsSenderIdNeeded(false);
|
||||
}}>
|
||||
<div className="space-y-1">
|
||||
<label htmlFor="label" className="mt-5 block text-sm font-medium text-gray-700">
|
||||
{t("action")}:
|
||||
</label>
|
||||
<div className="mt-5 space-y-1">
|
||||
<Label htmlFor="label">{t("action")}:</Label>
|
||||
<Controller
|
||||
name="action"
|
||||
control={form.control}
|
||||
@@ -84,20 +134,9 @@ export const AddActionDialog = (props: IAddActionDialog) => {
|
||||
return (
|
||||
<Select
|
||||
isSearchable={false}
|
||||
className="block w-full min-w-0 flex-1 rounded-sm text-sm"
|
||||
className="text-sm"
|
||||
defaultValue={actionOptions[0]}
|
||||
onChange={(val) => {
|
||||
if (val) {
|
||||
form.setValue("action", val.value);
|
||||
if (val.value === WorkflowActions.SMS_NUMBER) {
|
||||
setIsPhoneNumberNeeded(true);
|
||||
} else {
|
||||
setIsPhoneNumberNeeded(false);
|
||||
form.unregister("sendTo");
|
||||
}
|
||||
form.clearErrors("action");
|
||||
}
|
||||
}}
|
||||
onChange={handleSelectAction}
|
||||
options={actionOptions}
|
||||
/>
|
||||
);
|
||||
@@ -109,13 +148,12 @@ export const AddActionDialog = (props: IAddActionDialog) => {
|
||||
</div>
|
||||
{isPhoneNumberNeeded && (
|
||||
<div className="mt-5 space-y-1">
|
||||
<label htmlFor="sendTo" className="block text-sm font-medium text-gray-700 dark:text-white">
|
||||
{t("phone_number")}
|
||||
</label>
|
||||
<div className="mt-1">
|
||||
<Label htmlFor="sendTo">{t("phone_number")}</Label>
|
||||
<div className="mt-1 mb-5">
|
||||
<PhoneInput<AddActionFormValues>
|
||||
control={form.control}
|
||||
name="sendTo"
|
||||
className="rounded-md"
|
||||
placeholder={t("enter_phone_number")}
|
||||
id="sendTo"
|
||||
required
|
||||
@@ -126,6 +164,37 @@ export const AddActionDialog = (props: IAddActionDialog) => {
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{isEmailAddressNeeded && (
|
||||
<div className="mt-5">
|
||||
<EmailField required label={t("email_address")} {...form.register("sendTo")} />
|
||||
</div>
|
||||
)}
|
||||
{isSenderIdNeeded && (
|
||||
<div className="mt-5">
|
||||
<TextField
|
||||
label={t("sender_id")}
|
||||
type="text"
|
||||
placeholder="Cal"
|
||||
maxLength={11}
|
||||
{...form.register(`sender`)}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
{form.getValues("action") === WorkflowActions.SMS_ATTENDEE && (
|
||||
<div className="mt-5">
|
||||
<Controller
|
||||
name="numberRequired"
|
||||
control={form.control}
|
||||
render={() => (
|
||||
<Checkbox
|
||||
defaultChecked={form.getValues("numberRequired") || false}
|
||||
description={t("make_phone_number_required")}
|
||||
onChange={(e) => form.setValue("numberRequired", e.target.checked)}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
<DialogFooter>
|
||||
<DialogClose asChild>
|
||||
<Button
|
||||
@@ -134,7 +203,10 @@ export const AddActionDialog = (props: IAddActionDialog) => {
|
||||
setIsOpenDialog(false);
|
||||
form.unregister("sendTo");
|
||||
form.unregister("action");
|
||||
form.unregister("numberRequired");
|
||||
setIsPhoneNumberNeeded(false);
|
||||
setIsEmailAddressNeeded(false);
|
||||
setIsSenderIdNeeded(false);
|
||||
}}>
|
||||
{t("cancel")}
|
||||
</Button>
|
||||
|
||||
@@ -1,58 +1,57 @@
|
||||
/**
|
||||
* @deprecated file
|
||||
* All new changes should be made to the V2 file in
|
||||
* `/packages/features/ee/workflows/components/v2/AddVariablesDropdown.tsx`
|
||||
*/
|
||||
import classNames from "@calcom/lib/classNames";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { Dropdown, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@calcom/ui/Dropdown";
|
||||
import { Dropdown, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, Icon } from "@calcom/ui";
|
||||
|
||||
interface IAddVariablesDropdown {
|
||||
addVariable: (isEmailSubject: boolean, variable: string) => void;
|
||||
disabled: boolean;
|
||||
isEmailSubject: boolean;
|
||||
}
|
||||
|
||||
const variables = [
|
||||
"event_name",
|
||||
"organizer_name",
|
||||
"attendee_name",
|
||||
"event_date",
|
||||
"event_time",
|
||||
"location",
|
||||
"organizer_name",
|
||||
"attendee_name",
|
||||
"attendee_email",
|
||||
"additional_notes",
|
||||
];
|
||||
|
||||
/**
|
||||
* @deprecated file
|
||||
* All new changes should be made to the V2 file in
|
||||
* `/packages/features/ee/workflows/components/v2/AddVariablesDropdown.tsx`
|
||||
*/
|
||||
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 className="pt-[6px] focus:bg-gray-50">
|
||||
<div className="flex items-center ">
|
||||
{t("add_variable")}
|
||||
<Icon.FiChevronDown className="ml-1 h-4 w-4" />
|
||||
</div>
|
||||
</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, t(`${variable}_workflow`))}>
|
||||
{t(`${variable}_workflow`)}
|
||||
</button>
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
<div className="pt-4 pb-1">
|
||||
<div className="mb-2 px-4 text-left text-xs text-gray-500">
|
||||
{t("add_dynamic_variables").toLocaleUpperCase()}
|
||||
</div>
|
||||
{variables.map((variable) => (
|
||||
<DropdownMenuItem key={variable} className="hover:ring-0">
|
||||
<button
|
||||
key={variable}
|
||||
type="button"
|
||||
className="w-full px-4 py-2"
|
||||
onClick={() => props.addVariable(props.isEmailSubject, t(`${variable}_workflow`))}>
|
||||
<div className="sm:grid sm:grid-cols-2">
|
||||
<div className="mr-3 text-left md:col-span-1">
|
||||
{`{${t(`${variable}_workflow`).toUpperCase().replace(/ /g, "_")}}`}
|
||||
</div>
|
||||
<div className="hidden text-left text-gray-600 sm:col-span-1 sm:flex">
|
||||
{t(`${variable}_info`)}
|
||||
</div>
|
||||
</div>
|
||||
</button>
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
</div>
|
||||
</DropdownMenuContent>
|
||||
</Dropdown>
|
||||
);
|
||||
|
||||
+1
-3
@@ -3,9 +3,7 @@ import { Dispatch, SetStateAction } from "react";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { HttpError } from "@calcom/lib/http-error";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import { Dialog } from "@calcom/ui/v2";
|
||||
import { showToast } from "@calcom/ui/v2";
|
||||
import ConfirmationDialogContent from "@calcom/ui/v2/core/ConfirmationDialogContent";
|
||||
import { ConfirmationDialogContent, Dialog, showToast } from "@calcom/ui";
|
||||
|
||||
interface IDeleteDialog {
|
||||
isOpenDialog: boolean;
|
||||
+1
-2
@@ -3,8 +3,7 @@ import { Icon as FeatherIcon } from "react-feather";
|
||||
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { SVGComponent } from "@calcom/types/SVGComponent";
|
||||
import { Icon } from "@calcom/ui/Icon";
|
||||
import { Button } from "@calcom/ui/components/button";
|
||||
import { Button, Icon } from "@calcom/ui";
|
||||
|
||||
type WorkflowExampleType = {
|
||||
Icon: FeatherIcon;
|
||||
+4
-6
@@ -1,18 +1,16 @@
|
||||
import { WorkflowActions } from "@prisma/client";
|
||||
import Link from "next/link";
|
||||
import { useRouter } from "next/router";
|
||||
import { useState, useEffect } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
import classNames from "@calcom/lib/classNames";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { HttpError } from "@calcom/lib/http-error";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import { Icon } from "@calcom/ui";
|
||||
import { Button } from "@calcom/ui/components";
|
||||
import { showToast, Switch, Tooltip, EmptyScreen } from "@calcom/ui/v2";
|
||||
import { Button, EmptyScreen, Icon, showToast, Switch, Tooltip } from "@calcom/ui";
|
||||
|
||||
import LicenseRequired from "../../../common/components/v2/LicenseRequired";
|
||||
import { getActionIcon } from "../../lib/getActionIcon";
|
||||
import LicenseRequired from "../../common/components/v2/LicenseRequired";
|
||||
import { getActionIcon } from "../lib/getActionIcon";
|
||||
import SkeletonLoader from "./SkeletonLoaderEventWorkflowsTab";
|
||||
import { WorkflowType } from "./WorkflowListPage";
|
||||
|
||||
@@ -1,255 +0,0 @@
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { TimeUnit, WorkflowActions, WorkflowTriggerEvents } from "@prisma/client";
|
||||
import { isValidPhoneNumber } from "libphonenumber-js";
|
||||
import { useRouter } from "next/router";
|
||||
import { useState } from "react";
|
||||
import { Controller, useForm } from "react-hook-form";
|
||||
import { z } from "zod";
|
||||
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { HttpError } from "@calcom/lib/http-error";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import { Button } from "@calcom/ui";
|
||||
import { Dialog, DialogClose, DialogContent, DialogTrigger } from "@calcom/ui/Dialog";
|
||||
import { Icon } from "@calcom/ui/Icon";
|
||||
import PhoneInput from "@calcom/ui/form/PhoneInputLazy";
|
||||
import Select from "@calcom/ui/form/Select";
|
||||
import { Form, TextField } from "@calcom/ui/form/fields";
|
||||
import showToast from "@calcom/ui/v2/core/notifications";
|
||||
|
||||
import { TIME_UNIT, WORKFLOW_ACTIONS, WORKFLOW_TRIGGER_EVENTS } from "../lib/constants";
|
||||
import {
|
||||
getWorkflowActionOptions,
|
||||
getWorkflowTimeUnitOptions,
|
||||
getWorkflowTriggerOptions,
|
||||
} from "../lib/getOptions";
|
||||
|
||||
type WorkflowFormValues = {
|
||||
name: string;
|
||||
trigger: WorkflowTriggerEvents;
|
||||
action: WorkflowActions;
|
||||
time?: number;
|
||||
timeUnit?: TimeUnit;
|
||||
sendTo?: string;
|
||||
};
|
||||
|
||||
export function NewWorkflowButton() {
|
||||
const { t } = useLocale();
|
||||
const router = useRouter();
|
||||
const [showTimeSection, setShowTimeSection] = useState(false);
|
||||
const [isPhoneNumberNeeded, setIsPhoneNumberNeeded] = useState(false);
|
||||
const triggerOptions = getWorkflowTriggerOptions(t);
|
||||
const actionOptions = getWorkflowActionOptions(t);
|
||||
const timeUnitOptions = getWorkflowTimeUnitOptions(t);
|
||||
|
||||
const formSchema = z.object({
|
||||
name: z.string().min(1),
|
||||
trigger: z.enum(WORKFLOW_TRIGGER_EVENTS),
|
||||
action: z.enum(WORKFLOW_ACTIONS),
|
||||
time: z.number().min(1).optional(),
|
||||
timeUnit: z.enum(TIME_UNIT).optional(),
|
||||
sendTo: z
|
||||
.string()
|
||||
.refine((val) => isValidPhoneNumber(val))
|
||||
.optional(),
|
||||
});
|
||||
|
||||
const form = useForm<WorkflowFormValues>({
|
||||
defaultValues: {
|
||||
timeUnit: TimeUnit.HOUR,
|
||||
},
|
||||
mode: "onSubmit",
|
||||
resolver: zodResolver(formSchema),
|
||||
});
|
||||
|
||||
const createMutation = trpc.viewer.workflows.create.useMutation({
|
||||
onSuccess: async ({ workflow }) => {
|
||||
await router.replace("/workflows/" + workflow.id);
|
||||
setIsPhoneNumberNeeded(false);
|
||||
setShowTimeSection(false);
|
||||
showToast(t("workflow_created_successfully", { workflowName: workflow.name }), "success");
|
||||
},
|
||||
onError: (err) => {
|
||||
if (err instanceof HttpError) {
|
||||
const message = `${err.statusCode}: ${err.message}`;
|
||||
showToast(message, "error");
|
||||
}
|
||||
|
||||
if (err.data?.code === "UNAUTHORIZED") {
|
||||
const message = `${err.data.code}: You are not able to create this event`;
|
||||
showToast(message, "error");
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
return (
|
||||
<Dialog name="new-workflow">
|
||||
<DialogTrigger asChild>
|
||||
<Button StartIcon={Icon.FiPlus}>{t("new_workflow_btn")}</Button>
|
||||
</DialogTrigger>
|
||||
<DialogContent>
|
||||
<div className="mb-4">
|
||||
<h3 className="text-lg font-bold leading-6 text-gray-900" id="modal-title">
|
||||
{t("add_new_workflow")}
|
||||
</h3>
|
||||
</div>
|
||||
<Form
|
||||
form={form}
|
||||
handleSubmit={(values) => {
|
||||
form.clearErrors();
|
||||
createMutation.mutate(values);
|
||||
}}>
|
||||
<>
|
||||
<div className="mt-9">
|
||||
<TextField
|
||||
label={t("workflow_name")}
|
||||
placeholder={t("custom_workflow")}
|
||||
{...form.register("name")}
|
||||
/>
|
||||
</div>
|
||||
<div className="mt-5 space-y-1">
|
||||
<label htmlFor="label" className="mt-5 block text-sm font-medium text-gray-700">
|
||||
{t("trigger")}:
|
||||
</label>
|
||||
<Controller
|
||||
name="trigger"
|
||||
control={form.control}
|
||||
render={() => {
|
||||
return (
|
||||
<Select
|
||||
isSearchable={false}
|
||||
className="block w-full min-w-0 flex-1 rounded-sm text-sm"
|
||||
onChange={(val) => {
|
||||
if (val) {
|
||||
form.setValue("trigger", val.value);
|
||||
form.clearErrors("trigger");
|
||||
if (val.value === WorkflowTriggerEvents.BEFORE_EVENT) {
|
||||
setShowTimeSection(true);
|
||||
} else {
|
||||
setShowTimeSection(false);
|
||||
form.unregister("time");
|
||||
form.unregister("timeUnit");
|
||||
}
|
||||
}
|
||||
}}
|
||||
options={triggerOptions}
|
||||
/>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
{form.formState.errors.trigger && (
|
||||
<p className="mt-1 text-sm text-red-500">{form.formState.errors.trigger.message}</p>
|
||||
)}
|
||||
</div>
|
||||
{showTimeSection && (
|
||||
<div className="mt-5 mb-4 space-y-1">
|
||||
<label htmlFor="label" className="mb-2 block text-sm font-medium text-gray-700">
|
||||
{t("how_long_before")}
|
||||
</label>
|
||||
<div className="flex">
|
||||
<input
|
||||
type="number"
|
||||
min="1"
|
||||
defaultValue={24}
|
||||
className="mr-5 block w-32 rounded-sm border-gray-300 px-3 py-2 text-sm marker:border focus:border-neutral-800 focus:outline-none focus:ring-1 focus:ring-neutral-800"
|
||||
{...form.register("time", { valueAsNumber: true })}
|
||||
/>
|
||||
<div className="w-28">
|
||||
<Controller
|
||||
name="timeUnit"
|
||||
control={form.control}
|
||||
render={() => {
|
||||
return (
|
||||
<Select
|
||||
isSearchable={false}
|
||||
className="block min-w-0 flex-1 rounded-sm text-sm"
|
||||
onChange={(val) => {
|
||||
if (val) {
|
||||
form.setValue("timeUnit", val.value);
|
||||
}
|
||||
}}
|
||||
defaultValue={timeUnitOptions[1]}
|
||||
options={timeUnitOptions}
|
||||
/>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<div className="mt-5 space-y-1">
|
||||
<label htmlFor="label" className="block text-sm font-medium text-gray-700">
|
||||
{t("action")}:
|
||||
</label>
|
||||
<Controller
|
||||
name="action"
|
||||
control={form.control}
|
||||
render={() => {
|
||||
return (
|
||||
<Select
|
||||
isSearchable={false}
|
||||
className="block w-full min-w-0 flex-1 rounded-sm text-sm"
|
||||
onChange={(val) => {
|
||||
if (val) {
|
||||
form.setValue("action", val.value);
|
||||
form.clearErrors("action");
|
||||
if (val.value === WorkflowActions.SMS_NUMBER) {
|
||||
setIsPhoneNumberNeeded(true);
|
||||
} else {
|
||||
setIsPhoneNumberNeeded(false);
|
||||
form.unregister("sendTo");
|
||||
}
|
||||
}
|
||||
}}
|
||||
options={actionOptions}
|
||||
/>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
{form.formState.errors.action && (
|
||||
<p className="mt-1 text-sm text-red-500">{form.formState.errors.action.message}</p>
|
||||
)}
|
||||
</div>
|
||||
{isPhoneNumberNeeded && (
|
||||
<div className="mt-5 space-y-1">
|
||||
<label htmlFor="sendTo" className="block text-sm font-medium text-gray-700 dark:text-white">
|
||||
{t("phone_number")}
|
||||
</label>
|
||||
<div className="mt-1">
|
||||
<PhoneInput<WorkflowFormValues>
|
||||
control={form.control}
|
||||
name="sendTo"
|
||||
placeholder={t("enter_phone_number")}
|
||||
id="sendTo"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
{form.formState.errors.sendTo && (
|
||||
<p className="mt-1 text-sm text-red-500">{form.formState.errors.sendTo.message}</p>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
<div className=" mt-8 flex flex-row-reverse gap-x-2">
|
||||
<Button type="submit" disabled={createMutation.isLoading}>
|
||||
{t("continue")}
|
||||
</Button>
|
||||
<DialogClose asChild>
|
||||
<Button
|
||||
color="secondary"
|
||||
onClick={() => {
|
||||
setShowTimeSection(false);
|
||||
setIsPhoneNumberNeeded(false);
|
||||
form.clearErrors();
|
||||
form.setValue("name", "");
|
||||
}}>
|
||||
{t("cancel")}
|
||||
</Button>
|
||||
</DialogClose>
|
||||
</div>
|
||||
</Form>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
import { SkeletonContainer, SkeletonText } from "@calcom/ui/v2";
|
||||
import { SkeletonContainer, SkeletonText } from "@calcom/ui";
|
||||
|
||||
function SkeletonLoader() {
|
||||
return (
|
||||
+1
-2
@@ -1,5 +1,4 @@
|
||||
import { Icon } from "@calcom/ui";
|
||||
import { SkeletonAvatar, SkeletonText } from "@calcom/ui/v2";
|
||||
import { SkeletonAvatar, SkeletonText } from "@calcom/ui";
|
||||
|
||||
function SkeletonLoader() {
|
||||
return (
|
||||
+1
-2
@@ -1,5 +1,4 @@
|
||||
import { Icon } from "@calcom/ui";
|
||||
import { SkeletonText } from "@calcom/ui/v2";
|
||||
import { Icon, SkeletonText } from "@calcom/ui";
|
||||
|
||||
function SkeletonLoader() {
|
||||
return (
|
||||
+10
-5
@@ -2,12 +2,17 @@ import { useState } from "react";
|
||||
import { UseFormReturn } from "react-hook-form";
|
||||
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { Icon } from "@calcom/ui/Icon";
|
||||
import { TextField } from "@calcom/ui/components/form";
|
||||
import { Dropdown, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@calcom/ui/v2";
|
||||
import {
|
||||
Dropdown,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuTrigger,
|
||||
Icon,
|
||||
TextField,
|
||||
} from "@calcom/ui";
|
||||
|
||||
import { getWorkflowTimeUnitOptions } from "../../lib/getOptions";
|
||||
import type { FormValues } from "../../pages/v2/workflow";
|
||||
import { getWorkflowTimeUnitOptions } from "../lib/getOptions";
|
||||
import type { FormValues } from "../pages/workflow";
|
||||
|
||||
type Props = {
|
||||
form: UseFormReturn<FormValues>;
|
||||
@@ -1,19 +1,19 @@
|
||||
import { ArrowDownIcon } from "@heroicons/react/outline";
|
||||
import { WorkflowActions, WorkflowTemplates } from "@prisma/client";
|
||||
import { useRouter } from "next/router";
|
||||
import { Dispatch, SetStateAction, useMemo, useState } from "react";
|
||||
import { Controller, UseFormReturn } from "react-hook-form";
|
||||
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { HttpError } from "@calcom/lib/http-error";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import { Button } from "@calcom/ui";
|
||||
import MultiSelectCheckboxes, { Option } from "@calcom/ui/form/MultiSelectCheckboxes";
|
||||
import { Form } from "@calcom/ui/form/fields";
|
||||
import showToast from "@calcom/ui/v2/core/notifications";
|
||||
import useMeQuery from "@calcom/trpc/react/hooks/useMeQuery";
|
||||
import { Icon } from "@calcom/ui";
|
||||
import { Button, Label, TextField } from "@calcom/ui";
|
||||
import { MultiSelectCheckboxes } from "@calcom/ui";
|
||||
import type { MultiSelectCheckboxesOptionType as Option } from "@calcom/ui";
|
||||
|
||||
import type { FormValues } from "../pages/workflow";
|
||||
import { AddActionDialog } from "./AddActionDialog";
|
||||
import { DeleteDialog } from "./DeleteDialog";
|
||||
import WorkflowStepContainer from "./WorkflowStepContainer";
|
||||
|
||||
interface Props {
|
||||
@@ -27,11 +27,13 @@ export default function WorkflowDetailsPage(props: Props) {
|
||||
const { form, workflowId, selectedEventTypes, setSelectedEventTypes } = props;
|
||||
const { t } = useLocale();
|
||||
const router = useRouter();
|
||||
const utils = trpc.useContext();
|
||||
|
||||
const me = useMeQuery();
|
||||
const isFreeUser = me.data?.plan === "FREE";
|
||||
|
||||
const [isAddActionDialogOpen, setIsAddActionDialogOpen] = useState(false);
|
||||
const [reload, setReload] = useState(false);
|
||||
const [editCounter, setEditCounter] = useState(0);
|
||||
const [deleteDialogOpen, setDeleteDialogOpen] = useState(false);
|
||||
|
||||
const { data, isLoading } = trpc.viewer.eventTypes.getByViewer.useQuery();
|
||||
|
||||
@@ -50,29 +52,7 @@ export default function WorkflowDetailsPage(props: Props) {
|
||||
[data]
|
||||
);
|
||||
|
||||
const updateMutation = trpc.viewer.workflows.update.useMutation({
|
||||
onSuccess: async ({ workflow }) => {
|
||||
if (workflow) {
|
||||
utils.viewer.workflows.get.setData({ id: +workflow.id }, workflow);
|
||||
|
||||
showToast(
|
||||
t("workflow_updated_successfully", {
|
||||
workflowName: workflow.name,
|
||||
}),
|
||||
"success"
|
||||
);
|
||||
}
|
||||
await router.push("/workflows");
|
||||
},
|
||||
onError: (err) => {
|
||||
if (err instanceof HttpError) {
|
||||
const message = `${err.statusCode}: ${err.message}`;
|
||||
showToast(message, "error");
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
const addAction = (action: WorkflowActions, sendTo?: string) => {
|
||||
const addAction = (action: WorkflowActions, sendTo?: string, numberRequired?: boolean, sender?: string) => {
|
||||
const steps = form.getValues("steps");
|
||||
const id =
|
||||
steps?.length > 0
|
||||
@@ -94,38 +74,22 @@ export default function WorkflowDetailsPage(props: Props) {
|
||||
workflowId: workflowId,
|
||||
reminderBody: null,
|
||||
emailSubject: null,
|
||||
template: WorkflowTemplates.REMINDER,
|
||||
numberRequired: null,
|
||||
template: WorkflowTemplates.CUSTOM,
|
||||
numberRequired: numberRequired || false,
|
||||
sender: sender || "Cal",
|
||||
};
|
||||
steps?.push(step);
|
||||
form.setValue("steps", steps);
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Form
|
||||
form={form}
|
||||
handleSubmit={async (values) => {
|
||||
let activeOnEventTypeIds: number[] = [];
|
||||
if (values.activeOn) {
|
||||
activeOnEventTypeIds = values.activeOn.map((option) => {
|
||||
return parseInt(option.value, 10);
|
||||
});
|
||||
}
|
||||
updateMutation.mutate({
|
||||
id: parseInt(router.query.workflow as string, 10),
|
||||
name: values.name,
|
||||
activeOn: activeOnEventTypeIds,
|
||||
steps: values.steps,
|
||||
trigger: values.trigger,
|
||||
time: values.time || null,
|
||||
timeUnit: values.timeUnit || null,
|
||||
});
|
||||
}}>
|
||||
<div className="-mt-7 space-y-1">
|
||||
<label htmlFor="label" className="blocktext-sm mb-2 font-medium text-gray-700">
|
||||
{t("active_on")}:
|
||||
</label>
|
||||
<>
|
||||
<div className="my-8 sm:my-0 md:flex">
|
||||
<div className="pl-2 pr-3 md:sticky md:top-6 md:h-0 md:pl-0">
|
||||
<div className="mb-5">
|
||||
<TextField label={`${t("workflow_name")}:`} type="text" {...form.register("name")} />
|
||||
</div>
|
||||
<Label>{t("which_event_type_apply")}</Label>
|
||||
<Controller
|
||||
name="activeOn"
|
||||
control={form.control}
|
||||
@@ -134,6 +98,7 @@ export default function WorkflowDetailsPage(props: Props) {
|
||||
<MultiSelectCheckboxes
|
||||
options={eventTypeOptions}
|
||||
isLoading={isLoading}
|
||||
className="w-full md:w-64"
|
||||
setSelected={setSelectedEventTypes}
|
||||
selected={selectedEventTypes}
|
||||
setValue={(s: Option[]) => {
|
||||
@@ -143,13 +108,23 @@ export default function WorkflowDetailsPage(props: Props) {
|
||||
);
|
||||
}}
|
||||
/>
|
||||
<div className="my-7 border-transparent md:border-t md:border-gray-200" />
|
||||
<Button
|
||||
type="button"
|
||||
StartIcon={Icon.FiTrash2}
|
||||
color="destructive"
|
||||
className="border"
|
||||
onClick={() => setDeleteDialogOpen(true)}>
|
||||
{t("delete_workflow")}
|
||||
</Button>
|
||||
<div className="my-7 border-t border-gray-200 md:border-none" />
|
||||
</div>
|
||||
|
||||
{/* Workflow Trigger Event & Steps */}
|
||||
<div className="mt-5 px-5 pt-10 pb-5">
|
||||
<div className="w-full rounded-md border border-gray-200 bg-gray-50 p-3 py-5 md:ml-3 md:p-8">
|
||||
{form.getValues("trigger") && (
|
||||
<div>
|
||||
<WorkflowStepContainer form={form} setEditCounter={setEditCounter} editCounter={editCounter} />
|
||||
<WorkflowStepContainer form={form} isFreeUser={isFreeUser} />
|
||||
</div>
|
||||
)}
|
||||
{form.getValues("steps") && (
|
||||
@@ -162,33 +137,34 @@ export default function WorkflowDetailsPage(props: Props) {
|
||||
step={step}
|
||||
reload={reload}
|
||||
setReload={setReload}
|
||||
setEditCounter={setEditCounter}
|
||||
editCounter={editCounter}
|
||||
isFreeUser={isFreeUser}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</>
|
||||
)}
|
||||
<div className="flex justify-center">
|
||||
<ArrowDownIcon className="my-4 h-7 stroke-1 text-gray-500" />
|
||||
<div className="my-3 flex justify-center">
|
||||
<Icon.FiArrowDown className="stroke-[1.5px] text-3xl text-gray-500" />
|
||||
</div>
|
||||
<div className="flex justify-center">
|
||||
<Button type="button" onClick={() => setIsAddActionDialogOpen(true)} color="secondary">
|
||||
{t("add_action")}
|
||||
</Button>
|
||||
</div>
|
||||
<div className="rtl:space-x-reverse; mt-10 flex justify-end space-x-2">
|
||||
<Button type="submit" disabled={updateMutation.isLoading || editCounter > 0}>
|
||||
{t("save")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Form>
|
||||
</div>
|
||||
<AddActionDialog
|
||||
isOpenDialog={isAddActionDialogOpen}
|
||||
setIsOpenDialog={setIsAddActionDialogOpen}
|
||||
addAction={addAction}
|
||||
isFreeUser={isFreeUser}
|
||||
/>
|
||||
</div>
|
||||
<DeleteDialog
|
||||
isOpenDialog={deleteDialogOpen}
|
||||
setIsOpenDialog={setDeleteDialogOpen}
|
||||
workflowId={workflowId}
|
||||
additionalFunction={async () => await router.push("/workflows")}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -1,31 +1,71 @@
|
||||
import { Workflow, WorkflowStep } from "@prisma/client";
|
||||
import Link from "next/link";
|
||||
import { useRouter } from "next/router";
|
||||
import { useState } from "react";
|
||||
|
||||
import classNames from "@calcom/lib/classNames";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { HttpError } from "@calcom/lib/http-error";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import { Button, Tooltip } from "@calcom/ui";
|
||||
import ConfirmationDialogContent from "@calcom/ui/ConfirmationDialogContent";
|
||||
import { Dialog } from "@calcom/ui/Dialog";
|
||||
import Dropdown, { DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@calcom/ui/Dropdown";
|
||||
import EmptyScreen from "@calcom/ui/EmptyScreen";
|
||||
import { Icon } from "@calcom/ui/Icon";
|
||||
import showToast from "@calcom/ui/v2/core/notifications";
|
||||
import {
|
||||
Button,
|
||||
ButtonGroup,
|
||||
Dropdown,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuTrigger,
|
||||
Icon,
|
||||
showToast,
|
||||
Tooltip,
|
||||
} from "@calcom/ui";
|
||||
|
||||
import { WorkflowType } from "./v2/WorkflowListPage";
|
||||
import { getActionIcon } from "../lib/getActionIcon";
|
||||
import { DeleteDialog } from "./DeleteDialog";
|
||||
import EmptyScreen from "./EmptyScreen";
|
||||
|
||||
const CreateFirstWorkflowView = () => {
|
||||
const CreateEmptyWorkflowView = () => {
|
||||
const { t } = useLocale();
|
||||
const router = useRouter();
|
||||
|
||||
const createMutation = trpc.viewer.workflows.createV2.useMutation({
|
||||
onSuccess: async ({ workflow }) => {
|
||||
await router.replace("/workflows/" + workflow.id);
|
||||
},
|
||||
onError: (err) => {
|
||||
if (err instanceof HttpError) {
|
||||
const message = `${err.statusCode}: ${err.message}`;
|
||||
showToast(message, "error");
|
||||
}
|
||||
|
||||
if (err.data?.code === "UNAUTHORIZED") {
|
||||
const message = `${err.data.code}: You are not able to create this workflow`;
|
||||
showToast(message, "error");
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
return (
|
||||
<EmptyScreen
|
||||
Icon={Icon.FiZap}
|
||||
headline={t("new_workflow_heading")}
|
||||
description={t("new_workflow_description")}
|
||||
buttonText={t("create_workflow")}
|
||||
buttonOnClick={() => createMutation.mutate()}
|
||||
IconHeading={Icon.FiZap}
|
||||
headline={t("workflows")}
|
||||
description={t("no_workflows_description")}
|
||||
isLoading={createMutation.isLoading}
|
||||
showExampleWorkflows={true}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export type WorkflowType = Workflow & {
|
||||
steps: WorkflowStep[];
|
||||
activeOn: {
|
||||
eventType: {
|
||||
id: number;
|
||||
title: string;
|
||||
};
|
||||
}[];
|
||||
};
|
||||
interface Props {
|
||||
workflows: WorkflowType[] | undefined;
|
||||
}
|
||||
@@ -33,68 +73,64 @@ export default function WorkflowListPage({ workflows }: Props) {
|
||||
const { t } = useLocale();
|
||||
const utils = trpc.useContext();
|
||||
const [deleteDialogOpen, setDeleteDialogOpen] = useState(false);
|
||||
const [deleteDialogTypeId, setDeleteDialogTypeId] = useState(0);
|
||||
|
||||
const query = trpc.viewer.workflows.list.useQuery();
|
||||
|
||||
const deleteMutation = trpc.viewer.workflows.delete.useMutation({
|
||||
onSuccess: async () => {
|
||||
await utils.viewer.workflows.list.invalidate();
|
||||
showToast(t("workflow_deleted_successfully"), "success");
|
||||
setDeleteDialogOpen(false);
|
||||
},
|
||||
onError: (err) => {
|
||||
if (err instanceof HttpError) {
|
||||
const message = `${err.statusCode}: ${err.message}`;
|
||||
showToast(message, "error");
|
||||
setDeleteDialogOpen(false);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
async function deleteWorkflowHandler(id: number) {
|
||||
const payload = { id };
|
||||
deleteMutation.mutate(payload);
|
||||
}
|
||||
const [workflowToDeleteId, setwWorkflowToDeleteId] = useState(0);
|
||||
const router = useRouter();
|
||||
|
||||
return (
|
||||
<>
|
||||
{workflows && workflows.length > 0 ? (
|
||||
<div className="-mx-4 mb-16 overflow-hidden rounded-sm border border-gray-200 bg-white sm:mx-0">
|
||||
<ul className="divide-y divide-neutral-200">
|
||||
<div className="overflow-hidden rounded-md border border-gray-200 bg-white sm:mx-0">
|
||||
<ul className="divide-y divide-gray-200">
|
||||
{workflows.map((workflow) => (
|
||||
<li key={workflow.id}>
|
||||
<div className="first-line:group flex w-full items-center justify-between px-4 py-4 hover:bg-neutral-50 sm:px-6">
|
||||
<div className="first-line:group flex w-full items-center justify-between p-4 hover:bg-neutral-50 sm:px-6">
|
||||
<Link href={"/workflows/" + workflow.id}>
|
||||
<a className="flex-grow cursor-pointer">
|
||||
<div className="rtl:space-x-reverse">
|
||||
<div className="max-w-56 truncate text-sm font-medium leading-6 text-neutral-900 md:max-w-max">
|
||||
{workflow.name}
|
||||
<div
|
||||
className={classNames(
|
||||
"max-w-56 truncate text-sm font-medium leading-6 text-gray-900 md:max-w-max",
|
||||
workflow.name ? "text-gray-900" : "text-neutral-500"
|
||||
)}>
|
||||
{workflow.name
|
||||
? workflow.name
|
||||
: "Untitled (" +
|
||||
`${t(`${workflow.steps[0].action.toLowerCase()}_action`)}`
|
||||
.charAt(0)
|
||||
.toUpperCase() +
|
||||
`${t(`${workflow.steps[0].action.toLowerCase()}_action`)}`.slice(1) +
|
||||
")"}
|
||||
</div>
|
||||
<ul className="mt-2 flex flex-wrap text-sm text-neutral-500 sm:flex-nowrap">
|
||||
<li className="mb-1 mr-4 flex min-w-[265px] items-center truncate whitespace-nowrap">
|
||||
<span className="mr-1">{t("triggers")}</span>
|
||||
{workflow.timeUnit && workflow.time && (
|
||||
<span className="mr-1">
|
||||
{t(`${workflow.timeUnit.toLowerCase()}`, { count: workflow.time })}
|
||||
</span>
|
||||
)}
|
||||
<span>{t(`${workflow.trigger.toLowerCase()}_trigger`)}</span>
|
||||
<ul className="mt-2 flex flex-wrap space-x-1 sm:flex-nowrap ">
|
||||
<li className="mb-1 flex items-center whitespace-nowrap rounded-sm bg-gray-100 px-1 py-px text-xs text-gray-800 dark:bg-gray-900 dark:text-white">
|
||||
<div>
|
||||
{getActionIcon(workflow.steps)}
|
||||
|
||||
<span className="mr-1">{t("triggers")}</span>
|
||||
{workflow.timeUnit && workflow.time && (
|
||||
<span className="mr-1">
|
||||
{t(`${workflow.timeUnit.toLowerCase()}`, { count: workflow.time })}
|
||||
</span>
|
||||
)}
|
||||
<span>{t(`${workflow.trigger.toLowerCase()}_trigger`)}</span>
|
||||
</div>
|
||||
</li>
|
||||
<li className="mb-1 mr-4 flex min-w-[11rem] items-center whitespace-nowrap">
|
||||
<Icon.FiLink
|
||||
className="mr-1.5 inline h-4 w-4 text-neutral-400"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<li className="mb-1 flex items-center whitespace-nowrap rounded-sm bg-gray-100 px-1 py-px text-xs text-gray-800 dark:bg-gray-900 dark:text-white">
|
||||
{workflow.activeOn && workflow.activeOn.length > 0 ? (
|
||||
<Tooltip
|
||||
content={workflow.activeOn.map((activeOn, key) => (
|
||||
<p key={key}>{activeOn.eventType.title}</p>
|
||||
))}>
|
||||
<span>{t("active_on_event_types", { count: workflow.activeOn.length })}</span>
|
||||
<div>
|
||||
<Icon.FiLink className="mr-1.5 inline h-3 w-3" aria-hidden="true" />
|
||||
{t("active_on_event_types", { count: workflow.activeOn.length })}
|
||||
</div>
|
||||
</Tooltip>
|
||||
) : (
|
||||
<span>{t("no_active_event_types")}</span>
|
||||
<div>
|
||||
<Icon.FiLink className="mr-1.5 inline h-3 w-3" aria-hidden="true" />
|
||||
{t("no_active_event_types")}
|
||||
</div>
|
||||
)}
|
||||
</li>
|
||||
</ul>
|
||||
@@ -102,7 +138,31 @@ export default function WorkflowListPage({ workflows }: Props) {
|
||||
</a>
|
||||
</Link>
|
||||
<div className="flex flex-shrink-0">
|
||||
<div className="flex justify-between space-x-2 rtl:space-x-reverse">
|
||||
<div className="hidden sm:block">
|
||||
<ButtonGroup combined>
|
||||
<Tooltip content={t("edit") as string}>
|
||||
<Button
|
||||
type="button"
|
||||
color="secondary"
|
||||
size="icon"
|
||||
StartIcon={Icon.FiEdit2}
|
||||
onClick={async () => await router.replace("/workflows/" + workflow.id)}
|
||||
/>
|
||||
</Tooltip>
|
||||
<Tooltip content={t("delete") as string}>
|
||||
<Button
|
||||
onClick={() => {
|
||||
setDeleteDialogOpen(true);
|
||||
setwWorkflowToDeleteId(workflow.id);
|
||||
}}
|
||||
color="secondary"
|
||||
size="icon"
|
||||
StartIcon={Icon.FiTrash2}
|
||||
/>
|
||||
</Tooltip>
|
||||
</ButtonGroup>
|
||||
</div>
|
||||
<div className="block sm:hidden">
|
||||
<Dropdown>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
@@ -114,27 +174,22 @@ export default function WorkflowListPage({ workflows }: Props) {
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent>
|
||||
<DropdownMenuItem>
|
||||
<Link href={"/workflows/" + workflow.id} passHref={true}>
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
color="minimal"
|
||||
className="w-full rounded-none"
|
||||
StartIcon={Icon.FiEdit2}>
|
||||
{t("edit")}
|
||||
</Button>
|
||||
</Link>
|
||||
<Button
|
||||
type="button"
|
||||
color="minimal"
|
||||
StartIcon={Icon.FiEdit2}
|
||||
onClick={async () => await router.replace("/workflows/" + workflow.id)}>
|
||||
{t("edit")}
|
||||
</Button>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem>
|
||||
<Button
|
||||
onClick={() => {
|
||||
setDeleteDialogOpen(true);
|
||||
setDeleteDialogTypeId(workflow.id);
|
||||
setwWorkflowToDeleteId(workflow.id);
|
||||
}}
|
||||
color="warn"
|
||||
size="sm"
|
||||
StartIcon={Icon.FiTrash}
|
||||
className="w-full rounded-none">
|
||||
color="minimal"
|
||||
StartIcon={Icon.FiTrash2}>
|
||||
{t("delete")}
|
||||
</Button>
|
||||
</DropdownMenuItem>
|
||||
@@ -146,24 +201,17 @@ export default function WorkflowListPage({ workflows }: Props) {
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
|
||||
<Dialog open={deleteDialogOpen} onOpenChange={setDeleteDialogOpen}>
|
||||
<ConfirmationDialogContent
|
||||
isLoading={deleteMutation.isLoading}
|
||||
variety="danger"
|
||||
title={t("delete_workflow")}
|
||||
confirmBtnText={t("confirm_delete_workflow")}
|
||||
loadingText={t("confirm_delete_workflow")}
|
||||
onConfirm={(e) => {
|
||||
e.preventDefault();
|
||||
deleteWorkflowHandler(deleteDialogTypeId);
|
||||
}}>
|
||||
{t("delete_workflow_description")}
|
||||
</ConfirmationDialogContent>
|
||||
</Dialog>
|
||||
<DeleteDialog
|
||||
isOpenDialog={deleteDialogOpen}
|
||||
setIsOpenDialog={setDeleteDialogOpen}
|
||||
workflowId={workflowToDeleteId}
|
||||
additionalFunction={async () => {
|
||||
await utils.viewer.workflows.list.invalidate();
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<CreateFirstWorkflowView />
|
||||
<CreateEmptyWorkflowView />
|
||||
)}
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { ArrowDownIcon } from "@heroicons/react/outline";
|
||||
import {
|
||||
TimeUnit,
|
||||
WorkflowActions,
|
||||
@@ -6,97 +5,104 @@ import {
|
||||
WorkflowTemplates,
|
||||
WorkflowTriggerEvents,
|
||||
} from "@prisma/client";
|
||||
import { isValidPhoneNumber } from "libphonenumber-js";
|
||||
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";
|
||||
|
||||
import classNames from "@calcom/lib/classNames";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { HttpError } from "@calcom/lib/http-error";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import { Button } from "@calcom/ui";
|
||||
import ConfirmationDialogContent from "@calcom/ui/ConfirmationDialogContent";
|
||||
import { Dialog } from "@calcom/ui/Dialog";
|
||||
import Dropdown, { DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@calcom/ui/Dropdown";
|
||||
import { Icon } from "@calcom/ui/Icon";
|
||||
import Select from "@calcom/ui/form/Select";
|
||||
import { TextArea } from "@calcom/ui/form/fields";
|
||||
import showToast from "@calcom/ui/v2/core/notifications";
|
||||
import {
|
||||
Button,
|
||||
Checkbox,
|
||||
ConfirmationDialogContent,
|
||||
Dialog,
|
||||
DialogClose,
|
||||
DialogContent,
|
||||
Dropdown,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuTrigger,
|
||||
EmailField,
|
||||
Icon,
|
||||
Label,
|
||||
PhoneInput,
|
||||
Select,
|
||||
showToast,
|
||||
TextArea,
|
||||
TextField,
|
||||
} from "@calcom/ui";
|
||||
|
||||
import { AddVariablesDropdown } from "../components/AddVariablesDropdown";
|
||||
import {
|
||||
getWorkflowActionOptions,
|
||||
getWorkflowTemplateOptions,
|
||||
getWorkflowTimeUnitOptions,
|
||||
getWorkflowTriggerOptions,
|
||||
} from "../lib/getOptions";
|
||||
import { getTranslatedText, translateVariablesToEnglish } from "../lib/variableTranslations";
|
||||
import { translateVariablesToEnglish } from "../lib/variableTranslations";
|
||||
import type { FormValues } from "../pages/workflow";
|
||||
import { TimeTimeUnitInput } from "./TimeTimeUnitInput";
|
||||
|
||||
type WorkflowStepProps = {
|
||||
step?: WorkflowStep;
|
||||
form: UseFormReturn<FormValues>;
|
||||
reload?: boolean;
|
||||
setReload?: Dispatch<SetStateAction<boolean>>;
|
||||
editCounter: number;
|
||||
setEditCounter: Dispatch<SetStateAction<number>>;
|
||||
isFreeUser: boolean;
|
||||
};
|
||||
|
||||
export default function WorkflowStepContainer(props: WorkflowStepProps) {
|
||||
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
|
||||
);
|
||||
const [editEmailBodyMode, setEditEmailBodyMode] = useState(false);
|
||||
const [sendTo, setSendTo] = useState(step?.sendTo || "");
|
||||
const [errorMessageNumber, setErrorMessageNumber] = useState("");
|
||||
const [errorMessageCustomInput, setErrorMessageCustomInput] = useState("");
|
||||
const [isInfoParagraphOpen, setIsInfoParagraphOpen] = useState(false);
|
||||
const { step, form, reload, setReload, isFreeUser } = props;
|
||||
const [isAdditionalInputsDialogOpen, setIsAdditionalInputsDialogOpen] = useState(false);
|
||||
const [confirmationDialogOpen, setConfirmationDialogOpen] = useState(false);
|
||||
const [isTestActionDisabled, setIsTestActionDisabled] = 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
|
||||
);
|
||||
|
||||
const [isSenderIdNeeded, setIsSenderIdNeeded] = useState(
|
||||
step?.action === WorkflowActions.SMS_NUMBER || step?.action === WorkflowActions.SMS_ATTENDEE
|
||||
? true
|
||||
: false
|
||||
);
|
||||
|
||||
const [isEmailAddressNeeded, setIsEmailAddressNeeded] = useState(
|
||||
step?.action === WorkflowActions.EMAIL_ADDRESS ? 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
|
||||
step?.action === WorkflowActions.EMAIL_ATTENDEE ||
|
||||
step?.action === WorkflowActions.EMAIL_HOST ||
|
||||
step?.action === WorkflowActions.EMAIL_ADDRESS
|
||||
? true
|
||||
: false
|
||||
);
|
||||
|
||||
const [showTimeSection, setShowTimeSection] = useState(
|
||||
form.getValues("trigger") === WorkflowTriggerEvents.BEFORE_EVENT ? true : false
|
||||
form.getValues("trigger") === WorkflowTriggerEvents.BEFORE_EVENT ||
|
||||
form.getValues("trigger") === WorkflowTriggerEvents.AFTER_EVENT
|
||||
);
|
||||
|
||||
const [showTimeSectionAfter, setShowTimeSectionAfter] = useState(
|
||||
form.getValues("trigger") === WorkflowTriggerEvents.AFTER_EVENT
|
||||
);
|
||||
|
||||
const actionOptions = getWorkflowActionOptions(t);
|
||||
const triggerOptions = getWorkflowTriggerOptions(t);
|
||||
const timeUnitOptions = getWorkflowTimeUnitOptions(t);
|
||||
const templateOptions = getWorkflowTemplateOptions(t);
|
||||
|
||||
const { ref: emailSubjectFormRef } = form.register(`steps.${step ? step.stepNumber - 1 : 0}.emailSubject`);
|
||||
const { ref: emailSubjectFormRef, ...restEmailSubjectForm } = step
|
||||
? form.register(`steps.${step.stepNumber - 1}.emailSubject`)
|
||||
: { ref: null, name: "" };
|
||||
|
||||
const { ref: reminderBodyFormRef } = form.register(`steps.${step ? step.stepNumber - 1 : 0}.reminderBody`);
|
||||
const { ref: reminderBodyFormRef, ...restReminderBodyForm } = step
|
||||
? form.register(`steps.${step.stepNumber - 1}.reminderBody`)
|
||||
: { ref: null, name: "" };
|
||||
|
||||
const refEmailSubject = useRef<HTMLTextAreaElement | null>(null);
|
||||
|
||||
@@ -109,15 +115,15 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
|
||||
const cursorPosition = refEmailSubject?.current?.selectionStart || currentEmailSubject.length;
|
||||
const subjectWithAddedVariable = `${currentEmailSubject.substring(0, cursorPosition)}{${variable
|
||||
.toUpperCase()
|
||||
.replace(" ", "_")}}${currentEmailSubject.substring(cursorPosition)}`;
|
||||
setTranslatedSubject(subjectWithAddedVariable);
|
||||
.replace(/ /g, "_")}}${currentEmailSubject.substring(cursorPosition)}`;
|
||||
form.setValue(`steps.${step.stepNumber - 1}.emailSubject`, 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);
|
||||
.replace(/ /g, "_")}}${currentMessageBody.substring(cursorPosition)}`;
|
||||
form.setValue(`steps.${step.stepNumber - 1}.reminderBody`, messageWithAddedVariable);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -137,20 +143,28 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
|
||||
//trigger
|
||||
if (!step) {
|
||||
const trigger = form.getValues("trigger");
|
||||
const timeUnit = form.getValues("timeUnit");
|
||||
const triggerString = t(`${trigger.toLowerCase()}_trigger`);
|
||||
|
||||
const selectedTrigger = { label: t(`${trigger.toLowerCase()}_trigger`), value: trigger };
|
||||
const selectedTimeUnit = timeUnit
|
||||
? { label: t(`${timeUnit.toLowerCase()}_timeUnit`), value: timeUnit }
|
||||
: undefined;
|
||||
const selectedTrigger = {
|
||||
label: triggerString.charAt(0).toUpperCase() + triggerString.slice(1),
|
||||
value: trigger,
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="flex justify-center">
|
||||
<div className=" min-w-80 w-[50rem] rounded border border-gray-200 bg-white pl-10 pr-12 pb-9 pt-5">
|
||||
<div className="text-base font-bold">{t("trigger")}</div>
|
||||
<div className="text-sm text-gray-600">{t("when_something_happens")}</div>
|
||||
<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>
|
||||
<div className="my-7 border-t border-gray-200" />
|
||||
<Label>{t("when")}</Label>
|
||||
<Controller
|
||||
name="trigger"
|
||||
control={form.control}
|
||||
@@ -158,16 +172,25 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
|
||||
return (
|
||||
<Select
|
||||
isSearchable={false}
|
||||
className="mt-3 block w-full min-w-0 flex-1 rounded-sm text-sm"
|
||||
className="text-sm"
|
||||
onChange={(val) => {
|
||||
if (val) {
|
||||
form.setValue("trigger", val.value);
|
||||
if (val.value === WorkflowTriggerEvents.BEFORE_EVENT) {
|
||||
if (
|
||||
val.value === WorkflowTriggerEvents.BEFORE_EVENT ||
|
||||
val.value === WorkflowTriggerEvents.AFTER_EVENT
|
||||
) {
|
||||
setShowTimeSection(true);
|
||||
if (val.value === WorkflowTriggerEvents.AFTER_EVENT) {
|
||||
setShowTimeSectionAfter(true);
|
||||
} else {
|
||||
setShowTimeSectionAfter(false);
|
||||
}
|
||||
form.setValue("time", 24);
|
||||
form.setValue("timeUnit", TimeUnit.HOUR);
|
||||
} else {
|
||||
setShowTimeSection(false);
|
||||
setShowTimeSectionAfter(false);
|
||||
form.unregister("time");
|
||||
form.unregister("timeUnit");
|
||||
}
|
||||
@@ -180,40 +203,9 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
|
||||
}}
|
||||
/>
|
||||
{showTimeSection && (
|
||||
<div className="mt-5 space-y-1">
|
||||
<label htmlFor="label" className="mb-2 block text-sm font-medium text-gray-700">
|
||||
{t("how_long_before")}
|
||||
</label>
|
||||
<div className="flex">
|
||||
<input
|
||||
type="number"
|
||||
min="1"
|
||||
defaultValue={form.getValues("time") || 24}
|
||||
className="mr-5 block w-20 rounded-sm border-gray-300 px-3 py-2 text-sm marker:border focus:border-neutral-800 focus:outline-none focus:ring-1 focus:ring-neutral-800"
|
||||
{...form.register("time", { valueAsNumber: true })}
|
||||
/>
|
||||
<div className="w-28">
|
||||
<Controller
|
||||
name="timeUnit"
|
||||
control={form.control}
|
||||
render={() => {
|
||||
return (
|
||||
<Select
|
||||
isSearchable={false}
|
||||
className="block min-w-0 flex-1 rounded-sm text-sm"
|
||||
onChange={(val) => {
|
||||
if (val) {
|
||||
form.setValue("timeUnit", val.value);
|
||||
}
|
||||
}}
|
||||
defaultValue={selectedTimeUnit || timeUnitOptions[1]}
|
||||
options={timeUnitOptions}
|
||||
/>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="mt-5">
|
||||
<Label>{showTimeSectionAfter ? t("how_long_after") : t("how_long_before")}</Label>
|
||||
<TimeTimeUnitInput form={form} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
@@ -223,21 +215,73 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
|
||||
}
|
||||
|
||||
if (step && step.action) {
|
||||
const selectedAction = { label: t(`${step.action.toLowerCase()}_action`), value: step.action };
|
||||
const actionString = t(`${step.action.toLowerCase()}_action`);
|
||||
|
||||
const selectedAction = {
|
||||
label: actionString.charAt(0).toUpperCase() + actionString.slice(1),
|
||||
value: step.action,
|
||||
};
|
||||
|
||||
const selectedTemplate = { label: t(`${step.template.toLowerCase()}`), value: step.template };
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="flex justify-center ">
|
||||
<ArrowDownIcon className="my-4 h-7 stroke-1 text-gray-500" />
|
||||
<div className="my-3 flex justify-center">
|
||||
<Icon.FiArrowDown className="stroke-[1.5px] text-3xl text-gray-500" />
|
||||
</div>
|
||||
<div className="flex justify-center">
|
||||
<div className=" min-w-80 flex w-[50rem] rounded border border-gray-200 bg-white px-6 pb-9 pt-5 pr-3 sm:px-10">
|
||||
<div className="w-full pt-5">
|
||||
<div className="text-base font-bold">{t("action")}</div>
|
||||
<div className="text-sm text-gray-600">{t("action_is_performed")}</div>
|
||||
<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>
|
||||
<div className="my-7 border-t border-gray-200" />
|
||||
<div>
|
||||
<Label>{t("do_this")}</Label>
|
||||
<Controller
|
||||
name={`steps.${step.stepNumber - 1}.action`}
|
||||
control={form.control}
|
||||
@@ -245,127 +289,125 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
|
||||
return (
|
||||
<Select
|
||||
isSearchable={false}
|
||||
className="mt-3 block w-full min-w-0 flex-1 rounded-sm text-sm"
|
||||
className="text-sm"
|
||||
onChange={(val) => {
|
||||
if (val) {
|
||||
let counter = 0;
|
||||
if (val.value === WorkflowActions.SMS_NUMBER) {
|
||||
setIsPhoneNumberNeeded(true);
|
||||
setEditNumberMode(true);
|
||||
counter = counter + 1;
|
||||
setIsTestActionDisabled(true);
|
||||
} else {
|
||||
setIsSenderIdNeeded(true);
|
||||
setIsEmailAddressNeeded(false);
|
||||
} else if (val.value === WorkflowActions.EMAIL_ADDRESS) {
|
||||
setIsEmailAddressNeeded(true);
|
||||
setIsPhoneNumberNeeded(false);
|
||||
setEditNumberMode(false);
|
||||
}
|
||||
if (
|
||||
form.getValues(`steps.${step.stepNumber - 1}.template`) ===
|
||||
WorkflowTemplates.CUSTOM
|
||||
) {
|
||||
setEditEmailBodyMode(true);
|
||||
counter = counter + 1;
|
||||
setIsTestActionDisabled(true);
|
||||
setIsSenderIdNeeded(false);
|
||||
} else if (val.value === WorkflowActions.SMS_ATTENDEE) {
|
||||
setIsSenderIdNeeded(true);
|
||||
setIsEmailAddressNeeded(false);
|
||||
setIsPhoneNumberNeeded(false);
|
||||
} else {
|
||||
setIsEmailAddressNeeded(false);
|
||||
setIsPhoneNumberNeeded(false);
|
||||
setIsSenderIdNeeded(false);
|
||||
}
|
||||
form.unregister(`steps.${step.stepNumber - 1}.sendTo`);
|
||||
form.clearErrors(`steps.${step.stepNumber - 1}.sendTo`);
|
||||
if (
|
||||
val.value === WorkflowActions.EMAIL_ATTENDEE ||
|
||||
val.value === WorkflowActions.EMAIL_HOST
|
||||
val.value === WorkflowActions.EMAIL_HOST ||
|
||||
val.value === WorkflowActions.EMAIL_ADDRESS
|
||||
) {
|
||||
setIsEmailSubjectNeeded(true);
|
||||
} else {
|
||||
setIsEmailSubjectNeeded(false);
|
||||
}
|
||||
setEditCounter(counter);
|
||||
form.setValue(`steps.${step.stepNumber - 1}.action`, val.value);
|
||||
setErrorMessageNumber("");
|
||||
setErrorMessageCustomInput("");
|
||||
}
|
||||
}}
|
||||
defaultValue={selectedAction}
|
||||
options={actionOptions}
|
||||
options={
|
||||
isFreeUser
|
||||
? actionOptions.filter(
|
||||
(actionOption) =>
|
||||
actionOption.value !== WorkflowActions.SMS_ATTENDEE &&
|
||||
actionOption.value !== WorkflowActions.SMS_NUMBER
|
||||
)
|
||||
: actionOptions
|
||||
}
|
||||
/>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
{form.getValues(`steps.${step.stepNumber - 1}.action`) === WorkflowActions.SMS_ATTENDEE && (
|
||||
<p className="mt-2 ml-1 text-sm text-gray-500">{t("not_triggering_existing_bookings")}</p>
|
||||
)}
|
||||
</div>
|
||||
{isPhoneNumberNeeded && (
|
||||
<>
|
||||
<label
|
||||
htmlFor="sendTo"
|
||||
className="mt-5 block text-sm font-medium text-gray-700 dark:text-white">
|
||||
{t("phone_number")}
|
||||
</label>
|
||||
<div className="flex space-y-1">
|
||||
<div className="mt-1 ">
|
||||
<PhoneInput
|
||||
international
|
||||
value={sendTo}
|
||||
onChange={(newValue) => {
|
||||
if (newValue) {
|
||||
setSendTo(newValue);
|
||||
} else {
|
||||
setSendTo("");
|
||||
}
|
||||
setErrorMessageNumber("");
|
||||
}}
|
||||
placeholder={t("enter_phone_number")}
|
||||
id="sendTo"
|
||||
disabled={!editNumberMode}
|
||||
{(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"
|
||||
required
|
||||
countrySelectProps={{ className: "text-black" }}
|
||||
numberInputProps={{ className: "border-0 text-sm focus:ring-0 dark:bg-gray-700" }}
|
||||
className={classNames(
|
||||
"focus-within:border-brand order-1 block w-full rounded-sm border border-gray-300 py-px pl-3 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" : ""
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
{!editNumberMode ? (
|
||||
<Button
|
||||
type="button"
|
||||
color="secondary"
|
||||
className="-ml-3"
|
||||
onClick={() => {
|
||||
setEditNumberMode(true);
|
||||
setEditCounter(editCounter + 1);
|
||||
setIsTestActionDisabled(true);
|
||||
}}>
|
||||
{t("edit")}
|
||||
</Button>
|
||||
) : (
|
||||
<Button
|
||||
type="button"
|
||||
color="primary"
|
||||
className="-ml-3"
|
||||
onClick={async () => {
|
||||
if (sendTo) {
|
||||
if (isValidPhoneNumber(sendTo)) {
|
||||
form.setValue(`steps.${step.stepNumber - 1}.sendTo`, sendTo);
|
||||
setEditNumberMode(false);
|
||||
setEditCounter(editCounter - 1);
|
||||
if (!editEmailBodyMode) {
|
||||
setIsTestActionDisabled(false);
|
||||
}
|
||||
} else {
|
||||
setErrorMessageNumber(t("invalid_input"));
|
||||
}
|
||||
} else {
|
||||
setErrorMessageNumber(t("no_input"));
|
||||
}
|
||||
}}>
|
||||
{t("save")}
|
||||
</Button>
|
||||
{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"
|
||||
placeholder="Cal"
|
||||
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>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</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)
|
||||
}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
{errorMessageNumber && <p className="mt-1 text-sm text-red-500">{errorMessageNumber}</p>}
|
||||
</>
|
||||
/>
|
||||
</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>
|
||||
)}
|
||||
<div className="mt-5">
|
||||
<label htmlFor="label" className="mt-5 block text-sm font-medium text-gray-700">
|
||||
{t("choose_template")}
|
||||
</label>
|
||||
<Label>{t("message_template")}</Label>
|
||||
<Controller
|
||||
name={`steps.${step.stepNumber - 1}.template`}
|
||||
control={form.control}
|
||||
@@ -373,21 +415,12 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
|
||||
return (
|
||||
<Select
|
||||
isSearchable={false}
|
||||
className="mt-3 block w-full min-w-0 flex-1 rounded-sm text-sm"
|
||||
className="text-sm"
|
||||
onChange={(val) => {
|
||||
if (val) {
|
||||
form.setValue(`steps.${step.stepNumber - 1}.template`, val.value);
|
||||
const isCustomTemplate = val.value === WorkflowTemplates.CUSTOM;
|
||||
setIsCustomReminderBodyNeeded(isCustomTemplate);
|
||||
if (isCustomTemplate) {
|
||||
setEditEmailBodyMode(true);
|
||||
setEditCounter(editCounter + 1);
|
||||
} else if (editEmailBodyMode) {
|
||||
setEditEmailBodyMode(false);
|
||||
setEditCounter(editCounter - 1);
|
||||
}
|
||||
|
||||
setErrorMessageCustomInput("");
|
||||
}
|
||||
}}
|
||||
defaultValue={selectedTemplate}
|
||||
@@ -398,176 +431,127 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
|
||||
/>
|
||||
</div>
|
||||
{isCustomReminderBodyNeeded && (
|
||||
<>
|
||||
<div className="mt-2 rounded-md bg-gray-50 p-4 pt-2 md:p-6 md:pt-4">
|
||||
{isEmailSubjectNeeded && (
|
||||
<div className="mt-5 mb-2 ">
|
||||
<label className="mt-3 mb-1 block text-sm font-medium text-gray-700">
|
||||
{t("subject")}
|
||||
</label>
|
||||
<div className="mtext-sm border-1 focus-within:border-1 rounded-sm border border-gray-300 bg-white 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 className="mb-5">
|
||||
<div className="mb-2 flex items-center">
|
||||
<Label className="mb-0 flex-none">{t("subject")}</Label>
|
||||
<div className="flex-grow text-right">
|
||||
<AddVariablesDropdown addVariable={addVariable} isEmailSubject={true} />
|
||||
</div>
|
||||
</div>
|
||||
<TextArea
|
||||
ref={(e) => {
|
||||
emailSubjectFormRef?.(e);
|
||||
refEmailSubject.current = e;
|
||||
}}
|
||||
className="my-0"
|
||||
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>
|
||||
)}
|
||||
<label className="mt-3 mb-1 block text-sm font-medium text-gray-700 dark:text-white">
|
||||
{isEmailSubjectNeeded ? t("email_body") : t("text_message")}
|
||||
</label>
|
||||
<div className="border-1 focus-within:border-1 mb-2 rounded-sm border border-gray-300 bg-white text-sm 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 className="mb-2 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>
|
||||
<div className="mt-3 mb-5 ">
|
||||
<button
|
||||
className="flex"
|
||||
type="button"
|
||||
onClick={() => setIsInfoParagraphOpen(!isInfoParagraphOpen)}>
|
||||
{isInfoParagraphOpen ? (
|
||||
<Icon.FiChevronDown className="w5 h-5 text-gray-700" />
|
||||
) : (
|
||||
<Icon.FiChevronRight className="w5 h-5 text-gray-700" />
|
||||
)}
|
||||
<span className="text-sm">{t("using_additional_inputs_as_variables")}</span>
|
||||
</button>
|
||||
{isInfoParagraphOpen && (
|
||||
<div className="mt-4 ml-6 w-full pr-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>
|
||||
<TextArea
|
||||
ref={(e) => {
|
||||
reminderBodyFormRef?.(e);
|
||||
refReminderBody.current = e;
|
||||
}}
|
||||
className="my-0 h-24"
|
||||
required
|
||||
{...restReminderBodyForm}
|
||||
/>
|
||||
{form.formState.errors.steps &&
|
||||
form.formState?.errors?.steps[step.stepNumber - 1]?.reminderBody && (
|
||||
<p className="mt-1 text-xs text-red-500">
|
||||
{form.formState?.errors?.steps[step.stepNumber - 1]?.reminderBody?.message || ""}
|
||||
</p>
|
||||
)}
|
||||
<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>
|
||||
</div>
|
||||
|
||||
{errorMessageCustomInput && (
|
||||
<p className="mb-3 text-sm text-red-500">{errorMessageCustomInput}</p>
|
||||
)}
|
||||
|
||||
{!editEmailBodyMode ? (
|
||||
<Button
|
||||
type="button"
|
||||
color="secondary"
|
||||
onClick={() => {
|
||||
setEditEmailBodyMode(true);
|
||||
setEditCounter(editCounter + 1);
|
||||
setIsTestActionDisabled(true);
|
||||
}}>
|
||||
{t("edit")}
|
||||
</Button>
|
||||
) : (
|
||||
<Button
|
||||
type="button"
|
||||
color="primary"
|
||||
onClick={async () => {
|
||||
let isEmpty = false;
|
||||
let errorMessage = "";
|
||||
|
||||
if (isEmailSubjectNeeded) {
|
||||
if (!translatedReminderBody || !translatedSubject) {
|
||||
isEmpty = true;
|
||||
errorMessage = "Email body or subject is empty";
|
||||
}
|
||||
} 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);
|
||||
if (!editNumberMode) {
|
||||
setIsTestActionDisabled(false);
|
||||
}
|
||||
}
|
||||
setErrorMessageCustomInput(errorMessage);
|
||||
}}>
|
||||
{t("save")}
|
||||
</Button>
|
||||
)}
|
||||
</>
|
||||
</div>
|
||||
)}
|
||||
{form.getValues(`steps.${step.stepNumber - 1}.action`) !== WorkflowActions.SMS_ATTENDEE && (
|
||||
<Button
|
||||
type="button"
|
||||
className="mt-7 w-full"
|
||||
disabled={isTestActionDisabled}
|
||||
onClick={() => {
|
||||
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;
|
||||
}
|
||||
if (
|
||||
form.getValues(`steps.${step.stepNumber - 1}.action`) !== WorkflowActions.SMS_NUMBER
|
||||
form.getValues(`steps.${step.stepNumber - 1}.template`) === WorkflowTemplates.CUSTOM
|
||||
) {
|
||||
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 }
|
||||
);
|
||||
|
||||
testActionMutation.mutate({
|
||||
action: step.action,
|
||||
emailSubject: step.emailSubject || "",
|
||||
reminderBody: step.reminderBody || "",
|
||||
emailSubject,
|
||||
reminderBody,
|
||||
template: step.template,
|
||||
sender: step.sender || "Cal",
|
||||
});
|
||||
} else {
|
||||
setConfirmationDialogOpen(true);
|
||||
const isNumberValid =
|
||||
form.formState.errors.steps &&
|
||||
form.formState?.errors?.steps[step.stepNumber - 1]?.sendTo
|
||||
? false
|
||||
: true;
|
||||
|
||||
if (isPhoneNumberNeeded && isNumberValid && !isEmpty) {
|
||||
setConfirmationDialogOpen(true);
|
||||
}
|
||||
}
|
||||
}}
|
||||
color="secondary">
|
||||
@@ -575,40 +559,6 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
|
||||
</Button>
|
||||
)}
|
||||
</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="warn"
|
||||
size="sm"
|
||||
StartIcon={Icon.FiTrash}
|
||||
className="w-full rounded-none">
|
||||
{t("delete")}
|
||||
</Button>
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</Dropdown>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<Dialog open={confirmationDialogOpen} onOpenChange={setConfirmationDialogOpen}>
|
||||
@@ -618,18 +568,78 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
|
||||
confirmBtnText={t("send_sms")}
|
||||
onConfirm={(e) => {
|
||||
e.preventDefault();
|
||||
const reminderBody = translateVariablesToEnglish(
|
||||
form.getValues(`steps.${step.stepNumber - 1}.reminderBody`) || "",
|
||||
{ locale: i18n.language, t }
|
||||
);
|
||||
|
||||
testActionMutation.mutate({
|
||||
action: step.action,
|
||||
emailSubject: step.emailSubject || "",
|
||||
reminderBody: step.reminderBody || "",
|
||||
emailSubject: "",
|
||||
reminderBody: reminderBody || "",
|
||||
template: step.template,
|
||||
sendTo: step.sendTo || "",
|
||||
});
|
||||
setConfirmationDialogOpen(false);
|
||||
}}>
|
||||
{t("send_sms_to_number", { number: sendTo })}
|
||||
{t("send_sms_to_number", { number: form.getValues(`steps.${step.stepNumber - 1}.sendTo`) })}
|
||||
</ConfirmationDialogContent>
|
||||
</Dialog>
|
||||
<Dialog open={isAdditionalInputsDialogOpen} onOpenChange={setIsAdditionalInputsDialogOpen}>
|
||||
<DialogContent useOwnActionButtons type="creation" className="sm:max-w-[610px] md:h-[570px]">
|
||||
<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">
|
||||
<DialogClose asChild>
|
||||
<Button color="primary" type="button">
|
||||
{t("close")}
|
||||
</Button>
|
||||
</DialogClose>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,211 +0,0 @@
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { WorkflowActions } from "@prisma/client";
|
||||
import { isValidPhoneNumber } from "libphonenumber-js";
|
||||
import { Dispatch, SetStateAction, useState } from "react";
|
||||
import { Controller, useForm } from "react-hook-form";
|
||||
import { z } from "zod";
|
||||
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { Button, Checkbox, EmailField, Form, Label, TextField } from "@calcom/ui/components";
|
||||
import PhoneInput from "@calcom/ui/form/PhoneInputLazy";
|
||||
import { Dialog, DialogClose, DialogContent, DialogFooter, Select } from "@calcom/ui/v2";
|
||||
|
||||
import { WORKFLOW_ACTIONS } from "../../lib/constants";
|
||||
import { getWorkflowActionOptions } from "../../lib/getOptions";
|
||||
import { onlyLettersNumbersSpaces } from "../../pages/v2/workflow";
|
||||
|
||||
interface IAddActionDialog {
|
||||
isOpenDialog: boolean;
|
||||
setIsOpenDialog: Dispatch<SetStateAction<boolean>>;
|
||||
addAction: (action: WorkflowActions, sendTo?: string, numberRequired?: boolean, sender?: string) => void;
|
||||
isFreeUser: boolean;
|
||||
}
|
||||
|
||||
interface ISelectActionOption {
|
||||
label: string;
|
||||
value: WorkflowActions;
|
||||
}
|
||||
|
||||
type AddActionFormValues = {
|
||||
action: WorkflowActions;
|
||||
sendTo?: string;
|
||||
numberRequired?: boolean;
|
||||
sender?: string;
|
||||
};
|
||||
|
||||
const cleanUpActionsForFreeUser = (actions: ISelectActionOption[]) => {
|
||||
return actions.filter(
|
||||
(item) => item.value !== WorkflowActions.SMS_ATTENDEE && item.value !== WorkflowActions.SMS_NUMBER
|
||||
);
|
||||
};
|
||||
|
||||
export const AddActionDialog = (props: IAddActionDialog) => {
|
||||
const { t } = useLocale();
|
||||
const { isOpenDialog, setIsOpenDialog, addAction, isFreeUser } = props;
|
||||
const [isPhoneNumberNeeded, setIsPhoneNumberNeeded] = useState(false);
|
||||
const [isSenderIdNeeded, setIsSenderIdNeeded] = useState(false);
|
||||
const [isEmailAddressNeeded, setIsEmailAddressNeeded] = useState(false);
|
||||
const workflowActions = getWorkflowActionOptions(t);
|
||||
const actionOptions = isFreeUser ? cleanUpActionsForFreeUser(workflowActions) : workflowActions;
|
||||
|
||||
const formSchema = z.object({
|
||||
action: z.enum(WORKFLOW_ACTIONS),
|
||||
sendTo: z
|
||||
.string()
|
||||
.refine((val) => isValidPhoneNumber(val) || val.includes("@"))
|
||||
.optional(),
|
||||
numberRequired: z.boolean().optional(),
|
||||
sender: z
|
||||
.string()
|
||||
.refine((val) => onlyLettersNumbersSpaces(val))
|
||||
.nullable(),
|
||||
});
|
||||
|
||||
const form = useForm<AddActionFormValues>({
|
||||
mode: "onSubmit",
|
||||
defaultValues: {
|
||||
action: WorkflowActions.EMAIL_HOST,
|
||||
sender: "Cal",
|
||||
},
|
||||
resolver: zodResolver(formSchema),
|
||||
});
|
||||
|
||||
const handleSelectAction = (newValue: ISelectActionOption | null) => {
|
||||
if (newValue) {
|
||||
form.setValue("action", newValue.value);
|
||||
if (newValue.value === WorkflowActions.SMS_NUMBER) {
|
||||
setIsPhoneNumberNeeded(true);
|
||||
setIsSenderIdNeeded(true);
|
||||
setIsEmailAddressNeeded(false);
|
||||
} else if (newValue.value === WorkflowActions.EMAIL_ADDRESS) {
|
||||
setIsEmailAddressNeeded(true);
|
||||
setIsSenderIdNeeded(false);
|
||||
setIsPhoneNumberNeeded(false);
|
||||
} else if (newValue.value === WorkflowActions.SMS_ATTENDEE) {
|
||||
setIsSenderIdNeeded(true);
|
||||
setIsEmailAddressNeeded(false);
|
||||
setIsPhoneNumberNeeded(false);
|
||||
} else {
|
||||
setIsSenderIdNeeded(false);
|
||||
setIsEmailAddressNeeded(false);
|
||||
setIsPhoneNumberNeeded(false);
|
||||
}
|
||||
form.unregister("sendTo");
|
||||
form.unregister("numberRequired");
|
||||
form.clearErrors("action");
|
||||
form.clearErrors("sendTo");
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={isOpenDialog} onOpenChange={setIsOpenDialog}>
|
||||
<DialogContent type="creation" useOwnActionButtons={true} title={t("add_action")}>
|
||||
<div className="space-x-3 ">
|
||||
<div className="pt-1">
|
||||
<Form
|
||||
form={form}
|
||||
handleSubmit={(values) => {
|
||||
addAction(values.action, values.sendTo, values.numberRequired, values.sender);
|
||||
form.unregister("sendTo");
|
||||
form.unregister("action");
|
||||
form.unregister("numberRequired");
|
||||
setIsOpenDialog(false);
|
||||
setIsPhoneNumberNeeded(false);
|
||||
setIsEmailAddressNeeded(false);
|
||||
setIsSenderIdNeeded(false);
|
||||
}}>
|
||||
<div className="mt-5 space-y-1">
|
||||
<Label htmlFor="label">{t("action")}:</Label>
|
||||
<Controller
|
||||
name="action"
|
||||
control={form.control}
|
||||
render={() => {
|
||||
return (
|
||||
<Select
|
||||
isSearchable={false}
|
||||
className="text-sm"
|
||||
defaultValue={actionOptions[0]}
|
||||
onChange={handleSelectAction}
|
||||
options={actionOptions}
|
||||
/>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
{form.formState.errors.action && (
|
||||
<p className="mt-1 text-sm text-red-500">{form.formState.errors.action.message}</p>
|
||||
)}
|
||||
</div>
|
||||
{isPhoneNumberNeeded && (
|
||||
<div className="mt-5 space-y-1">
|
||||
<Label htmlFor="sendTo">{t("phone_number")}</Label>
|
||||
<div className="mt-1 mb-5">
|
||||
<PhoneInput<AddActionFormValues>
|
||||
control={form.control}
|
||||
name="sendTo"
|
||||
className="rounded-md"
|
||||
placeholder={t("enter_phone_number")}
|
||||
id="sendTo"
|
||||
required
|
||||
/>
|
||||
{form.formState.errors.sendTo && (
|
||||
<p className="mt-1 text-sm text-red-500">{form.formState.errors.sendTo.message}</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{isEmailAddressNeeded && (
|
||||
<div className="mt-5">
|
||||
<EmailField required label={t("email_address")} {...form.register("sendTo")} />
|
||||
</div>
|
||||
)}
|
||||
{isSenderIdNeeded && (
|
||||
<div className="mt-5">
|
||||
<TextField
|
||||
label={t("sender_id")}
|
||||
type="text"
|
||||
placeholder="Cal"
|
||||
maxLength={11}
|
||||
{...form.register(`sender`)}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
{form.getValues("action") === WorkflowActions.SMS_ATTENDEE && (
|
||||
<div className="mt-5">
|
||||
<Controller
|
||||
name="numberRequired"
|
||||
control={form.control}
|
||||
render={() => (
|
||||
<Checkbox
|
||||
defaultChecked={form.getValues("numberRequired") || false}
|
||||
description={t("make_phone_number_required")}
|
||||
onChange={(e) => form.setValue("numberRequired", e.target.checked)}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
<DialogFooter>
|
||||
<DialogClose asChild>
|
||||
<Button
|
||||
color="secondary"
|
||||
onClick={() => {
|
||||
setIsOpenDialog(false);
|
||||
form.unregister("sendTo");
|
||||
form.unregister("action");
|
||||
form.unregister("numberRequired");
|
||||
setIsPhoneNumberNeeded(false);
|
||||
setIsEmailAddressNeeded(false);
|
||||
setIsSenderIdNeeded(false);
|
||||
}}>
|
||||
{t("cancel")}
|
||||
</Button>
|
||||
</DialogClose>
|
||||
<Button type="submit">{t("add")}</Button>
|
||||
</DialogFooter>
|
||||
</Form>
|
||||
</div>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
};
|
||||
@@ -1,64 +0,0 @@
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { Icon } from "@calcom/ui";
|
||||
import {
|
||||
Dropdown,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuTrigger,
|
||||
} from "@calcom/ui/v2/core/Dropdown";
|
||||
|
||||
interface IAddVariablesDropdown {
|
||||
addVariable: (isEmailSubject: boolean, variable: string) => void;
|
||||
isEmailSubject: boolean;
|
||||
}
|
||||
|
||||
const variables = [
|
||||
"event_name",
|
||||
"event_date",
|
||||
"event_time",
|
||||
"location",
|
||||
"organizer_name",
|
||||
"attendee_name",
|
||||
"attendee_email",
|
||||
"additional_notes",
|
||||
];
|
||||
|
||||
export const AddVariablesDropdown = (props: IAddVariablesDropdown) => {
|
||||
const { t } = useLocale();
|
||||
|
||||
return (
|
||||
<Dropdown>
|
||||
<DropdownMenuTrigger className="pt-[6px] focus:bg-gray-50">
|
||||
<div className="flex items-center ">
|
||||
{t("add_variable")}
|
||||
<Icon.FiChevronDown className="ml-1 h-4 w-4" />
|
||||
</div>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent className="h-40 overflow-scroll">
|
||||
<div className="pt-4 pb-1">
|
||||
<div className="mb-2 px-4 text-left text-xs text-gray-500">
|
||||
{t("add_dynamic_variables").toLocaleUpperCase()}
|
||||
</div>
|
||||
{variables.map((variable) => (
|
||||
<DropdownMenuItem key={variable} className="hover:ring-0">
|
||||
<button
|
||||
key={variable}
|
||||
type="button"
|
||||
className="w-full px-4 py-2"
|
||||
onClick={() => props.addVariable(props.isEmailSubject, t(`${variable}_workflow`))}>
|
||||
<div className="sm:grid sm:grid-cols-2">
|
||||
<div className="mr-3 text-left md:col-span-1">
|
||||
{`{${t(`${variable}_workflow`).toUpperCase().replace(/ /g, "_")}}`}
|
||||
</div>
|
||||
<div className="hidden text-left text-gray-600 sm:col-span-1 sm:flex">
|
||||
{t(`${variable}_info`)}
|
||||
</div>
|
||||
</div>
|
||||
</button>
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
</div>
|
||||
</DropdownMenuContent>
|
||||
</Dropdown>
|
||||
);
|
||||
};
|
||||
@@ -1,169 +0,0 @@
|
||||
import { WorkflowActions, WorkflowTemplates } from "@prisma/client";
|
||||
import { useRouter } from "next/router";
|
||||
import { Dispatch, SetStateAction, useMemo, useState } from "react";
|
||||
import { Controller, UseFormReturn } from "react-hook-form";
|
||||
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import useMeQuery from "@calcom/trpc/react/hooks/useMeQuery";
|
||||
import { Icon } from "@calcom/ui/Icon";
|
||||
import { Button, Label, TextField } from "@calcom/ui/components";
|
||||
import MultiSelectCheckboxes, { Option } from "@calcom/ui/v2/core/form/MultiSelectCheckboxes";
|
||||
|
||||
import type { FormValues } from "../../pages/v2/workflow";
|
||||
import { AddActionDialog } from "./AddActionDialog";
|
||||
import { DeleteDialog } from "./DeleteDialog";
|
||||
import WorkflowStepContainer from "./WorkflowStepContainer";
|
||||
|
||||
interface Props {
|
||||
form: UseFormReturn<FormValues>;
|
||||
workflowId: number;
|
||||
selectedEventTypes: Option[];
|
||||
setSelectedEventTypes: Dispatch<SetStateAction<Option[]>>;
|
||||
}
|
||||
|
||||
export default function WorkflowDetailsPage(props: Props) {
|
||||
const { form, workflowId, selectedEventTypes, setSelectedEventTypes } = props;
|
||||
const { t } = useLocale();
|
||||
const router = useRouter();
|
||||
|
||||
const me = useMeQuery();
|
||||
const isFreeUser = me.data?.plan === "FREE";
|
||||
|
||||
const [isAddActionDialogOpen, setIsAddActionDialogOpen] = useState(false);
|
||||
const [reload, setReload] = useState(false);
|
||||
const [deleteDialogOpen, setDeleteDialogOpen] = useState(false);
|
||||
|
||||
const { data, isLoading } = trpc.viewer.eventTypes.getByViewer.useQuery();
|
||||
|
||||
const eventTypeOptions = useMemo(
|
||||
() =>
|
||||
data?.eventTypeGroups.reduce(
|
||||
(options, group) => [
|
||||
...options,
|
||||
...group.eventTypes.map((eventType) => ({
|
||||
value: String(eventType.id),
|
||||
label: eventType.title,
|
||||
})),
|
||||
],
|
||||
[] as Option[]
|
||||
) || [],
|
||||
[data]
|
||||
);
|
||||
|
||||
const addAction = (action: WorkflowActions, sendTo?: string, numberRequired?: boolean, sender?: string) => {
|
||||
const steps = form.getValues("steps");
|
||||
const id =
|
||||
steps?.length > 0
|
||||
? steps.sort((a, b) => {
|
||||
return a.id - b.id;
|
||||
})[0].id - 1
|
||||
: 0;
|
||||
|
||||
const step = {
|
||||
id: id > 0 ? 0 : id, //id of new steps always <= 0
|
||||
action,
|
||||
stepNumber:
|
||||
steps && steps.length > 0
|
||||
? steps.sort((a, b) => {
|
||||
return a.stepNumber - b.stepNumber;
|
||||
})[steps.length - 1].stepNumber + 1
|
||||
: 1,
|
||||
sendTo: sendTo || null,
|
||||
workflowId: workflowId,
|
||||
reminderBody: null,
|
||||
emailSubject: null,
|
||||
template: WorkflowTemplates.CUSTOM,
|
||||
numberRequired: numberRequired || false,
|
||||
sender: sender || "Cal",
|
||||
};
|
||||
steps?.push(step);
|
||||
form.setValue("steps", steps);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="my-8 sm:my-0 md:flex">
|
||||
<div className="pl-2 pr-3 md:sticky md:top-6 md:h-0 md:pl-0">
|
||||
<div className="mb-5">
|
||||
<TextField label={`${t("workflow_name")}:`} type="text" {...form.register("name")} />
|
||||
</div>
|
||||
<Label>{t("which_event_type_apply")}</Label>
|
||||
<Controller
|
||||
name="activeOn"
|
||||
control={form.control}
|
||||
render={() => {
|
||||
return (
|
||||
<MultiSelectCheckboxes
|
||||
options={eventTypeOptions}
|
||||
isLoading={isLoading}
|
||||
className="w-full md:w-64"
|
||||
setSelected={setSelectedEventTypes}
|
||||
selected={selectedEventTypes}
|
||||
setValue={(s: Option[]) => {
|
||||
form.setValue("activeOn", s);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
<div className="my-7 border-transparent md:border-t md:border-gray-200" />
|
||||
<Button
|
||||
type="button"
|
||||
StartIcon={Icon.FiTrash2}
|
||||
color="destructive"
|
||||
className="border"
|
||||
onClick={() => setDeleteDialogOpen(true)}>
|
||||
{t("delete_workflow")}
|
||||
</Button>
|
||||
<div className="my-7 border-t border-gray-200 md:border-none" />
|
||||
</div>
|
||||
|
||||
{/* Workflow Trigger Event & Steps */}
|
||||
<div className="w-full rounded-md border border-gray-200 bg-gray-50 p-3 py-5 md:ml-3 md:p-8">
|
||||
{form.getValues("trigger") && (
|
||||
<div>
|
||||
<WorkflowStepContainer form={form} isFreeUser={isFreeUser} />
|
||||
</div>
|
||||
)}
|
||||
{form.getValues("steps") && (
|
||||
<>
|
||||
{form.getValues("steps")?.map((step) => {
|
||||
return (
|
||||
<WorkflowStepContainer
|
||||
key={step.id}
|
||||
form={form}
|
||||
step={step}
|
||||
reload={reload}
|
||||
setReload={setReload}
|
||||
isFreeUser={isFreeUser}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</>
|
||||
)}
|
||||
<div className="my-3 flex justify-center">
|
||||
<Icon.FiArrowDown className="stroke-[1.5px] text-3xl text-gray-500" />
|
||||
</div>
|
||||
<div className="flex justify-center">
|
||||
<Button type="button" onClick={() => setIsAddActionDialogOpen(true)} color="secondary">
|
||||
{t("add_action")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<AddActionDialog
|
||||
isOpenDialog={isAddActionDialogOpen}
|
||||
setIsOpenDialog={setIsAddActionDialogOpen}
|
||||
addAction={addAction}
|
||||
isFreeUser={isFreeUser}
|
||||
/>
|
||||
<DeleteDialog
|
||||
isOpenDialog={deleteDialogOpen}
|
||||
setIsOpenDialog={setDeleteDialogOpen}
|
||||
workflowId={workflowId}
|
||||
additionalFunction={async () => await router.push("/workflows")}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -1,217 +0,0 @@
|
||||
import { Workflow, WorkflowStep } from "@prisma/client";
|
||||
import Link from "next/link";
|
||||
import { useRouter } from "next/router";
|
||||
import { useState } from "react";
|
||||
|
||||
import classNames from "@calcom/lib/classNames";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { HttpError } from "@calcom/lib/http-error";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import { Icon } from "@calcom/ui/Icon";
|
||||
import { Button, ButtonGroup } from "@calcom/ui/components";
|
||||
import {
|
||||
Dropdown,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuTrigger,
|
||||
showToast,
|
||||
Tooltip,
|
||||
} from "@calcom/ui/v2";
|
||||
|
||||
import { getActionIcon } from "../../lib/getActionIcon";
|
||||
import { DeleteDialog } from "./DeleteDialog";
|
||||
import EmptyScreen from "./EmptyScreen";
|
||||
|
||||
const CreateEmptyWorkflowView = () => {
|
||||
const { t } = useLocale();
|
||||
const router = useRouter();
|
||||
|
||||
const createMutation = trpc.viewer.workflows.createV2.useMutation({
|
||||
onSuccess: async ({ workflow }) => {
|
||||
await router.replace("/workflows/" + workflow.id);
|
||||
},
|
||||
onError: (err) => {
|
||||
if (err instanceof HttpError) {
|
||||
const message = `${err.statusCode}: ${err.message}`;
|
||||
showToast(message, "error");
|
||||
}
|
||||
|
||||
if (err.data?.code === "UNAUTHORIZED") {
|
||||
const message = `${err.data.code}: You are not able to create this workflow`;
|
||||
showToast(message, "error");
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
return (
|
||||
<EmptyScreen
|
||||
buttonText={t("create_workflow")}
|
||||
buttonOnClick={() => createMutation.mutate()}
|
||||
IconHeading={Icon.FiZap}
|
||||
headline={t("workflows")}
|
||||
description={t("no_workflows_description")}
|
||||
isLoading={createMutation.isLoading}
|
||||
showExampleWorkflows={true}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export type WorkflowType = Workflow & {
|
||||
steps: WorkflowStep[];
|
||||
activeOn: {
|
||||
eventType: {
|
||||
id: number;
|
||||
title: string;
|
||||
};
|
||||
}[];
|
||||
};
|
||||
interface Props {
|
||||
workflows: WorkflowType[] | undefined;
|
||||
}
|
||||
export default function WorkflowListPage({ workflows }: Props) {
|
||||
const { t } = useLocale();
|
||||
const utils = trpc.useContext();
|
||||
const [deleteDialogOpen, setDeleteDialogOpen] = useState(false);
|
||||
const [workflowToDeleteId, setwWorkflowToDeleteId] = useState(0);
|
||||
const router = useRouter();
|
||||
|
||||
return (
|
||||
<>
|
||||
{workflows && workflows.length > 0 ? (
|
||||
<div className="overflow-hidden rounded-md border border-gray-200 bg-white sm:mx-0">
|
||||
<ul className="divide-y divide-gray-200">
|
||||
{workflows.map((workflow) => (
|
||||
<li key={workflow.id}>
|
||||
<div className="first-line:group flex w-full items-center justify-between p-4 hover:bg-neutral-50 sm:px-6">
|
||||
<Link href={"/workflows/" + workflow.id}>
|
||||
<a className="flex-grow cursor-pointer">
|
||||
<div className="rtl:space-x-reverse">
|
||||
<div
|
||||
className={classNames(
|
||||
"max-w-56 truncate text-sm font-medium leading-6 text-gray-900 md:max-w-max",
|
||||
workflow.name ? "text-gray-900" : "text-neutral-500"
|
||||
)}>
|
||||
{workflow.name
|
||||
? workflow.name
|
||||
: "Untitled (" +
|
||||
`${t(`${workflow.steps[0].action.toLowerCase()}_action`)}`
|
||||
.charAt(0)
|
||||
.toUpperCase() +
|
||||
`${t(`${workflow.steps[0].action.toLowerCase()}_action`)}`.slice(1) +
|
||||
")"}
|
||||
</div>
|
||||
<ul className="mt-2 flex flex-wrap space-x-1 sm:flex-nowrap ">
|
||||
<li className="mb-1 flex items-center whitespace-nowrap rounded-sm bg-gray-100 px-1 py-px text-xs text-gray-800 dark:bg-gray-900 dark:text-white">
|
||||
<div>
|
||||
{getActionIcon(workflow.steps)}
|
||||
|
||||
<span className="mr-1">{t("triggers")}</span>
|
||||
{workflow.timeUnit && workflow.time && (
|
||||
<span className="mr-1">
|
||||
{t(`${workflow.timeUnit.toLowerCase()}`, { count: workflow.time })}
|
||||
</span>
|
||||
)}
|
||||
<span>{t(`${workflow.trigger.toLowerCase()}_trigger`)}</span>
|
||||
</div>
|
||||
</li>
|
||||
<li className="mb-1 flex items-center whitespace-nowrap rounded-sm bg-gray-100 px-1 py-px text-xs text-gray-800 dark:bg-gray-900 dark:text-white">
|
||||
{workflow.activeOn && workflow.activeOn.length > 0 ? (
|
||||
<Tooltip
|
||||
content={workflow.activeOn.map((activeOn, key) => (
|
||||
<p key={key}>{activeOn.eventType.title}</p>
|
||||
))}>
|
||||
<div>
|
||||
<Icon.FiLink className="mr-1.5 inline h-3 w-3" aria-hidden="true" />
|
||||
{t("active_on_event_types", { count: workflow.activeOn.length })}
|
||||
</div>
|
||||
</Tooltip>
|
||||
) : (
|
||||
<div>
|
||||
<Icon.FiLink className="mr-1.5 inline h-3 w-3" aria-hidden="true" />
|
||||
{t("no_active_event_types")}
|
||||
</div>
|
||||
)}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</a>
|
||||
</Link>
|
||||
<div className="flex flex-shrink-0">
|
||||
<div className="hidden sm:block">
|
||||
<ButtonGroup combined>
|
||||
<Tooltip content={t("edit") as string}>
|
||||
<Button
|
||||
type="button"
|
||||
color="secondary"
|
||||
size="icon"
|
||||
StartIcon={Icon.FiEdit2}
|
||||
onClick={async () => await router.replace("/workflows/" + workflow.id)}
|
||||
/>
|
||||
</Tooltip>
|
||||
<Tooltip content={t("delete") as string}>
|
||||
<Button
|
||||
onClick={() => {
|
||||
setDeleteDialogOpen(true);
|
||||
setwWorkflowToDeleteId(workflow.id);
|
||||
}}
|
||||
color="secondary"
|
||||
size="icon"
|
||||
StartIcon={Icon.FiTrash2}
|
||||
/>
|
||||
</Tooltip>
|
||||
</ButtonGroup>
|
||||
</div>
|
||||
<div className="block sm:hidden">
|
||||
<Dropdown>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
type="button"
|
||||
color="minimal"
|
||||
size="icon"
|
||||
StartIcon={Icon.FiMoreHorizontal}
|
||||
/>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent>
|
||||
<DropdownMenuItem>
|
||||
<Button
|
||||
type="button"
|
||||
color="minimal"
|
||||
StartIcon={Icon.FiEdit2}
|
||||
onClick={async () => await router.replace("/workflows/" + workflow.id)}>
|
||||
{t("edit")}
|
||||
</Button>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem>
|
||||
<Button
|
||||
onClick={() => {
|
||||
setDeleteDialogOpen(true);
|
||||
setwWorkflowToDeleteId(workflow.id);
|
||||
}}
|
||||
color="minimal"
|
||||
StartIcon={Icon.FiTrash2}>
|
||||
{t("delete")}
|
||||
</Button>
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</Dropdown>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
<DeleteDialog
|
||||
isOpenDialog={deleteDialogOpen}
|
||||
setIsOpenDialog={setDeleteDialogOpen}
|
||||
workflowId={workflowToDeleteId}
|
||||
additionalFunction={async () => {
|
||||
await utils.viewer.workflows.list.invalidate();
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<CreateEmptyWorkflowView />
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -1,639 +0,0 @@
|
||||
import {
|
||||
TimeUnit,
|
||||
WorkflowActions,
|
||||
WorkflowStep,
|
||||
WorkflowTemplates,
|
||||
WorkflowTriggerEvents,
|
||||
} from "@prisma/client";
|
||||
import { Dispatch, SetStateAction, useRef, useState } from "react";
|
||||
import { Controller, UseFormReturn } from "react-hook-form";
|
||||
import "react-phone-number-input/style.css";
|
||||
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { HttpError } from "@calcom/lib/http-error";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import { Dialog } from "@calcom/ui/Dialog";
|
||||
import Dropdown, { DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@calcom/ui/Dropdown";
|
||||
import { Icon } from "@calcom/ui/Icon";
|
||||
import { Button } from "@calcom/ui/components";
|
||||
import { Checkbox } from "@calcom/ui/components";
|
||||
import { EmailField, Label, TextArea, TextField } from "@calcom/ui/components/form";
|
||||
import PhoneInput from "@calcom/ui/form/PhoneInputLazy";
|
||||
import { DialogClose, DialogContent } from "@calcom/ui/v2";
|
||||
import ConfirmationDialogContent from "@calcom/ui/v2/core/ConfirmationDialogContent";
|
||||
import Select from "@calcom/ui/v2/core/form/select";
|
||||
import showToast from "@calcom/ui/v2/core/notifications";
|
||||
|
||||
import { AddVariablesDropdown } from "../../components/v2/AddVariablesDropdown";
|
||||
import {
|
||||
getWorkflowActionOptions,
|
||||
getWorkflowTemplateOptions,
|
||||
getWorkflowTriggerOptions,
|
||||
} from "../../lib/getOptions";
|
||||
import { translateVariablesToEnglish } from "../../lib/variableTranslations";
|
||||
import type { FormValues } from "../../pages/v2/workflow";
|
||||
import { TimeTimeUnitInput } from "./TimeTimeUnitInput";
|
||||
|
||||
type WorkflowStepProps = {
|
||||
step?: WorkflowStep;
|
||||
form: UseFormReturn<FormValues>;
|
||||
reload?: boolean;
|
||||
setReload?: Dispatch<SetStateAction<boolean>>;
|
||||
isFreeUser: boolean;
|
||||
};
|
||||
|
||||
export default function WorkflowStepContainer(props: WorkflowStepProps) {
|
||||
const { t, i18n } = useLocale();
|
||||
const { step, form, reload, setReload, isFreeUser } = props;
|
||||
const [isAdditionalInputsDialogOpen, setIsAdditionalInputsDialogOpen] = useState(false);
|
||||
const [confirmationDialogOpen, setConfirmationDialogOpen] = useState(false);
|
||||
|
||||
const [isPhoneNumberNeeded, setIsPhoneNumberNeeded] = useState(
|
||||
step?.action === WorkflowActions.SMS_NUMBER ? true : false
|
||||
);
|
||||
|
||||
const [isSenderIdNeeded, setIsSenderIdNeeded] = useState(
|
||||
step?.action === WorkflowActions.SMS_NUMBER || step?.action === WorkflowActions.SMS_ATTENDEE
|
||||
? true
|
||||
: false
|
||||
);
|
||||
|
||||
const [isEmailAddressNeeded, setIsEmailAddressNeeded] = useState(
|
||||
step?.action === WorkflowActions.EMAIL_ADDRESS ? 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 ||
|
||||
step?.action === WorkflowActions.EMAIL_ADDRESS
|
||||
? true
|
||||
: false
|
||||
);
|
||||
|
||||
const [showTimeSection, setShowTimeSection] = useState(
|
||||
form.getValues("trigger") === WorkflowTriggerEvents.BEFORE_EVENT ||
|
||||
form.getValues("trigger") === WorkflowTriggerEvents.AFTER_EVENT
|
||||
);
|
||||
|
||||
const [showTimeSectionAfter, setShowTimeSectionAfter] = useState(
|
||||
form.getValues("trigger") === WorkflowTriggerEvents.AFTER_EVENT
|
||||
);
|
||||
|
||||
const actionOptions = getWorkflowActionOptions(t);
|
||||
const triggerOptions = getWorkflowTriggerOptions(t);
|
||||
const templateOptions = getWorkflowTemplateOptions(t);
|
||||
|
||||
const { ref: emailSubjectFormRef, ...restEmailSubjectForm } = step
|
||||
? form.register(`steps.${step.stepNumber - 1}.emailSubject`)
|
||||
: { ref: null, name: "" };
|
||||
|
||||
const { ref: reminderBodyFormRef, ...restReminderBodyForm } = step
|
||||
? form.register(`steps.${step.stepNumber - 1}.reminderBody`)
|
||||
: { ref: null, name: "" };
|
||||
|
||||
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(/ /g, "_")}}${currentEmailSubject.substring(cursorPosition)}`;
|
||||
form.setValue(`steps.${step.stepNumber - 1}.emailSubject`, subjectWithAddedVariable);
|
||||
} else {
|
||||
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 testActionMutation = trpc.viewer.workflows.testAction.useMutation({
|
||||
onSuccess: async () => {
|
||||
showToast(t("notification_sent"), "success");
|
||||
},
|
||||
onError: (err) => {
|
||||
if (err instanceof HttpError) {
|
||||
const message = `${err.statusCode}: ${err.message}`;
|
||||
showToast(message, "error");
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
//trigger
|
||||
if (!step) {
|
||||
const trigger = form.getValues("trigger");
|
||||
const triggerString = t(`${trigger.toLowerCase()}_trigger`);
|
||||
|
||||
const selectedTrigger = {
|
||||
label: triggerString.charAt(0).toUpperCase() + triggerString.slice(1),
|
||||
value: trigger,
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="flex justify-center">
|
||||
<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>
|
||||
<div className="my-7 border-t border-gray-200" />
|
||||
<Label>{t("when")}</Label>
|
||||
<Controller
|
||||
name="trigger"
|
||||
control={form.control}
|
||||
render={() => {
|
||||
return (
|
||||
<Select
|
||||
isSearchable={false}
|
||||
className="text-sm"
|
||||
onChange={(val) => {
|
||||
if (val) {
|
||||
form.setValue("trigger", val.value);
|
||||
if (
|
||||
val.value === WorkflowTriggerEvents.BEFORE_EVENT ||
|
||||
val.value === WorkflowTriggerEvents.AFTER_EVENT
|
||||
) {
|
||||
setShowTimeSection(true);
|
||||
if (val.value === WorkflowTriggerEvents.AFTER_EVENT) {
|
||||
setShowTimeSectionAfter(true);
|
||||
} else {
|
||||
setShowTimeSectionAfter(false);
|
||||
}
|
||||
form.setValue("time", 24);
|
||||
form.setValue("timeUnit", TimeUnit.HOUR);
|
||||
} else {
|
||||
setShowTimeSection(false);
|
||||
setShowTimeSectionAfter(false);
|
||||
form.unregister("time");
|
||||
form.unregister("timeUnit");
|
||||
}
|
||||
}
|
||||
}}
|
||||
defaultValue={selectedTrigger}
|
||||
options={triggerOptions}
|
||||
/>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
{showTimeSection && (
|
||||
<div className="mt-5">
|
||||
<Label>{showTimeSectionAfter ? t("how_long_after") : t("how_long_before")}</Label>
|
||||
<TimeTimeUnitInput form={form} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
if (step && step.action) {
|
||||
const actionString = t(`${step.action.toLowerCase()}_action`);
|
||||
|
||||
const selectedAction = {
|
||||
label: actionString.charAt(0).toUpperCase() + actionString.slice(1),
|
||||
value: step.action,
|
||||
};
|
||||
|
||||
const selectedTemplate = { label: t(`${step.template.toLowerCase()}`), value: step.template };
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="my-3 flex justify-center">
|
||||
<Icon.FiArrowDown className="stroke-[1.5px] text-3xl text-gray-500" />
|
||||
</div>
|
||||
<div className="flex justify-center">
|
||||
<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>
|
||||
<div className="my-7 border-t border-gray-200" />
|
||||
<div>
|
||||
<Label>{t("do_this")}</Label>
|
||||
<Controller
|
||||
name={`steps.${step.stepNumber - 1}.action`}
|
||||
control={form.control}
|
||||
render={() => {
|
||||
return (
|
||||
<Select
|
||||
isSearchable={false}
|
||||
className="text-sm"
|
||||
onChange={(val) => {
|
||||
if (val) {
|
||||
if (val.value === WorkflowActions.SMS_NUMBER) {
|
||||
setIsPhoneNumberNeeded(true);
|
||||
setIsSenderIdNeeded(true);
|
||||
setIsEmailAddressNeeded(false);
|
||||
} else if (val.value === WorkflowActions.EMAIL_ADDRESS) {
|
||||
setIsEmailAddressNeeded(true);
|
||||
setIsPhoneNumberNeeded(false);
|
||||
setIsSenderIdNeeded(false);
|
||||
} else if (val.value === WorkflowActions.SMS_ATTENDEE) {
|
||||
setIsSenderIdNeeded(true);
|
||||
setIsEmailAddressNeeded(false);
|
||||
setIsPhoneNumberNeeded(false);
|
||||
} else {
|
||||
setIsEmailAddressNeeded(false);
|
||||
setIsPhoneNumberNeeded(false);
|
||||
setIsSenderIdNeeded(false);
|
||||
}
|
||||
form.unregister(`steps.${step.stepNumber - 1}.sendTo`);
|
||||
form.clearErrors(`steps.${step.stepNumber - 1}.sendTo`);
|
||||
if (
|
||||
val.value === WorkflowActions.EMAIL_ATTENDEE ||
|
||||
val.value === WorkflowActions.EMAIL_HOST ||
|
||||
val.value === WorkflowActions.EMAIL_ADDRESS
|
||||
) {
|
||||
setIsEmailSubjectNeeded(true);
|
||||
} else {
|
||||
setIsEmailSubjectNeeded(false);
|
||||
}
|
||||
form.setValue(`steps.${step.stepNumber - 1}.action`, val.value);
|
||||
}
|
||||
}}
|
||||
defaultValue={selectedAction}
|
||||
options={
|
||||
isFreeUser
|
||||
? actionOptions.filter(
|
||||
(actionOption) =>
|
||||
actionOption.value !== WorkflowActions.SMS_ATTENDEE &&
|
||||
actionOption.value !== WorkflowActions.SMS_NUMBER
|
||||
)
|
||||
: actionOptions
|
||||
}
|
||||
/>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
{(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"
|
||||
required
|
||||
/>
|
||||
{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"
|
||||
placeholder="Cal"
|
||||
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>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</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)
|
||||
}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
</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>
|
||||
)}
|
||||
<div className="mt-5">
|
||||
<Label>{t("message_template")}</Label>
|
||||
<Controller
|
||||
name={`steps.${step.stepNumber - 1}.template`}
|
||||
control={form.control}
|
||||
render={() => {
|
||||
return (
|
||||
<Select
|
||||
isSearchable={false}
|
||||
className="text-sm"
|
||||
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 && (
|
||||
<div className="mt-2 rounded-md bg-gray-50 p-4 pt-2 md:p-6 md:pt-4">
|
||||
{isEmailSubjectNeeded && (
|
||||
<div className="mb-5">
|
||||
<div className="mb-2 flex items-center">
|
||||
<Label className="mb-0 flex-none">{t("subject")}</Label>
|
||||
<div className="flex-grow text-right">
|
||||
<AddVariablesDropdown addVariable={addVariable} isEmailSubject={true} />
|
||||
</div>
|
||||
</div>
|
||||
<TextArea
|
||||
ref={(e) => {
|
||||
emailSubjectFormRef?.(e);
|
||||
refEmailSubject.current = e;
|
||||
}}
|
||||
className="my-0"
|
||||
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>
|
||||
)}
|
||||
<div className="mb-2 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}
|
||||
/>
|
||||
{form.formState.errors.steps &&
|
||||
form.formState?.errors?.steps[step.stepNumber - 1]?.reminderBody && (
|
||||
<p className="mt-1 text-xs text-red-500">
|
||||
{form.formState?.errors?.steps[step.stepNumber - 1]?.reminderBody?.message || ""}
|
||||
</p>
|
||||
)}
|
||||
<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>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{form.getValues(`steps.${step.stepNumber - 1}.action`) !== WorkflowActions.SMS_ATTENDEE && (
|
||||
<Button
|
||||
type="button"
|
||||
className="mt-7 w-full"
|
||||
onClick={() => {
|
||||
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;
|
||||
}
|
||||
if (
|
||||
form.getValues(`steps.${step.stepNumber - 1}.template`) === WorkflowTemplates.CUSTOM
|
||||
) {
|
||||
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 }
|
||||
);
|
||||
|
||||
testActionMutation.mutate({
|
||||
action: step.action,
|
||||
emailSubject,
|
||||
reminderBody,
|
||||
template: step.template,
|
||||
sender: step.sender || "Cal",
|
||||
});
|
||||
} else {
|
||||
const isNumberValid =
|
||||
form.formState.errors.steps &&
|
||||
form.formState?.errors?.steps[step.stepNumber - 1]?.sendTo
|
||||
? false
|
||||
: true;
|
||||
|
||||
if (isPhoneNumberNeeded && isNumberValid && !isEmpty) {
|
||||
setConfirmationDialogOpen(true);
|
||||
}
|
||||
}
|
||||
}}
|
||||
color="secondary">
|
||||
<div className="w-full">{t("test_action")}</div>
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<Dialog open={confirmationDialogOpen} onOpenChange={setConfirmationDialogOpen}>
|
||||
<ConfirmationDialogContent
|
||||
variety="warning"
|
||||
title={t("test_workflow_action")}
|
||||
confirmBtnText={t("send_sms")}
|
||||
onConfirm={(e) => {
|
||||
e.preventDefault();
|
||||
const reminderBody = translateVariablesToEnglish(
|
||||
form.getValues(`steps.${step.stepNumber - 1}.reminderBody`) || "",
|
||||
{ locale: i18n.language, t }
|
||||
);
|
||||
|
||||
testActionMutation.mutate({
|
||||
action: step.action,
|
||||
emailSubject: "",
|
||||
reminderBody: reminderBody || "",
|
||||
template: step.template,
|
||||
sendTo: step.sendTo || "",
|
||||
});
|
||||
setConfirmationDialogOpen(false);
|
||||
}}>
|
||||
{t("send_sms_to_number", { number: form.getValues(`steps.${step.stepNumber - 1}.sendTo`) })}
|
||||
</ConfirmationDialogContent>
|
||||
</Dialog>
|
||||
<Dialog open={isAdditionalInputsDialogOpen} onOpenChange={setIsAdditionalInputsDialogOpen}>
|
||||
<DialogContent useOwnActionButtons type="creation" className="sm:max-w-[610px] md:h-[570px]">
|
||||
<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">
|
||||
<DialogClose asChild>
|
||||
<Button color="primary" type="button">
|
||||
{t("close")}
|
||||
</Button>
|
||||
</DialogClose>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
return <></>;
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import { WorkflowActions, WorkflowStep } from "@prisma/client";
|
||||
|
||||
import { classNames } from "@calcom/lib";
|
||||
import { Icon } from "@calcom/ui/Icon";
|
||||
import { Icon } from "@calcom/ui";
|
||||
|
||||
export function getActionIcon(steps: WorkflowStep[], className?: string): JSX.Element {
|
||||
if (steps.length === 0) {
|
||||
|
||||
@@ -1,45 +1,69 @@
|
||||
import { useSession } from "next-auth/react";
|
||||
import { useRouter } from "next/router";
|
||||
|
||||
import LicenseRequired from "@calcom/features/ee/common/components/LicenseRequired";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { HttpError } from "@calcom/lib/http-error";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import useMeQuery from "@calcom/trpc/react/hooks/useMeQuery";
|
||||
import { Alert } from "@calcom/ui/Alert";
|
||||
import Loader from "@calcom/ui/Loader";
|
||||
import Shell from "@calcom/ui/Shell";
|
||||
import { Button, Icon, Shell, showToast } from "@calcom/ui";
|
||||
|
||||
import { NewWorkflowButton } from "../components/NewWorkflowButton";
|
||||
import LicenseRequired from "../../common/components/v2/LicenseRequired";
|
||||
import SkeletonLoader from "../components/SkeletonLoaderList";
|
||||
import WorkflowList from "../components/WorkflowListPage";
|
||||
|
||||
function WorkflowsPage() {
|
||||
const { t } = useLocale();
|
||||
|
||||
const session = useSession();
|
||||
|
||||
const me = useMeQuery();
|
||||
const isFreeUser = me.data?.plan === "FREE";
|
||||
const router = useRouter();
|
||||
|
||||
const { data, isLoading } = trpc.viewer.workflows.list.useQuery();
|
||||
|
||||
return (
|
||||
const createMutation = trpc.viewer.workflows.createV2.useMutation({
|
||||
onSuccess: async ({ workflow }) => {
|
||||
await router.replace("/workflows/" + workflow.id);
|
||||
},
|
||||
onError: (err) => {
|
||||
if (err instanceof HttpError) {
|
||||
const message = `${err.statusCode}: ${err.message}`;
|
||||
showToast(message, "error");
|
||||
}
|
||||
|
||||
if (err.data?.code === "UNAUTHORIZED") {
|
||||
const message = `${err.data.code}: You are not able to create this workflow`;
|
||||
showToast(message, "error");
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
return session.data ? (
|
||||
<Shell
|
||||
heading={t("workflows")}
|
||||
subtitle={t("workflows_to_automate_notifications")}
|
||||
CTA={session.data?.hasValidLicense && !isFreeUser ? <NewWorkflowButton /> : <></>}>
|
||||
heading={data?.workflows.length ? t("workflows") : undefined}
|
||||
title={t("workflows")}
|
||||
subtitle={data?.workflows.length ? t("workflows_to_automate_notifications") : ""}
|
||||
CTA={
|
||||
session.data?.hasValidLicense && data?.workflows && data?.workflows.length > 0 ? (
|
||||
<Button
|
||||
StartIcon={Icon.FiPlus}
|
||||
onClick={() => createMutation.mutate()}
|
||||
loading={createMutation.isLoading}>
|
||||
{t("new")}
|
||||
</Button>
|
||||
) : (
|
||||
<></>
|
||||
)
|
||||
}>
|
||||
<LicenseRequired>
|
||||
{isLoading ? (
|
||||
<Loader />
|
||||
<SkeletonLoader />
|
||||
) : (
|
||||
<>
|
||||
{isFreeUser ? (
|
||||
<Alert className="border " severity="warning" title={t("pro_feature_workflows")} />
|
||||
) : (
|
||||
<WorkflowList workflows={data?.workflows} />
|
||||
)}
|
||||
<WorkflowList workflows={data?.workflows} />
|
||||
</>
|
||||
)}
|
||||
</LicenseRequired>
|
||||
</Shell>
|
||||
) : (
|
||||
<></>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
import { useSession } from "next-auth/react";
|
||||
import { useRouter } from "next/router";
|
||||
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { HttpError } from "@calcom/lib/http-error";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import { Icon } from "@calcom/ui";
|
||||
import { Button } from "@calcom/ui/components";
|
||||
import { showToast } from "@calcom/ui/v2";
|
||||
import Shell from "@calcom/ui/v2/core/Shell";
|
||||
|
||||
import LicenseRequired from "../../../common/components/v2/LicenseRequired";
|
||||
import SkeletonLoader from "../../components/v2/SkeletonLoaderList";
|
||||
import WorkflowList from "../../components/v2/WorkflowListPage";
|
||||
|
||||
function WorkflowsPage() {
|
||||
const { t } = useLocale();
|
||||
|
||||
const session = useSession();
|
||||
const router = useRouter();
|
||||
|
||||
const { data, isLoading } = trpc.viewer.workflows.list.useQuery();
|
||||
|
||||
const createMutation = trpc.viewer.workflows.createV2.useMutation({
|
||||
onSuccess: async ({ workflow }) => {
|
||||
await router.replace("/workflows/" + workflow.id);
|
||||
},
|
||||
onError: (err) => {
|
||||
if (err instanceof HttpError) {
|
||||
const message = `${err.statusCode}: ${err.message}`;
|
||||
showToast(message, "error");
|
||||
}
|
||||
|
||||
if (err.data?.code === "UNAUTHORIZED") {
|
||||
const message = `${err.data.code}: You are not able to create this workflow`;
|
||||
showToast(message, "error");
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
return session.data ? (
|
||||
<Shell
|
||||
heading={data?.workflows.length ? t("workflows") : undefined}
|
||||
title={t("workflows")}
|
||||
subtitle={data?.workflows.length ? t("workflows_to_automate_notifications") : ""}
|
||||
CTA={
|
||||
session.data?.hasValidLicense && data?.workflows && data?.workflows.length > 0 ? (
|
||||
<Button
|
||||
StartIcon={Icon.FiPlus}
|
||||
onClick={() => createMutation.mutate()}
|
||||
loading={createMutation.isLoading}>
|
||||
{t("new")}
|
||||
</Button>
|
||||
) : (
|
||||
<></>
|
||||
)
|
||||
}>
|
||||
<LicenseRequired>
|
||||
{isLoading ? (
|
||||
<SkeletonLoader />
|
||||
) : (
|
||||
<>
|
||||
<WorkflowList workflows={data?.workflows} />
|
||||
</>
|
||||
)}
|
||||
</LicenseRequired>
|
||||
</Shell>
|
||||
) : (
|
||||
<></>
|
||||
);
|
||||
}
|
||||
|
||||
export default WorkflowsPage;
|
||||
@@ -1,246 +0,0 @@
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import {
|
||||
TimeUnit,
|
||||
WorkflowActions,
|
||||
WorkflowStep,
|
||||
WorkflowTemplates,
|
||||
WorkflowTriggerEvents,
|
||||
} from "@prisma/client";
|
||||
import { isValidPhoneNumber } from "libphonenumber-js";
|
||||
import { useSession } from "next-auth/react";
|
||||
import { useRouter } from "next/router";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useForm } from "react-hook-form";
|
||||
import { z } from "zod";
|
||||
|
||||
import { classNames } from "@calcom/lib";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { HttpError } from "@calcom/lib/http-error";
|
||||
import { stringOrNumber } from "@calcom/prisma/zod-utils";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import { Button, Form } from "@calcom/ui/components";
|
||||
import { Option } from "@calcom/ui/form/MultiSelectCheckboxes";
|
||||
import { showToast, Alert } from "@calcom/ui/v2";
|
||||
import Shell from "@calcom/ui/v2/core/Shell";
|
||||
|
||||
import LicenseRequired from "../../../common/components/v2/LicenseRequired";
|
||||
import SkeletonLoader from "../../components/v2/SkeletonLoaderEdit";
|
||||
import WorkflowDetailsPage from "../../components/v2/WorkflowDetailsPage";
|
||||
import { getTranslatedText } from "../../lib/variableTranslations";
|
||||
import { translateVariablesToEnglish } from "../../lib/variableTranslations";
|
||||
|
||||
export type FormValues = {
|
||||
name: string;
|
||||
activeOn: Option[];
|
||||
steps: WorkflowStep[];
|
||||
trigger: WorkflowTriggerEvents;
|
||||
time?: number;
|
||||
timeUnit?: TimeUnit;
|
||||
};
|
||||
|
||||
export function onlyLettersNumbersSpaces(str: string) {
|
||||
if (str.length <= 11 && /^[A-Za-z0-9\s]*$/.test(str)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const formSchema = z.object({
|
||||
name: z.string(),
|
||||
activeOn: z.object({ value: z.string(), label: z.string() }).array(),
|
||||
trigger: z.nativeEnum(WorkflowTriggerEvents),
|
||||
time: z.number().gte(0).optional(),
|
||||
timeUnit: z.nativeEnum(TimeUnit).optional(),
|
||||
steps: z
|
||||
.object({
|
||||
id: z.number(),
|
||||
stepNumber: z.number(),
|
||||
action: z.nativeEnum(WorkflowActions),
|
||||
workflowId: z.number(),
|
||||
reminderBody: z.string().nullable(),
|
||||
emailSubject: z.string().nullable(),
|
||||
template: z.nativeEnum(WorkflowTemplates),
|
||||
numberRequired: z.boolean().nullable(),
|
||||
sendTo: z
|
||||
.string()
|
||||
.refine((val) => isValidPhoneNumber(val) || val.includes("@"))
|
||||
.nullable(),
|
||||
sender: z
|
||||
.string()
|
||||
.refine((val) => onlyLettersNumbersSpaces(val))
|
||||
.optional()
|
||||
.nullable(),
|
||||
})
|
||||
.array(),
|
||||
});
|
||||
|
||||
const querySchema = z.object({
|
||||
workflow: stringOrNumber,
|
||||
});
|
||||
|
||||
function WorkflowPage() {
|
||||
const { t, i18n } = useLocale();
|
||||
const session = useSession();
|
||||
const router = useRouter();
|
||||
|
||||
const [selectedEventTypes, setSelectedEventTypes] = useState<Option[]>([]);
|
||||
const [isAllDataLoaded, setIsAllDataLoaded] = useState(false);
|
||||
|
||||
const form = useForm<FormValues>({
|
||||
mode: "onBlur",
|
||||
resolver: zodResolver(formSchema),
|
||||
});
|
||||
|
||||
const { workflow: workflowId } = router.isReady ? querySchema.parse(router.query) : { workflow: -1 };
|
||||
const utils = trpc.useContext();
|
||||
|
||||
const {
|
||||
data: workflow,
|
||||
isError,
|
||||
error,
|
||||
} = trpc.viewer.workflows.get.useQuery(
|
||||
{ id: +workflowId },
|
||||
{
|
||||
enabled: router.isReady && !!workflowId,
|
||||
}
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (workflow) {
|
||||
setSelectedEventTypes(
|
||||
workflow.activeOn.map((active) => ({
|
||||
value: String(active.eventType.id),
|
||||
label: active.eventType.title,
|
||||
})) || []
|
||||
);
|
||||
const activeOn = workflow.activeOn
|
||||
? workflow.activeOn.map((active) => ({
|
||||
value: active.eventType.id.toString(),
|
||||
label: active.eventType.slug,
|
||||
}))
|
||||
: undefined;
|
||||
|
||||
//translate dynamic variables into local language
|
||||
const steps = workflow.steps.map((step) => {
|
||||
const updatedStep = step;
|
||||
if (step.reminderBody) {
|
||||
updatedStep.reminderBody = getTranslatedText(step.reminderBody || "", {
|
||||
locale: i18n.language,
|
||||
t,
|
||||
});
|
||||
}
|
||||
if (step.emailSubject) {
|
||||
updatedStep.emailSubject = getTranslatedText(step.emailSubject || "", {
|
||||
locale: i18n.language,
|
||||
t,
|
||||
});
|
||||
}
|
||||
return updatedStep;
|
||||
});
|
||||
|
||||
form.setValue("name", workflow.name);
|
||||
form.setValue("steps", steps);
|
||||
form.setValue("trigger", workflow.trigger);
|
||||
form.setValue("time", workflow.time || undefined);
|
||||
form.setValue("timeUnit", workflow.timeUnit || undefined);
|
||||
form.setValue("activeOn", activeOn || []);
|
||||
setIsAllDataLoaded(true);
|
||||
}
|
||||
}, [workflow]);
|
||||
|
||||
const updateMutation = trpc.viewer.workflows.update.useMutation({
|
||||
onSuccess: async ({ workflow }) => {
|
||||
if (workflow) {
|
||||
utils.viewer.workflows.get.setData({ id: +workflow.id }, workflow);
|
||||
|
||||
showToast(
|
||||
t("workflow_updated_successfully", {
|
||||
workflowName: workflow.name,
|
||||
}),
|
||||
"success"
|
||||
);
|
||||
}
|
||||
await router.push("/workflows");
|
||||
},
|
||||
onError: (err) => {
|
||||
if (err instanceof HttpError) {
|
||||
const message = `${err.statusCode}: ${err.message}`;
|
||||
showToast(message, "error");
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
return session.data ? (
|
||||
<Form
|
||||
form={form}
|
||||
handleSubmit={async (values) => {
|
||||
let activeOnEventTypeIds: number[] = [];
|
||||
|
||||
values.steps.forEach((step) => {
|
||||
if (step.reminderBody) {
|
||||
step.reminderBody = translateVariablesToEnglish(step.reminderBody, { locale: i18n.language, t });
|
||||
}
|
||||
if (step.emailSubject) {
|
||||
step.emailSubject = translateVariablesToEnglish(step.emailSubject, { locale: i18n.language, t });
|
||||
}
|
||||
});
|
||||
|
||||
if (values.activeOn) {
|
||||
activeOnEventTypeIds = values.activeOn.map((option) => {
|
||||
return parseInt(option.value, 10);
|
||||
});
|
||||
}
|
||||
updateMutation.mutate({
|
||||
id: parseInt(router.query.workflow as string, 10),
|
||||
name: values.name,
|
||||
activeOn: activeOnEventTypeIds,
|
||||
steps: values.steps,
|
||||
trigger: values.trigger,
|
||||
time: values.time || null,
|
||||
timeUnit: values.timeUnit || null,
|
||||
});
|
||||
}}>
|
||||
<Shell
|
||||
backPath="/workflows"
|
||||
title={workflow && workflow.name ? workflow.name : "Untitled"}
|
||||
CTA={
|
||||
<div>
|
||||
<Button type="submit">{t("save")}</Button>
|
||||
</div>
|
||||
}
|
||||
heading={
|
||||
session.data?.hasValidLicense &&
|
||||
isAllDataLoaded && (
|
||||
<div className={classNames(workflow && !workflow.name ? "text-gray-400" : "")}>
|
||||
{workflow && workflow.name ? workflow.name : "untitled"}
|
||||
</div>
|
||||
)
|
||||
}>
|
||||
<LicenseRequired>
|
||||
{!isError ? (
|
||||
<>
|
||||
{isAllDataLoaded ? (
|
||||
<>
|
||||
<WorkflowDetailsPage
|
||||
form={form}
|
||||
workflowId={+workflowId}
|
||||
selectedEventTypes={selectedEventTypes}
|
||||
setSelectedEventTypes={setSelectedEventTypes}
|
||||
/>
|
||||
</>
|
||||
) : (
|
||||
<SkeletonLoader />
|
||||
)}
|
||||
</>
|
||||
) : (
|
||||
<Alert severity="error" title="Something went wrong" message={error.message} />
|
||||
)}
|
||||
</LicenseRequired>
|
||||
</Shell>
|
||||
</Form>
|
||||
) : (
|
||||
<></>
|
||||
);
|
||||
}
|
||||
|
||||
export default WorkflowPage;
|
||||
@@ -13,18 +13,18 @@ import { useEffect, useState } from "react";
|
||||
import { useForm } from "react-hook-form";
|
||||
import { z } from "zod";
|
||||
|
||||
import { classNames } from "@calcom/lib";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { HttpError } from "@calcom/lib/http-error";
|
||||
import { stringOrNumber } from "@calcom/prisma/zod-utils";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import useMeQuery from "@calcom/trpc/react/hooks/useMeQuery";
|
||||
import { Alert } from "@calcom/ui/Alert";
|
||||
import { Icon } from "@calcom/ui/Icon";
|
||||
import Loader from "@calcom/ui/Loader";
|
||||
import Shell from "@calcom/ui/Shell";
|
||||
import { Option } from "@calcom/ui/form/MultiSelectCheckboxes";
|
||||
import type { MultiSelectCheckboxesOptionType as Option } from "@calcom/ui";
|
||||
import { Alert, Button, Form, Shell, showToast } from "@calcom/ui";
|
||||
|
||||
import LicenseRequired from "../../common/components/LicenseRequired";
|
||||
import LicenseRequired from "../../common/components/v2/LicenseRequired";
|
||||
import SkeletonLoader from "../components/SkeletonLoaderEdit";
|
||||
import WorkflowDetailsPage from "../components/WorkflowDetailsPage";
|
||||
import { getTranslatedText, translateVariablesToEnglish } from "../lib/variableTranslations";
|
||||
|
||||
export type FormValues = {
|
||||
name: string;
|
||||
@@ -35,6 +35,13 @@ export type FormValues = {
|
||||
timeUnit?: TimeUnit;
|
||||
};
|
||||
|
||||
export function onlyLettersNumbersSpaces(str: string) {
|
||||
if (str.length <= 11 && /^[A-Za-z0-9\s]*$/.test(str)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const formSchema = z.object({
|
||||
name: z.string(),
|
||||
activeOn: z.object({ value: z.string(), label: z.string() }).array(),
|
||||
@@ -50,9 +57,15 @@ const formSchema = z.object({
|
||||
reminderBody: z.string().nullable(),
|
||||
emailSubject: z.string().nullable(),
|
||||
template: z.nativeEnum(WorkflowTemplates),
|
||||
numberRequired: z.boolean().nullable(),
|
||||
sendTo: z
|
||||
.string()
|
||||
.refine((val) => isValidPhoneNumber(val))
|
||||
.refine((val) => isValidPhoneNumber(val) || val.includes("@"))
|
||||
.nullable(),
|
||||
sender: z
|
||||
.string()
|
||||
.refine((val) => onlyLettersNumbersSpaces(val))
|
||||
.optional()
|
||||
.nullable(),
|
||||
})
|
||||
.array(),
|
||||
@@ -63,26 +76,25 @@ const querySchema = z.object({
|
||||
});
|
||||
|
||||
function WorkflowPage() {
|
||||
const { t } = useLocale();
|
||||
const { t, i18n } = useLocale();
|
||||
const session = useSession();
|
||||
const router = useRouter();
|
||||
const me = useMeQuery();
|
||||
const isFreeUser = me.data?.plan === "FREE";
|
||||
|
||||
const [editIcon, setEditIcon] = useState(true);
|
||||
const [selectedEventTypes, setSelectedEventTypes] = useState<Option[]>([]);
|
||||
const [isAllDataLoaded, setIsAllDataLoaded] = useState(false);
|
||||
|
||||
const form = useForm<FormValues>({
|
||||
mode: "onBlur",
|
||||
resolver: zodResolver(formSchema),
|
||||
});
|
||||
|
||||
const { workflow: workflowId } = router.isReady ? querySchema.parse(router.query) : { workflow: -1 };
|
||||
const utils = trpc.useContext();
|
||||
|
||||
const {
|
||||
data: workflow,
|
||||
isError,
|
||||
error,
|
||||
dataUpdatedAt,
|
||||
} = trpc.viewer.workflows.get.useQuery(
|
||||
{ id: +workflowId },
|
||||
{
|
||||
@@ -91,7 +103,7 @@ function WorkflowPage() {
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (workflow && !form.getValues("name")) {
|
||||
if (workflow) {
|
||||
setSelectedEventTypes(
|
||||
workflow.activeOn.map((active) => ({
|
||||
value: String(active.eventType.id),
|
||||
@@ -104,80 +116,127 @@ function WorkflowPage() {
|
||||
label: active.eventType.slug,
|
||||
}))
|
||||
: undefined;
|
||||
|
||||
//translate dynamic variables into local language
|
||||
const steps = workflow.steps.map((step) => {
|
||||
const updatedStep = step;
|
||||
if (step.reminderBody) {
|
||||
updatedStep.reminderBody = getTranslatedText(step.reminderBody || "", {
|
||||
locale: i18n.language,
|
||||
t,
|
||||
});
|
||||
}
|
||||
if (step.emailSubject) {
|
||||
updatedStep.emailSubject = getTranslatedText(step.emailSubject || "", {
|
||||
locale: i18n.language,
|
||||
t,
|
||||
});
|
||||
}
|
||||
return updatedStep;
|
||||
});
|
||||
|
||||
form.setValue("name", workflow.name);
|
||||
form.setValue("steps", workflow.steps);
|
||||
form.setValue("steps", steps);
|
||||
form.setValue("trigger", workflow.trigger);
|
||||
form.setValue("time", workflow.time || undefined);
|
||||
form.setValue("timeUnit", workflow.timeUnit || undefined);
|
||||
form.setValue("activeOn", activeOn || []);
|
||||
setIsAllDataLoaded(true);
|
||||
}
|
||||
}, [dataUpdatedAt]);
|
||||
}, [workflow]);
|
||||
|
||||
return (
|
||||
<Shell
|
||||
title="Title"
|
||||
heading={
|
||||
session.data?.hasValidLicense &&
|
||||
isAllDataLoaded && (
|
||||
<div className="group relative cursor-pointer" onClick={() => setEditIcon(false)}>
|
||||
{editIcon ? (
|
||||
<>
|
||||
<h1
|
||||
style={{ fontSize: 22, letterSpacing: "-0.0009em" }}
|
||||
className="inline pl-0 text-gray-900 focus:text-black group-hover:text-gray-500">
|
||||
{form.getValues("name") && form.getValues("name") !== ""
|
||||
? form.getValues("name")
|
||||
: workflow?.name}
|
||||
</h1>
|
||||
<Icon.FiEdit2 className="ml-1 -mt-1 inline h-4 w-4 text-gray-700 group-hover:text-gray-500" />
|
||||
</>
|
||||
) : (
|
||||
<div style={{ marginBottom: -11 }}>
|
||||
<input
|
||||
type="text"
|
||||
autoFocus
|
||||
style={{ top: -6, fontSize: 22 }}
|
||||
required
|
||||
className="relative h-10 w-full cursor-pointer border-none bg-transparent pl-0 text-gray-900 hover:text-gray-700 focus:text-black focus:outline-none focus:ring-0"
|
||||
placeholder={t("Custom workflow")}
|
||||
{...form.register("name")}
|
||||
defaultValue={workflow?.name}
|
||||
onBlur={() => {
|
||||
setEditIcon(true);
|
||||
form.getValues("name") === "" && form.setValue("name", workflow?.name || "");
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
const updateMutation = trpc.viewer.workflows.update.useMutation({
|
||||
onSuccess: async ({ workflow }) => {
|
||||
if (workflow) {
|
||||
utils.viewer.workflows.get.setData({ id: +workflow.id }, workflow);
|
||||
|
||||
showToast(
|
||||
t("workflow_updated_successfully", {
|
||||
workflowName: workflow.name,
|
||||
}),
|
||||
"success"
|
||||
);
|
||||
}
|
||||
await router.push("/workflows");
|
||||
},
|
||||
onError: (err) => {
|
||||
if (err instanceof HttpError) {
|
||||
const message = `${err.statusCode}: ${err.message}`;
|
||||
showToast(message, "error");
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
return session.data ? (
|
||||
<Form
|
||||
form={form}
|
||||
handleSubmit={async (values) => {
|
||||
let activeOnEventTypeIds: number[] = [];
|
||||
|
||||
values.steps.forEach((step) => {
|
||||
if (step.reminderBody) {
|
||||
step.reminderBody = translateVariablesToEnglish(step.reminderBody, { locale: i18n.language, t });
|
||||
}
|
||||
if (step.emailSubject) {
|
||||
step.emailSubject = translateVariablesToEnglish(step.emailSubject, { locale: i18n.language, t });
|
||||
}
|
||||
});
|
||||
|
||||
if (values.activeOn) {
|
||||
activeOnEventTypeIds = values.activeOn.map((option) => {
|
||||
return parseInt(option.value, 10);
|
||||
});
|
||||
}
|
||||
updateMutation.mutate({
|
||||
id: parseInt(router.query.workflow as string, 10),
|
||||
name: values.name,
|
||||
activeOn: activeOnEventTypeIds,
|
||||
steps: values.steps,
|
||||
trigger: values.trigger,
|
||||
time: values.time || null,
|
||||
timeUnit: values.timeUnit || null,
|
||||
});
|
||||
}}>
|
||||
<Shell
|
||||
backPath="/workflows"
|
||||
title={workflow && workflow.name ? workflow.name : "Untitled"}
|
||||
CTA={
|
||||
<div>
|
||||
<Button type="submit">{t("save")}</Button>
|
||||
</div>
|
||||
)
|
||||
}>
|
||||
<LicenseRequired>
|
||||
{isFreeUser ? (
|
||||
<Alert className="border " severity="warning" title={t("pro_feature_workflows")} />
|
||||
) : (
|
||||
<>
|
||||
{!isError ? (
|
||||
<>
|
||||
{isAllDataLoaded ? (
|
||||
}
|
||||
heading={
|
||||
session.data?.hasValidLicense &&
|
||||
isAllDataLoaded && (
|
||||
<div className={classNames(workflow && !workflow.name ? "text-gray-400" : "")}>
|
||||
{workflow && workflow.name ? workflow.name : "untitled"}
|
||||
</div>
|
||||
)
|
||||
}>
|
||||
<LicenseRequired>
|
||||
{!isError ? (
|
||||
<>
|
||||
{isAllDataLoaded ? (
|
||||
<>
|
||||
<WorkflowDetailsPage
|
||||
form={form}
|
||||
workflowId={+workflowId}
|
||||
selectedEventTypes={selectedEventTypes}
|
||||
setSelectedEventTypes={setSelectedEventTypes}
|
||||
/>
|
||||
) : (
|
||||
<Loader />
|
||||
)}
|
||||
</>
|
||||
) : (
|
||||
<Alert severity="error" title="Something went wrong" message={error.message} />
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</LicenseRequired>
|
||||
</Shell>
|
||||
</>
|
||||
) : (
|
||||
<SkeletonLoader />
|
||||
)}
|
||||
</>
|
||||
) : (
|
||||
<Alert severity="error" title="Something went wrong" message={error.message} />
|
||||
)}
|
||||
</LicenseRequired>
|
||||
</Shell>
|
||||
</Form>
|
||||
) : (
|
||||
<></>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user