feat: workflows v3 UI (#22772)

* early UI refresher of workflows using v3 designs. needs tons of testing, might have broken

* Delete .claude/settings.local.json

* fix: bunch of design fixes, merge conflict fixes

* fix: e2e and type-check

* fix: await button click

* review fixes

* code rabbit fixes

* fix styles in variables dropdown

* fix text truncate

* fix: unit tests

* fix: unit tests

* chore: add missing i18n

* review fixes

* review fixes

* fix testing info message

* move timeSectionText up

* fix which team does this apply to info message

* disable set up agent button with read only

* fix: cal.ai breaking on mobile screen

---------

Co-authored-by: Amit Sharma <[email protected]>
Co-authored-by: Udit Takkar <[email protected]>
Co-authored-by: CarinaWolli <[email protected]>
This commit is contained in:
authored and GitHub committed 2025-09-11 17:01:42 +05:30
1 parent 65f6689025
commit 1d25265c56
20 files changed
+5598 -1082

No files matched your search

@@ -12,7 +12,7 @@ export type AdminLayoutProps = {
children: React.ReactNode;
userRole: UserPermissionRole | "INACTIVE_ADMIN" | undefined;
} & ComponentProps<typeof Shell>;
export default function AdminLayoutAppDirClient({ userRole, children }: AdminLayoutProps) {
export default function AdminLayoutAppDirClient({ children }: AdminLayoutProps) {
const pathname = usePathname();
const isAppsPage = pathname?.startsWith("/settings/admin/apps");
+4 -1
View File
@@ -46,7 +46,8 @@ export function createWorkflowPageFixture(page: Page) {
const saveWorkflow = async () => {
const submitPromise = page.waitForResponse("/api/trpc/workflows/update?batch=1");
await page.getByTestId("save-workflow").click();
const saveButton = await page.getByTestId("save-workflow");
await saveButton.click();
const response = await submitPromise;
expect(response.status()).toBe(200);
const responseData = await response.json();
@@ -61,7 +62,9 @@ export function createWorkflowPageFixture(page: Page) {
};
const fillNameInput = async (name: string) => {
await page.getByTestId("edit-workflow-name-button").click();
await page.getByTestId("workflow-name").fill(name);
await page.keyboard.press("Enter");
};
const editSelectedWorkflow = async (name: string) => {
@@ -846,6 +846,7 @@
"phone_number_subscription_cancelled_successfully": "Phone number subscription canceled successfully",
"updating": "Updating",
"round_robin": "Round Robin",
"hi_how_are_you_doing": "Hi, how are you doing?",
"round_robin_description": "Cycle meetings between multiple team members.",
"managed_event": "Managed Event",
"username_placeholder": "username",
@@ -2341,7 +2342,6 @@
"could_not_charge_card": "Could not charge card for payment.",
"insights": "Insights",
"routing_forms": "Routing Forms",
"testing_workflow_info_message": "When testing this workflow, be aware that Emails and SMS can only be scheduled at least 1 hour in advance",
"insights_no_data_found_for_filter": "No data found for the selected filter or selected dates.",
"acknowledge_booking_no_show_fee": "I acknowledge that if I do not attend this event that a {{amount, currency}} no show fee will be applied to my card.",
"days": "days",
@@ -3594,6 +3594,7 @@
"webhook_trigger_event": "The name of the trigger event (e.g., BOOKING_CREATED, BOOKING_CANCELLED)",
"webhook_created_at": "The time of the webhook",
"webhook_type": "The event type slug",
"set_up_agent": "Set up Agent",
"webhook_title": "The event type name",
"webhook_start_time": "The event's start time",
"webhook_end_time": "The event's end time",
@@ -3652,5 +3653,6 @@
"before_scheduled_start_time": "Before scheduled start time",
"cancel_booking_acknowledge_no_show_fee": "I acknowledge that by cancelling the booking within {{timeValue}} {{timeUnit}} of the start time I will be charged the no show fee of {{amount, currency}}",
"contact_organizer": "If you have any questions, please contact the organizer.",
"testing_sms_workflow_info_message": "When testing this workflow, be aware that SMS need to be scheduled at least 15 minutes in advance",
"ADD_NEW_STRINGS_ABOVE_THIS_LINE_TO_PREVENT_MERGE_CONFLICTS": "↑↑↑↑↑↑↑↑↑↑↑↑↑ Add your new strings above here ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑"
}
+1 -1
View File
@@ -10,8 +10,8 @@ import { describe, it, beforeEach, vi, expect } from "vitest";
import * as handleConfirmationModule from "@calcom/features/bookings/lib/handleConfirmation";
import { BookingStatus } from "@calcom/prisma/enums";
import type { TrpcSessionUser } from "@calcom/trpc/server/types";
import { confirmHandler } from "@calcom/trpc/server/routers/viewer/bookings/confirm.handler";
import type { TrpcSessionUser } from "@calcom/trpc/server/types";
describe("confirmHandler", () => {
beforeEach(() => {
@@ -9,7 +9,7 @@ import { v4 as uuidv4 } from "uuid";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import classNames from "@calcom/ui/classNames";
import { Button } from "@calcom/ui/components/button";
import { FormCard } from "@calcom/ui/components/card";
import { FormCard, FormCardBody } from "@calcom/ui/components/card";
import {
BooleanToggleGroupField,
Label,
@@ -90,7 +90,7 @@ function Field({
router ? { text: router.name, variant: "gray", href: `${appUrl}/form-edit/${router.id}` } : null
}
deleteField={router ? null : deleteField}>
<div className="bg-default border-default w-full gap-3 rounded-2xl border p-3">
<FormCardBody>
<div className="mb-3 w-full">
<TextField
data-testid={`${hookFieldNamespace}.label`}
@@ -211,7 +211,7 @@ function Field({
}}
/>
</div>
</div>
</FormCardBody>
</FormCard>
</div>
);
@@ -1,6 +1,7 @@
"use client";
import { isSupportedCountry } from "libphonenumber-js";
import type { CSSProperties } from "react";
import { useState, useEffect } from "react";
import PhoneInput from "react-phone-input-2";
import "react-phone-input-2/lib/style.css";
@@ -19,6 +20,8 @@ export type PhoneInputProps = {
disabled?: boolean;
onChange: (value: string) => void;
defaultCountry?: string;
inputStyle?: CSSProperties;
flagButtonStyle?: CSSProperties;
};
function BasePhoneInput({
@@ -45,6 +48,7 @@ function BasePhoneInput({
if (value !== sanitized) {
onChange(sanitized);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
if (!isPlatform) {
@@ -97,6 +101,8 @@ function BasePhoneInputWeb({
className = "",
onChange,
value,
inputStyle,
flagButtonStyle,
...rest
}: Omit<PhoneInputProps, "defaultCountry">) {
const defaultCountry = useDefaultCountry();
@@ -122,9 +128,10 @@ function BasePhoneInputWeb({
)}
inputClass="text-sm focus:ring-0 !bg-default text-default placeholder:text-muted"
buttonClass="text-emphasis !bg-default hover:!bg-emphasis"
buttonStyle={{ ...flagButtonStyle }}
searchClass="!text-default !bg-default hover:!bg-emphasis"
dropdownClass="!text-default !bg-default"
inputStyle={{ width: "inherit", border: 0 }}
inputStyle={{ width: "inherit", border: 0, ...inputStyle }}
searchStyle={{
display: "flex",
flexDirection: "row",
@@ -71,6 +71,7 @@ export async function handler(req: NextRequest) {
//cancel reminders for cancelled/rescheduled bookings that are scheduled within the next hour
const remindersToCancel: { referenceId: string | null; id: number }[] = await getAllRemindersToCancel();
//eslint-disable-next-line @typescript-eslint/no-explicit-any
const cancelUpdatePromises: Promise<any>[] = [];
for (const reminder of remindersToCancel) {
@@ -98,6 +99,7 @@ export async function handler(req: NextRequest) {
}
// schedule all unscheduled reminders within the next 72 hours
//eslint-disable-next-line @typescript-eslint/no-explicit-any
const sendEmailPromises: Promise<any>[] = [];
const unscheduledReminders = await getAllUnscheduledReminders();
@@ -3,19 +3,8 @@ import { SkeletonText, SkeletonContainer } from "@calcom/ui/components/skeleton"
function SkeletonLoader() {
return (
<SkeletonContainer>
<div className="ml-2 mt-10 md:flex">
<div className="mr-6 flex flex-col md:flex-none">
<SkeletonText className="h-4 w-28" />
<SkeletonText className="mb-6 mt-2 h-8 w-full md:w-64" />
<SkeletonText className="h-4 w-28" />
<SkeletonText className="mt-2 h-8 w-full md:w-64" />
<SkeletonText className="mt-8 hidden h-0.5 w-full md:block" />
<SkeletonText className="mb-6 mt-8 h-8 w-40" />
</div>
<div className="hidden flex-grow md:flex">
<SkeletonText className="h-64 w-full" />
</div>
</div>
<SkeletonText className="mx-auto my-8 h-48 w-full max-w-4xl" />
<SkeletonText className="mx-auto my-8 h-80 w-full max-w-4xl" />
</SkeletonContainer>
);
}
@@ -1,35 +1,27 @@
import { useRouter, useSearchParams } from "next/navigation";
import { useSearchParams } from "next/navigation";
import type { Dispatch, SetStateAction } from "react";
import { useState, useEffect } from "react";
import type { UseFormReturn } from "react-hook-form";
import { Controller } from "react-hook-form";
import { SENDER_ID, SENDER_NAME, SCANNING_WORKFLOW_STEPS } from "@calcom/lib/constants";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import type { WorkflowPermissions } from "@calcom/lib/server/repository/workflow-permissions";
import type { WorkflowActions } from "@calcom/prisma/enums";
import { WorkflowTemplates } from "@calcom/prisma/enums";
import type { RouterOutputs } from "@calcom/trpc/react";
import { InfoBadge } from "@calcom/ui/components/badge";
import { trpc } from "@calcom/trpc/react";
import { Button } from "@calcom/ui/components/button";
import { FormCard, FormCardBody } from "@calcom/ui/components/card";
import type { MultiSelectCheckboxesOptionType as Option } from "@calcom/ui/components/form";
import { Label, MultiSelectCheckbox, TextField, CheckboxField } from "@calcom/ui/components/form";
import { Icon } from "@calcom/ui/components/icon";
import { isSMSAction, isCalAIAction } from "../lib/actionHelperFunctions";
import { isCalAIAction, isSMSAction } from "../lib/actionHelperFunctions";
import type { FormValues } from "../pages/workflow";
import { AddActionDialog } from "./AddActionDialog";
import { DeleteDialog } from "./DeleteDialog";
import WorkflowStepContainer from "./WorkflowStepContainer";
type User = RouterOutputs["viewer"]["me"]["get"];
interface WorkflowPermissions {
canView: boolean;
canUpdate: boolean;
canDelete: boolean;
readOnly: boolean; // Keep for backward compatibility
}
interface Props {
form: UseFormReturn<FormValues>;
workflowId: number;
@@ -37,43 +29,21 @@ interface Props {
setSelectedOptions: Dispatch<SetStateAction<Option[]>>;
teamId?: number;
user: User;
readOnly: boolean;
isOrg: boolean;
allOptions: Option[];
permissions?: WorkflowPermissions;
onSaveWorkflow?: () => Promise<void>;
permissions: WorkflowPermissions;
}
export default function WorkflowDetailsPage(props: Props) {
const {
form,
workflowId,
selectedOptions,
setSelectedOptions,
teamId,
isOrg,
allOptions,
permissions: _permissions,
} = props;
const { form, workflowId, selectedOptions, setSelectedOptions, teamId, isOrg, allOptions, permissions } =
props;
const { t } = useLocale();
const router = useRouter();
const hasCalAIAction = () => {
const steps = form.getValues("steps") || [];
return steps.some((step) => isCalAIAction(step.action));
};
const permissions = _permissions || {
canView: !teamId ? true : !props.readOnly,
canUpdate: !teamId ? true : !props.readOnly,
canDelete: !teamId ? true : !props.readOnly,
readOnly: !teamId ? false : props.readOnly,
};
const [isAddActionDialogOpen, setIsAddActionDialogOpen] = useState(false);
const [isDeleteStepDialogOpen, setIsDeleteStepDialogOpen] = useState(false);
const [reload, setReload] = useState(false);
const [deleteDialogOpen, setDeleteDialogOpen] = useState(false);
const searchParams = useSearchParams();
const eventTypeId = searchParams?.get("eventTypeId");
@@ -88,6 +58,8 @@ export default function WorkflowDetailsPage(props: Props) {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [eventTypeId]);
const steps = form.getValues("steps") || [];
const addAction = (
action: WorkflowActions,
sendTo?: string,
@@ -129,146 +101,142 @@ export default function WorkflowDetailsPage(props: Props) {
form.setValue("steps", steps);
};
const agentQueriesTrpc = trpc.useQueries((t) =>
steps.map((step, index) => {
const watchedAgentId = form.watch(`steps.${index}.agentId`);
const agentId = step?.agentId ?? watchedAgentId ?? null;
return t.viewer.aiVoiceAgent.get({ id: agentId ?? "" }, { enabled: !!agentId });
})
);
return (
<>
<div className="z-1 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
data-testid="workflow-name"
disabled={props.readOnly}
label={`${t("workflow_name")}:`}
type="text"
{...form.register("name")}
/>
</div>
{isOrg ? (
<div className="flex">
<Label>{t("which_team_apply")}</Label>
<div className="-mt-0.5">
<InfoBadge content={t("team_select_info")} />
<div>
<FormCard
className="border-muted mb-0"
collapsible={false}
label={
<div className="flex items-center gap-2 pb-2 pt-1">
<div className="border-subtle text-subtle ml-1 rounded-lg border p-1">
<Icon name="zap" size="16" />
</div>
<div className="text-sm font-medium leading-none">{t("trigger")}</div>
</div>
) : (
<Label>{t("which_event_type_apply")}</Label>
)}
<Controller
name="activeOn"
control={form.control}
render={() => {
}>
<FormCardBody className="border-muted">
<WorkflowStepContainer
form={form}
user={props.user}
teamId={teamId}
readOnly={permissions.readOnly}
selectedOptions={selectedOptions}
setSelectedOptions={setSelectedOptions}
isOrganization={isOrg}
allOptions={allOptions}
onSaveWorkflow={props.onSaveWorkflow}
/>
</FormCardBody>
</FormCard>
<div className="!mt-0 ml-7 h-3 w-2 border-l" />
{form.getValues("steps") && (
<div className="">
{form.getValues("steps")?.map((step, index) => {
const agentData = agentQueriesTrpc[index]?.data;
const isAgentLoading = agentQueriesTrpc[index]?.isPending;
return (
<MultiSelectCheckbox
options={allOptions}
isDisabled={props.readOnly || form.getValues("selectAll")}
className="w-full md:w-64"
setSelected={setSelectedOptions}
selected={form.getValues("selectAll") ? allOptions : selectedOptions}
setValue={(s: Option[]) => {
form.setValue("activeOn", s);
}}
countText={isOrg ? "count_team" : "nr_event_type"}
/>
<div key={index}>
<FormCard
key={step.id}
className="bg-muted border-muted mb-0"
collapsible={false}
label={
<div className="flex items-center gap-2 pb-2 pt-1">
<div className="border-subtle text-subtle rounded-lg border p-1">
<Icon name="arrow-right" size="16" />
</div>
<div className="text-sm font-medium leading-none">{t("action")}</div>
</div>
}
deleteField={
!permissions.readOnly
? {
color: "destructive",
check: () => true,
disabled: !permissions.canUpdate,
fn: () => {
if (
isCalAIAction(step.action) &&
agentData?.outboundPhoneNumbers &&
agentData.outboundPhoneNumbers.length > 0
) {
setIsDeleteStepDialogOpen(true);
} else {
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);
}
}
},
}
: null
}>
<FormCardBody className="border-muted">
<WorkflowStepContainer
form={form}
user={props.user}
step={step}
reload={reload}
setReload={setReload}
teamId={teamId}
readOnly={permissions.readOnly}
onSaveWorkflow={props.onSaveWorkflow}
setIsDeleteStepDialogOpen={setIsDeleteStepDialogOpen}
isDeleteStepDialogOpen={isDeleteStepDialogOpen}
isAgentLoading={isAgentLoading}
agentData={agentData}
/>
</FormCardBody>
</FormCard>
{index !== form.getValues("steps").length - 1 && (
<div className="border-default !mt-0 ml-7 h-3 w-2 border-l" />
)}
</div>
);
}}
/>
{!hasCalAIAction() && (
<div className="mt-3">
<Controller
name="selectAll"
render={({ field: { value, onChange } }) => (
<CheckboxField
description={isOrg ? t("apply_to_all_teams") : t("apply_to_all_event_types")}
disabled={props.readOnly}
onChange={(e) => {
onChange(e);
if (e.target.value) {
setSelectedOptions(allOptions);
form.setValue("activeOn", allOptions);
}
}}
checked={value}
/>
)}
/>
</div>
)}
<div className="md:border-subtle my-7 border-transparent md:border-t" />
{permissions.canDelete && (
})}
</div>
)}
{!permissions.readOnly && (
<>
<div className="border-default !mt-0 ml-7 h-3 w-2 border-l" />
<Button
type="button"
StartIcon="trash-2"
color="destructive"
className="border"
onClick={() => setDeleteDialogOpen(true)}>
{t("delete_workflow")}
onClick={() => setIsAddActionDialogOpen(true)}
color="secondary"
className="bg-default">
{t("add_action")}
</Button>
)}
<div className="border-subtle my-7 border-t md:border-none" />
</div>
{/* Workflow Trigger Event & Steps */}
<div className="bg-muted border-subtle w-full rounded-md border p-3 py-5 md:ml-3 md:p-8">
{form.getValues("trigger") && (
<div>
<WorkflowStepContainer
form={form}
user={props.user}
teamId={teamId}
readOnly={props.readOnly}
isOrganization={isOrg}
onSaveWorkflow={props.onSaveWorkflow}
/>
</div>
)}
{form.getValues("steps") && (
<>
{form.getValues("steps")?.map((step) => {
return (
<WorkflowStepContainer
key={step.id}
form={form}
user={props.user}
step={step}
reload={reload}
setReload={setReload}
teamId={teamId}
readOnly={props.readOnly}
isOrganization={isOrg}
onSaveWorkflow={props.onSaveWorkflow}
/>
);
})}
</>
)}
{!props.readOnly && (
<>
<div className="my-3 flex justify-center">
<Icon name="arrow-down" className="text-subtle stroke-[1.5px] text-3xl" />
</div>
<div className="flex justify-center">
<Button
type="button"
onClick={() => setIsAddActionDialogOpen(true)}
color="secondary"
className="bg-default">
{t("add_action")}
</Button>
</div>
</>
)}
</div>
</>
)}
</div>
<AddActionDialog
isOpenDialog={isAddActionDialogOpen}
setIsOpenDialog={setIsAddActionDialogOpen}
addAction={addAction}
/>
<DeleteDialog
isOpenDialog={deleteDialogOpen}
setIsOpenDialog={setDeleteDialogOpen}
workflowId={workflowId}
additionalFunction={async () => router.push("/workflows")}
/>
</>
);
}
File diff suppressed because it is too large. Load diff
+177 -69
View File
@@ -5,26 +5,29 @@ import type { WorkflowStep } from "@prisma/client";
import { useSession } from "next-auth/react";
import { useEffect, useState } from "react";
import { useForm } from "react-hook-form";
import { Toaster } from "sonner";
import Shell, { ShellMain } from "@calcom/features/shell/Shell";
import { SENDER_ID } from "@calcom/lib/constants";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { HttpError } from "@calcom/lib/http-error";
import type { WorkflowRepository } from "@calcom/lib/server/repository/workflow";
import type { WorkflowPermissions } from "@calcom/lib/server/repository/workflow-permissions";
import type { TimeUnit, WorkflowTriggerEvents } from "@calcom/prisma/enums";
import { WorkflowActions } from "@calcom/prisma/enums";
import type { RouterOutputs } from "@calcom/trpc/react";
import { trpc } from "@calcom/trpc/react";
import useMeQuery from "@calcom/trpc/react/hooks/useMeQuery";
import classNames from "@calcom/ui/classNames";
import { Alert } from "@calcom/ui/components/alert";
import { Badge } from "@calcom/ui/components/badge";
import { Button } from "@calcom/ui/components/button";
import type { MultiSelectCheckboxesOptionType as Option } from "@calcom/ui/components/form";
import { Form } from "@calcom/ui/components/form";
import { Form, Input } from "@calcom/ui/components/form";
import { Icon } from "@calcom/ui/components/icon";
import { showToast } from "@calcom/ui/components/toast";
import { Tooltip } from "@calcom/ui/components/tooltip";
import LicenseRequired from "../../common/components/LicenseRequired";
import { DeleteDialog } from "../components/DeleteDialog";
import SkeletonLoader from "../components/SkeletonLoaderEdit";
import WorkflowDetailsPage from "../components/WorkflowDetailsPage";
import { isSMSAction, isSMSOrWhatsappAction, isCalAIAction } from "../lib/actionHelperFunctions";
@@ -60,6 +63,9 @@ function WorkflowPage({
const [selectedOptions, setSelectedOptions] = useState<Option[]>([]);
const [isAllDataLoaded, setIsAllDataLoaded] = useState(false);
const [isMixedEventType, setIsMixedEventType] = useState(false); //for old event types before team workflows existed
const [deleteDialogOpen, setDeleteDialogOpen] = useState(false);
const [isEditingName, setIsEditingName] = useState(false);
const [nameValue, setNameValue] = useState("");
const form = useForm<FormValues>({
mode: "onBlur",
@@ -130,7 +136,38 @@ function WorkflowPage({
return w !== null && w !== undefined && "permissions" in w;
};
const readOnly = workflow && hasPermissions(workflow) ? !workflow.permissions?.canUpdate : true;
const permissions: WorkflowPermissions =
workflow && hasPermissions(workflow)
? workflow?.permissions
: {
canUpdate: !teamId,
canView: !teamId,
canDelete: !teamId,
readOnly: !!teamId,
};
// Watch for form name changes
const watchedName = form.watch("name");
// Handler functions for editable name
const handleNameChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setNameValue(e.target.value);
};
const handleNameSubmit = () => {
form.setValue("name", nameValue);
setIsEditingName(false);
};
const handleNameKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
if (e.key === "Enter") {
form.setValue("name", nameValue);
setIsEditingName(false);
} else if (e.key === "Escape") {
setNameValue(watchedName || "");
setIsEditingName(false);
}
};
const isPending = isPendingWorkflow || isPendingEventTypes;
@@ -162,8 +199,16 @@ function WorkflowPage({
setFormData(workflowWithDefaults);
}
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isPending]);
// Update nameValue when workflow changes
useEffect(() => {
if (workflow?.name) {
setNameValue(workflow.name);
}
}, [workflow?.name]);
function setFormData(workflowData: RouterOutputs["viewer"]["workflows"]["get"] | undefined) {
if (workflowData) {
if (workflowData.userId && workflowData.activeOn.find((active) => !!active.eventType.teamId)) {
@@ -229,6 +274,7 @@ function WorkflowPage({
form.setValue("timeUnit", workflowData.timeUnit || undefined);
form.setValue("activeOn", activeOn || []);
form.setValue("selectAll", workflowData.isActiveOnAll ?? false);
setNameValue(workflowData.name);
setIsAllDataLoaded(true);
}
}
@@ -352,73 +398,135 @@ function WorkflowPage({
};
return session.data ? (
<Shell withoutMain backPath="/workflows">
<LicenseRequired>
<Form
form={form}
handleSubmit={async (values) => {
await validateAndSubmitWorkflow(values);
}}>
<ShellMain
backPath="/workflows"
title={workflow && workflow.name ? workflow.name : "Untitled"}
CTA={
!readOnly && (
<div>
<Button data-testid="save-workflow" type="submit" loading={updateMutation.isPending}>
{t("save")}
</Button>
</div>
)
}
heading={
isAllDataLoaded && (
<div className="flex">
<div className={classNames(workflow && !workflow.name ? "text-muted" : "")}>
{workflow && workflow.name ? workflow.name : "untitled"}
</div>
{workflow && workflow.team && (
<Badge className="ml-4 mt-1" variant="gray">
{workflow.team.name}
</Badge>
)}
{readOnly && (
<Badge className="ml-4 mt-1" variant="gray">
{t("readonly")}
</Badge>
)}
</div>
)
}>
{!isError ? (
<>
{isAllDataLoaded && user ? (
<>
<WorkflowDetailsPage
permissions={workflow && hasPermissions(workflow) ? workflow.permissions : undefined}
form={form}
workflowId={+workflowId}
user={user}
selectedOptions={selectedOptions}
setSelectedOptions={setSelectedOptions}
teamId={workflow ? workflow.teamId || undefined : undefined}
readOnly={readOnly}
isOrg={isOrg}
allOptions={isOrg ? teamOptions : allEventTypeOptions}
onSaveWorkflow={handleSaveWorkflow}
/>
</>
<LicenseRequired>
<Form
form={form}
handleSubmit={async (values) => {
await validateAndSubmitWorkflow(values);
}}>
<div className="flex h-full min-h-screen w-full flex-col">
<div className="bg-default border-muted flex w-full items-center justify-between border-b px-4 py-2">
<div className="border-muted flex items-center gap-2">
<Button
color="secondary"
size="sm"
variant="icon"
StartIcon="arrow-left"
href="/workflows"
data-testid="go-back-button"
/>
<div className="flex min-w-0 items-center leading-none">
<span className="text-subtle min-w-content text-sm font-semibold leading-none">
{t("workflows")}
</span>
<span className="text-subtle mx-1 text-sm font-semibold leading-none">/</span>
{isEditingName ? (
<Input
{...form.register("name")}
data-testid="workflow-name"
onChange={handleNameChange}
onKeyDown={handleNameKeyDown}
onBlur={handleNameSubmit}
className="text-default focus:shadow-outline-gray-focused h-auto w-full whitespace-nowrap border-none p-1 text-sm font-semibold leading-none focus:ring-0"
autoFocus
/>
) : (
<SkeletonLoader />
<div className="group flex items-center gap-1">
<span
className="text-default hover:bg-muted min-w-[100px] cursor-pointer truncate whitespace-nowrap rounded p-1 text-sm font-semibold leading-none"
onClick={() => setIsEditingName(true)}>
{watchedName ? watchedName : isPending ? t("loading") : t("untitled")}
</span>
<Button
variant="icon"
color="minimal"
data-testid="edit-workflow-name-button"
disabled={isPending}
onClick={() => setIsEditingName(true)}
CustomStartIcon={
<Icon name="pencil" className="text-subtle group-hover:text-default h-3 w-3" />
}>
<span className="sr-only">{t("edit")}</span>
</Button>
</div>
)}
</>
) : (
<Alert severity="error" title="Something went wrong" message={error?.message ?? ""} />
)}
</ShellMain>
</Form>
</LicenseRequired>
</Shell>
</div>
{workflow && workflow.team && (
<Badge className="ml-4 mt-1" variant="gray">
{workflow.team.name}
</Badge>
)}
{permissions.readOnly && (
<Badge className="ml-4 mt-1" variant="gray">
{t("readonly")}
</Badge>
)}
</div>
<div className="border-muted flex justify-end gap-2">
<Tooltip sideOffset={4} content={t("delete")} side="bottom">
<Button
color="destructive"
type="button"
StartIcon="trash-2"
data-testid="delete-button"
onClick={() => {
setDeleteDialogOpen(true);
}}
disabled={!permissions.canDelete}
/>
</Tooltip>
<Button
loading={updateMutation.isPending}
disabled={permissions.readOnly || updateMutation.isPending}
data-testid="save-workflow"
type="submit"
color="primary">
{t("save")}
</Button>
</div>
</div>
<div className="bg-default min-h-screen w-full px-2 sm:p-0">
<div className="mx-auto my-8 max-w-4xl ">
{!isError ? (
<>
{isAllDataLoaded && user ? (
<>
<WorkflowDetailsPage
form={form}
workflowId={+workflowId}
user={user}
selectedOptions={selectedOptions}
setSelectedOptions={setSelectedOptions}
teamId={workflow ? workflow.teamId || undefined : undefined}
isOrg={isOrg}
allOptions={isOrg ? teamOptions : allEventTypeOptions}
onSaveWorkflow={handleSaveWorkflow}
permissions={permissions}
/>
</>
) : (
<SkeletonLoader />
)}
</>
) : (
<Alert severity="error" title={t("something_went_wrong")} message={error?.message ?? ""} />
)}
</div>
</div>
</div>
</Form>
<DeleteDialog
isOpenDialog={deleteDialogOpen}
setIsOpenDialog={setDeleteDialogOpen}
workflowId={workflowId}
additionalFunction={async () => {
// Navigate back to workflows list after deletion
window.location.href = "/workflows";
}}
/>
<Toaster position="bottom-right" />
</LicenseRequired>
) : (
<></>
);
@@ -0,0 +1,4 @@
.selected-flag {
border-top-left-radius: 10px !important;
border-bottom-left-radius: 10px !important;
}
@@ -8,6 +8,7 @@ import { BookingStatus } from "@calcom/prisma/enums";
import type { TrpcSessionUser } from "../../../types";
import { confirmHandler } from "./confirm.handler";
//eslint-disable-next-line playwright/no-skipped-test
describe.skip("confirmHandler", () => {
beforeEach(() => {
// Reset all mocks before each test
@@ -200,4 +201,4 @@ describe.skip("confirmHandler", () => {
expect(res?.status).toBe(BookingStatus.REJECTED);
expectWorkflowToBeTriggered({ emailsToReceive: [organizer.email], emails });
});
});
});
+30 -7
View File
@@ -13,7 +13,7 @@ import { Input } from "../form/inputs/TextField";
import { Icon } from "../icon";
import type { IconName } from "../icon";
type Action = { check: () => boolean; fn: () => void };
type Action = { check: () => boolean; fn: () => void; color?: "destructive" | "minimal"; disabled?: boolean };
type FormCardActionsProps = {
deleteField?: Action | null;
@@ -25,7 +25,8 @@ const FormCardActions = ({ deleteField, duplicateField }: FormCardActionsProps)
label: string;
icon: IconName;
onClick: () => void;
color?: "destructive" | "minimal";
color: "destructive" | "minimal";
disabled?: boolean;
};
const actions: ActionItem[] = [
@@ -37,8 +38,9 @@ const FormCardActions = ({ deleteField, duplicateField }: FormCardActionsProps)
deleteField?.fn && {
label: "Delete",
icon: "trash",
color: "minimal",
onClick: () => deleteField.fn(),
color: deleteField.color ?? "minimal",
disabled: deleteField.disabled,
},
].filter((action): action is ActionItem => !!action);
@@ -56,6 +58,7 @@ const FormCardActions = ({ deleteField, duplicateField }: FormCardActionsProps)
onClick={action.onClick}
StartIcon={action.icon}
title={action.label}
disabled={action.disabled}
/>
);
}
@@ -77,6 +80,7 @@ const FormCardActions = ({ deleteField, duplicateField }: FormCardActionsProps)
e.preventDefault();
action.onClick();
}}
disabled={action.disabled}
color={action.color}>
{action.label}
</DropdownItem>
@@ -102,7 +106,7 @@ export default function FormCard({
...restProps
}: {
children: React.ReactNode;
label: string;
label: React.ReactNode;
isLabelEditable?: boolean;
onLabelChange?: (label: string) => void;
deleteField?: Action | null;
@@ -173,10 +177,14 @@ export default function FormCard({
className="text-muted"
/>
)}
{isLabelEditable ? (
<Input type="text" value={label} onChange={(e) => onLabelChange?.(e.target.value)} />
{typeof label === "string" ? (
isLabelEditable ? (
<Input type="text" value={label} onChange={(e) => onLabelChange?.(e.target.value)} />
) : (
<span className="text-emphasis text-sm font-semibold">{label}</span>
)
) : (
<span className="text-emphasis text-sm font-semibold">{label}</span>
label
)}
{badge && (
<Badge className="ml-2" variant={badge.variant}>
@@ -193,3 +201,18 @@ export default function FormCard({
</div>
);
}
export function FormCardBody({
children,
className = "",
...props
}: {
children: React.ReactNode;
className?: string;
} & React.HTMLAttributes<HTMLDivElement>) {
return (
<div className={`bg-default border-default w-full gap-3 rounded-2xl border p-3 ${className}`} {...props}>
{children}
</div>
);
}
+1 -1
View File
@@ -1,5 +1,5 @@
export { default as Card } from "./Card";
export type { BaseCardProps } from "./Card";
export { StepCard } from "./StepCard";
export { default as FormCard } from "./FormCard";
export { default as FormCard, FormCardBody } from "./FormCard";
export { PanelCard } from "./PanelCard";
@@ -5,6 +5,10 @@ import { describe, it, expect, vi } from "vitest";
import { Editor } from "./Editor";
import type { TextEditorProps } from "./types";
vi.mock("@calcom/lib/hooks/useMediaQuery", () => ({
default: (_query: string) => false,
}));
describe("Editor", () => {
const defaultProps: TextEditorProps = {
getText: vi.fn(),
@@ -17,6 +17,10 @@ vi.mock("../../dropdown", () => ({
DropdownMenuItem: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
}));
vi.mock("@calcom/lib/hooks/useMediaQuery", () => ({
default: (_query: string) => false,
}));
describe("AddVariablesDropdown", () => {
const mockAddVariable = vi.fn();
const variables = ["var1", "var2", "var3"];
@@ -1,8 +1,11 @@
import { useMemo, useState } from "react";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import useMediaQuery from "@calcom/lib/hooks/useMediaQuery";
import classNames from "../../../classNames";
import { Dropdown, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "../../dropdown";
import { Input } from "../../form";
import { Icon } from "../../icon";
interface IAddVariablesDropdown {
@@ -16,6 +19,7 @@ interface IAddVariablesDropdown {
export const AddVariablesDropdown = (props: IAddVariablesDropdown) => {
const { t } = useLocale();
const [query, setQuery] = useState("");
const isMobile = useMediaQuery("(max-width: 640px)");
const filteredVariables = useMemo(() => {
const q = query.trim().toLowerCase();
@@ -60,14 +64,15 @@ export const AddVariablesDropdown = (props: IAddVariablesDropdown) => {
)}
</div>
</DropdownMenuTrigger>
<DropdownMenuContent className="w-96">
<div className="p-4">
<div className="text-subtle mb-3 text-left text-xs font-medium uppercase tracking-wide">
<DropdownMenuContent className="w-52">
<div className="space-y-2 p-1">
<div className="text-muted ml-1 text-left text-xs font-medium tracking-wide">
{t("add_dynamic_variables")}
</div>
<div className="mb-2 px-2">
<input
<div>
<Input
type="text"
size="sm"
value={query}
onChange={(e) => setQuery(e.target.value)}
placeholder={t("search_variables")}
@@ -75,29 +80,30 @@ export const AddVariablesDropdown = (props: IAddVariablesDropdown) => {
className="border-subtle bg-default focus:ring-brand-800 w-full rounded-md border px-3 py-2 text-sm outline-none focus:ring-1"
/>
</div>
<div className="max-h-64 overflow-y-auto md:max-h-80">
<div className="max-h-64 overflow-y-auto overflow-x-hidden md:max-h-80">
{filteredVariables.length === 0 ? (
<div className="text-subtle px-4 py-2 text-center text-sm">{t("no_variables_found")}</div>
) : (
filteredVariables.map((variable) => (
<DropdownMenuItem key={variable} className="hover:ring-0">
<button
<DropdownMenuItem key={variable} className="w-full p-1 hover:ring-0">
<div
key={variable}
type="button"
className="hover:bg-muted w-full rounded-md px-3 py-2 text-left transition-colors"
className="w-full cursor-pointer rounded-md text-left transition-colors"
onClick={() => {
props.addVariable(t(`${variable}_variable`));
setQuery("");
}}>
<div className="flex flex-col space-y-1">
<div className="text-default font-mono text-sm">
<div className="flex flex-col">
<div
className={classNames(
"text-default font-mono text-sm",
isMobile ? "break-all" : "truncate"
)}>
{`{${t(`${variable}_variable`).toUpperCase().replace(/ /g, "_")}}`}
</div>
<div className="text-muted-foreground hidden text-xs sm:block">
{t(`${variable}_info`)}
</div>
<div className="text-muted hidden text-xs sm:block">{t(`${variable}_info`)}</div>
</div>
</button>
</div>
</DropdownMenuItem>
))
)}
@@ -126,6 +126,7 @@ export default function MultiSelectCheckboxes({
}}
variant="checkbox"
options={allOptions.length > 1 ? allOptions : []}
innerClassNames={{ valueContainer: "font-medium", option: "font-medium" }}
isMulti
isDisabled={isDisabled}
className={classNames(className ? className : "w-64 text-sm")}
+4418 -25
View File
File diff suppressed because it is too large. Load diff