refactor: move feature-flags, calendars, and schedules components from packages/features to apps/web/modules (#27222)

* refactor: move feature-flags, calendars, and schedules components from packages/features to apps/web/modules

Co-Authored-By: [email protected] <[email protected]>

* fix

* fix

* fix

* fix: move DatePicker and DateOverrideInputDialog to apps/web/modules and update imports

Co-Authored-By: [email protected] <[email protected]>

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* rename

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* wip

* wip

* wip

* fix unit tests

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
Benny JooandDevin AI authored and GitHub committed 2026-01-29 16:41:44 +02:00
1 parent 18049bc1d6
commit c7ee3984ef
36 files changed
+134 -53

No files matched your search

@@ -0,0 +1,94 @@
import { revalidateAvailabilityList } from "app/(use-page-wrapper)/(main-nav)/availability/actions";
import { useRouter } from "next/navigation";
import { useForm } from "react-hook-form";
import { Dialog } from "@calcom/features/components/controlled-dialog";
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/components/button";
import { DialogContent, DialogFooter, DialogTrigger, DialogClose } from "@calcom/ui/components/dialog";
import { Form } from "@calcom/ui/components/form";
import { InputField } from "@calcom/ui/components/form";
import { showToast } from "@calcom/ui/components/toast";
export function NewScheduleButton({
name = "new-schedule",
fromEventType,
}: {
name?: string;
fromEventType?: boolean;
}) {
const router = useRouter();
const { t } = useLocale();
const form = useForm<{
name: string;
}>();
const { register } = form;
const utils = trpc.useUtils();
const createMutation = trpc.viewer.availability.schedule.create.useMutation({
onSuccess: async ({ schedule }) => {
await router.push(`/availability/${schedule.id}${fromEventType ? "?fromEventType=true" : ""}`);
showToast(t("schedule_created_successfully", { scheduleName: schedule.name }), "success");
revalidateAvailabilityList();
utils.viewer.availability.list.setData(undefined, (data) => {
const newSchedule = { ...schedule, isDefault: false, availability: [] };
if (!data)
return {
schedules: [newSchedule],
};
return {
...data,
schedules: [...data.schedules, newSchedule],
};
});
},
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}: ${t("error_schedule_unauthorized_create")}`;
showToast(message, "error");
}
},
});
return (
<Dialog name={name} clearQueryParamsOnClose={["copy-schedule-id"]}>
<DialogTrigger asChild>
<Button variant="fab" data-testid={name} StartIcon="plus" size="sm">
{t("new")}
</Button>
</DialogTrigger>
<DialogContent title={t("add_new_schedule")}>
<Form
form={form}
handleSubmit={(values) => {
createMutation.mutate(values);
}}>
<InputField
label={t("name")}
type="text"
id="name"
required
placeholder={t("default_schedule_name")}
{...register("name", {
setValueAs: (v) => (!v || v.trim() === "" ? null : v),
})}
/>
<DialogFooter>
<DialogClose />
<Button type="submit" loading={createMutation.isPending}>
{t("continue")}
</Button>
</DialogFooter>
</Form>
</DialogContent>
</Dialog>
);
}
@@ -0,0 +1,29 @@
import React from "react";
import type { Control, FieldValues } from "react-hook-form";
import {
ScheduleComponent,
type FieldPathByValue,
type ScheduleLabelsType,
} from "@calcom/features/schedules/components/ScheduleComponent";
import useMeQuery from "@calcom/trpc/react/hooks/useMeQuery";
import type { TimeRange } from "@calcom/types/schedule";
const Schedule = <
TFieldValues extends FieldValues,
TPath extends FieldPathByValue<TFieldValues, TimeRange[][]>
>(props: {
name: TPath;
control: Control<TFieldValues>;
weekStart?: number;
disabled?: boolean;
labels?: ScheduleLabelsType;
userTimeFormat?: number | null;
}) => {
const query = useMeQuery();
const { timeFormat } = query.data || { timeFormat: null };
return <ScheduleComponent userTimeFormat={timeFormat} {...props} />;
};
export default Schedule;
@@ -0,0 +1,122 @@
import { TooltipProvider } from "@radix-ui/react-tooltip";
import { render, renderHook, screen } from "@testing-library/react";
// eslint-disable-next-line no-restricted-imports
import { noop } from "lodash";
import { useFieldArray, useForm, FormProvider } from "react-hook-form";
import { vi } from "vitest";
import dayjs from "@calcom/dayjs";
import DateOverrideList from "@calcom/features/schedules/components/DateOverrideList";
import type { TimeRange } from "@calcom/types/schedule";
vi.mock("next/navigation", async (importOriginal) => {
const actual = await importOriginal<typeof import("next/navigation")>();
return {
...actual,
useRouter: vi.fn(() => ({
push: vi.fn(() => {
return;
}),
})),
};
});
type FormValues = {
dateOverrides: { ranges: TimeRange[] }[];
};
describe("DateOverrideList", () => {
it("renders DateOverrideList component in military time", () => {
const { result } = renderHook(() =>
useForm<FormValues>({
values: {
dateOverrides: [
{
ranges: [
{
start: dayjs.utc().startOf("day").add(540, "minute").toDate(),
end: dayjs.utc().startOf("day").add(1020, "minute").toDate(),
},
],
},
],
},
})
);
const methods = result.current;
const { control } = methods;
const { result: fieldArrayResult } = renderHook(() => useFieldArray({ control, name: "dateOverrides" }));
render(
<TooltipProvider>
<FormProvider {...methods}>
<DateOverrideList
hour12={false}
userTimeFormat={24}
fields={fieldArrayResult.current.fields}
replace={fieldArrayResult.current.replace}
workingHours={[]}
handleAvailabilityUpdate={noop}
/>
</FormProvider>
</TooltipProvider>
);
const dateString = new Intl.DateTimeFormat("en", {
weekday: "long",
month: "long",
day: "numeric",
timeZone: "UTC",
}).format(new Date());
expect(screen.getByText(dateString)).toBeInTheDocument();
expect(screen.getByText(`09:00 - 17:00`)).toBeInTheDocument();
});
it("renders DateOverrideList component in AM/PM", () => {
const { result } = renderHook(() =>
useForm<FormValues>({
values: {
dateOverrides: [
{
ranges: [
{
start: dayjs.utc().startOf("day").add(540, "minute").toDate(),
end: dayjs.utc().startOf("day").add(1020, "minute").toDate(),
},
],
},
],
},
})
);
const methods = result.current;
const { control } = methods;
const { result: fieldArrayResult } = renderHook(() => useFieldArray({ control, name: "dateOverrides" }));
render(
<TooltipProvider>
<FormProvider {...methods}>
<DateOverrideList
hour12={true}
userTimeFormat={12}
fields={fieldArrayResult.current.fields}
replace={fieldArrayResult.current.replace}
workingHours={[]}
handleAvailabilityUpdate={noop}
/>
</FormProvider>
</TooltipProvider>
);
const dateString = new Intl.DateTimeFormat("en", {
weekday: "long",
month: "long",
day: "numeric",
timeZone: "UTC",
}).format(new Date());
expect(screen.getByText(dateString)).toBeInTheDocument();
expect(screen.getByText(`9:00 AM - 5:00 PM`)).toBeInTheDocument();
});
});