refactor: v2 schedules (#15403)
* refactor: platform-types schedule types * refactor: lib add bidirectional schedule transformers api <-> atom * refactor: trpc handlers use renamed lib transformers * refactor: platform-libraries export new bi-directional transformers * chore: v2 update platform-libraries * chore: enable also old platform-libraries * fix: platform-types support previous types * refactor: versioning date * chore: version old schedules as schedules_2024_04_15 module * chore: version old schedules as schedules_2024_04_15 module * feat: new 2024_06_11 schedules module * feat: atoms use refactored schedule api * refactor: remove ?for=atom in schedules hooks * fix: unit test
This commit is contained in:
1 parent
357a42b512
commit
68ce9524eb
79 files changed
+2664
-522
No files matched your search
@@ -128,10 +128,10 @@ export function getWorkingHours(
|
||||
}
|
||||
|
||||
export function availabilityAsString(
|
||||
availability: Availability,
|
||||
availability: Pick<Availability, "days" | "startTime" | "endTime">,
|
||||
{ locale, hour12 }: { locale?: string; hour12?: boolean }
|
||||
) {
|
||||
const weekSpan = (availability: Availability) => {
|
||||
const weekSpan = (availability: Pick<Availability, "days" | "startTime" | "endTime">) => {
|
||||
const days = availability.days.slice(1).reduce(
|
||||
(days, day) => {
|
||||
if (days[days.length - 1].length === 1 && days[days.length - 1][0] === day - 1) {
|
||||
@@ -153,7 +153,7 @@ export function availabilityAsString(
|
||||
.join(", ");
|
||||
};
|
||||
|
||||
const timeSpan = (availability: Availability) => {
|
||||
const timeSpan = (availability: Pick<Availability, "days" | "startTime" | "endTime">) => {
|
||||
return `${new Intl.DateTimeFormat(locale, { hour: "numeric", minute: "numeric", hour12 }).format(
|
||||
new Date(availability.startTime.toISOString().slice(0, -1))
|
||||
)} - ${new Intl.DateTimeFormat(locale, { hour: "numeric", minute: "numeric", hour12 }).format(
|
||||
|
||||
@@ -1 +1 @@
|
||||
export * from "./client/transformers";
|
||||
export * from "./transformers";
|
||||
+14
-21
@@ -1,33 +1,25 @@
|
||||
import type { Availability as AvailabilityModel, Schedule as ScheduleModel } from "@prisma/client";
|
||||
import type { Availability } from "@prisma/client";
|
||||
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import { getWorkingHours } from "@calcom/lib/availability";
|
||||
import { yyyymmdd } from "@calcom/lib/date-fns";
|
||||
import type { Schedule, TimeRange } from "@calcom/types/schedule";
|
||||
|
||||
export type ScheduleWithAvailabilities = ScheduleModel & { availability: AvailabilityModel[] };
|
||||
type ScheduleAvailability = Pick<Availability, "days" | "startTime" | "endTime">[];
|
||||
type ScheduleOverride = Pick<Availability, "date" | "startTime" | "endTime">[];
|
||||
|
||||
export type ScheduleWithAvailabilitiesForWeb = Pick<ScheduleModel, "id" | "name"> & {
|
||||
isManaged: boolean;
|
||||
workingHours: ReturnType<typeof transformWorkingHoursForClient>;
|
||||
schedule: AvailabilityModel[];
|
||||
availability: ReturnType<typeof transformAvailabilityForClient>;
|
||||
timeZone: string;
|
||||
dateOverrides: ReturnType<typeof transformDateOverridesForClient>;
|
||||
isDefault: boolean;
|
||||
isLastSchedule: boolean;
|
||||
readOnly: boolean;
|
||||
};
|
||||
|
||||
export function transformWorkingHoursForClient(schedule: ScheduleWithAvailabilities) {
|
||||
export function transformWorkingHoursForAtom(schedule: {
|
||||
timeZone: string | null;
|
||||
availability: ScheduleAvailability;
|
||||
}) {
|
||||
return getWorkingHours(
|
||||
{ timeZone: schedule.timeZone || undefined, utcOffset: 0 },
|
||||
schedule.availability || []
|
||||
);
|
||||
}
|
||||
|
||||
export function transformAvailabilityForClient(schedule: ScheduleWithAvailabilities) {
|
||||
return transformScheduleToAvailabilityForClient(schedule).map((a) =>
|
||||
export function transformAvailabilityForAtom(schedule: { availability: ScheduleAvailability }) {
|
||||
return transformScheduleToAvailabilityForAtom(schedule).map((a) =>
|
||||
a.map((startAndEnd) => ({
|
||||
...startAndEnd,
|
||||
end: new Date(startAndEnd.end.toISOString().replace("23:59:00.000Z", "23:59:59.999Z")),
|
||||
@@ -35,7 +27,10 @@ export function transformAvailabilityForClient(schedule: ScheduleWithAvailabilit
|
||||
);
|
||||
}
|
||||
|
||||
export function transformDateOverridesForClient(schedule: ScheduleWithAvailabilities, timeZone: string) {
|
||||
export function transformDateOverridesForAtom(
|
||||
schedule: { availability: ScheduleOverride },
|
||||
timeZone: string
|
||||
) {
|
||||
return schedule.availability.reduce((acc, override) => {
|
||||
// only if future date override
|
||||
const currentUtcOffset = dayjs().tz(timeZone).utcOffset();
|
||||
@@ -70,9 +65,7 @@ export function transformDateOverridesForClient(schedule: ScheduleWithAvailabili
|
||||
}, [] as { ranges: TimeRange[] }[]);
|
||||
}
|
||||
|
||||
export const transformScheduleToAvailabilityForClient = (
|
||||
schedule: Partial<ScheduleModel> & { availability: AvailabilityModel[] }
|
||||
) => {
|
||||
export const transformScheduleToAvailabilityForAtom = (schedule: { availability: ScheduleAvailability }) => {
|
||||
return schedule.availability.reduce(
|
||||
(schedule: Schedule, availability) => {
|
||||
availability.days.forEach((day) => {
|
||||
@@ -0,0 +1,54 @@
|
||||
import type { ScheduleAvailabilityInput_2024_06_11 } from "@calcom/platform-types/schedules/schedules-2024-06-11";
|
||||
import type { ScheduleOverrideInput_2024_06_11 } from "@calcom/platform-types/schedules/schedules-2024-06-11";
|
||||
import type { WeekDay } from "@calcom/platform-types/schedules/schedules-2024-06-11";
|
||||
|
||||
export function transformApiScheduleAvailability(inputAvailability: ScheduleAvailabilityInput_2024_06_11[]) {
|
||||
return inputAvailability.map((availability) => ({
|
||||
days: availability.days.map(transformDayToNumber),
|
||||
startTime: createDateFromHoursMinutes(availability.startTime),
|
||||
endTime: createDateFromHoursMinutes(availability.endTime),
|
||||
}));
|
||||
}
|
||||
|
||||
export function transformApiScheduleOverrides(inputOverrides: ScheduleOverrideInput_2024_06_11[]) {
|
||||
return inputOverrides.map((override) => ({
|
||||
date: new Date(override.date),
|
||||
startTime: createDateFromHoursMinutes(override.startTime),
|
||||
endTime: createDateFromHoursMinutes(override.endTime),
|
||||
}));
|
||||
}
|
||||
|
||||
function createDateFromHoursMinutes(hoursMinutes: string): Date {
|
||||
const parts = hoursMinutes.split(":");
|
||||
|
||||
if (parts.length < 2) {
|
||||
throw new Error("Invalid time format. Please use 'hh:mm'.");
|
||||
}
|
||||
|
||||
const hours = parseInt(parts[0], 10);
|
||||
const minutes = parseInt(parts[1], 10);
|
||||
|
||||
if (isNaN(hours) || hours < 0 || hours > 23) {
|
||||
throw new Error("Hours must be a number between 0 and 23.");
|
||||
}
|
||||
if (isNaN(minutes) || minutes < 0 || minutes > 59) {
|
||||
throw new Error("Minutes must be a number between 0 and 59.");
|
||||
}
|
||||
|
||||
const utcDate = new Date(Date.UTC(1970, 0, 1, hours, minutes));
|
||||
|
||||
return utcDate;
|
||||
}
|
||||
|
||||
function transformDayToNumber(day: WeekDay): number {
|
||||
const weekMap: { [key in WeekDay]: number } = {
|
||||
Sunday: 0,
|
||||
Monday: 1,
|
||||
Tuesday: 2,
|
||||
Wednesday: 3,
|
||||
Thursday: 4,
|
||||
Friday: 5,
|
||||
Saturday: 6,
|
||||
};
|
||||
return weekMap[day];
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from "./for-atom";
|
||||
export * from "./from-api";
|
||||
@@ -62,6 +62,8 @@ export type CustomClassNames = {
|
||||
};
|
||||
};
|
||||
|
||||
export type Availability = Pick<Schedule, "days" | "startTime" | "endTime">;
|
||||
|
||||
type AvailabilitySettingsProps = {
|
||||
skeletonLabel?: string;
|
||||
schedule: {
|
||||
@@ -73,7 +75,7 @@ type AvailabilitySettingsProps = {
|
||||
workingHours: WorkingHours[];
|
||||
dateOverrides: { ranges: TimeRange[] }[];
|
||||
timeZone: string;
|
||||
schedule: Schedule[];
|
||||
schedule: Availability[];
|
||||
};
|
||||
travelSchedules?: RouterOutputs["viewer"]["getTravelSchedules"];
|
||||
handleDelete: () => void;
|
||||
@@ -289,7 +291,9 @@ export function AvailabilitySettings({
|
||||
schedule.schedule
|
||||
.filter((availability) => !!availability.days.length)
|
||||
.map((availability) => (
|
||||
<span key={availability.id} className={cn(customClassNames?.subtitlesClassName)}>
|
||||
<span
|
||||
key={availability.startTime.valueOf().toString()}
|
||||
className={cn(customClassNames?.subtitlesClassName)}>
|
||||
{availabilityAsString(availability, { locale: i18n.language, hour12: timeFormat === 12 })}
|
||||
<br />
|
||||
</span>
|
||||
|
||||
+152
@@ -0,0 +1,152 @@
|
||||
import type { ScheduleOutput_2024_06_11 } from "@calcom/platform-types";
|
||||
import type { User } from "@calcom/prisma/client";
|
||||
|
||||
import { transformApiScheduleForAtom } from "./transformApiScheduleForAtom";
|
||||
|
||||
const SCHEDULE_OWNER_ID = 256;
|
||||
|
||||
describe("transformScheduleForAtom", () => {
|
||||
const user: Pick<User, "id" | "defaultScheduleId" | "timeZone"> = {
|
||||
id: SCHEDULE_OWNER_ID,
|
||||
defaultScheduleId: 139,
|
||||
timeZone: "America/New_York",
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
jest.resetAllMocks();
|
||||
});
|
||||
|
||||
it("should return null if user is not provided", () => {
|
||||
const schedule: ScheduleOutput_2024_06_11 | null = {
|
||||
id: 139,
|
||||
ownerId: SCHEDULE_OWNER_ID,
|
||||
name: "Default",
|
||||
timeZone: "America/Cancun",
|
||||
availability: [
|
||||
{
|
||||
days: ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"],
|
||||
startTime: "09:00",
|
||||
endTime: "17:00",
|
||||
},
|
||||
],
|
||||
isDefault: true,
|
||||
overrides: [],
|
||||
};
|
||||
|
||||
expect(transformApiScheduleForAtom(undefined, schedule, 1)).toBeNull();
|
||||
});
|
||||
|
||||
it("should return null if schedule is not provided", () => {
|
||||
expect(transformApiScheduleForAtom(user, null, 1)).toBeNull();
|
||||
});
|
||||
|
||||
it("should transform schedule correctly", () => {
|
||||
const schedule: ScheduleOutput_2024_06_11 = {
|
||||
id: 139,
|
||||
ownerId: SCHEDULE_OWNER_ID,
|
||||
name: "Default",
|
||||
timeZone: "America/Cancun",
|
||||
availability: [
|
||||
{
|
||||
days: ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"],
|
||||
startTime: "09:00",
|
||||
endTime: "17:00",
|
||||
},
|
||||
],
|
||||
isDefault: true,
|
||||
overrides: [],
|
||||
};
|
||||
|
||||
const date = new Date();
|
||||
const year = date.getFullYear();
|
||||
const month = date.getMonth() + 1;
|
||||
const day = date.getDate();
|
||||
|
||||
const expectedResult = {
|
||||
id: 139,
|
||||
name: "Default",
|
||||
isManaged: false,
|
||||
workingHours: [
|
||||
{
|
||||
days: [1, 2, 3, 4, 5],
|
||||
startTime: 540,
|
||||
endTime: 1020,
|
||||
userId: 256,
|
||||
},
|
||||
],
|
||||
schedule: [
|
||||
{
|
||||
userId: 256,
|
||||
scheduleId: 139,
|
||||
days: [1, 2, 3, 4, 5],
|
||||
startTime: new Date(Date.UTC(1970, 0, 1, 9, 0)),
|
||||
endTime: new Date(Date.UTC(1970, 0, 1, 17, 0)),
|
||||
date: null,
|
||||
},
|
||||
],
|
||||
availability: [
|
||||
[],
|
||||
[
|
||||
{
|
||||
start: new Date(
|
||||
`${year}-${month.toString().padStart(2, "0")}-${day.toString().padStart(2, "0")}T09:00:00.000Z`
|
||||
),
|
||||
end: new Date(
|
||||
`${year}-${month.toString().padStart(2, "0")}-${day.toString().padStart(2, "0")}T17:00:00.000Z`
|
||||
),
|
||||
},
|
||||
],
|
||||
[
|
||||
{
|
||||
start: new Date(
|
||||
`${year}-${month.toString().padStart(2, "0")}-${day.toString().padStart(2, "0")}T09:00:00.000Z`
|
||||
),
|
||||
end: new Date(
|
||||
`${year}-${month.toString().padStart(2, "0")}-${day.toString().padStart(2, "0")}T17:00:00.000Z`
|
||||
),
|
||||
},
|
||||
],
|
||||
[
|
||||
{
|
||||
start: new Date(
|
||||
`${year}-${month.toString().padStart(2, "0")}-${day.toString().padStart(2, "0")}T09:00:00.000Z`
|
||||
),
|
||||
end: new Date(
|
||||
`${year}-${month.toString().padStart(2, "0")}-${day.toString().padStart(2, "0")}T17:00:00.000Z`
|
||||
),
|
||||
},
|
||||
],
|
||||
[
|
||||
{
|
||||
start: new Date(
|
||||
`${year}-${month.toString().padStart(2, "0")}-${day.toString().padStart(2, "0")}T09:00:00.000Z`
|
||||
),
|
||||
end: new Date(
|
||||
`${year}-${month.toString().padStart(2, "0")}-${day.toString().padStart(2, "0")}T17:00:00.000Z`
|
||||
),
|
||||
},
|
||||
],
|
||||
[
|
||||
{
|
||||
start: new Date(
|
||||
`${year}-${month.toString().padStart(2, "0")}-${day.toString().padStart(2, "0")}T09:00:00.000Z`
|
||||
),
|
||||
end: new Date(
|
||||
`${year}-${month.toString().padStart(2, "0")}-${day.toString().padStart(2, "0")}T17:00:00.000Z`
|
||||
),
|
||||
},
|
||||
],
|
||||
[],
|
||||
],
|
||||
timeZone: "America/Cancun",
|
||||
dateOverrides: [],
|
||||
isDefault: true,
|
||||
isLastSchedule: true,
|
||||
readOnly: false,
|
||||
};
|
||||
|
||||
const result = transformApiScheduleForAtom(user, schedule, 1);
|
||||
|
||||
expect(result).toEqual(expectedResult);
|
||||
});
|
||||
});
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
import {
|
||||
transformAvailabilityForAtom,
|
||||
transformDateOverridesForAtom,
|
||||
transformApiScheduleAvailability,
|
||||
transformApiScheduleOverrides,
|
||||
transformWorkingHoursForAtom,
|
||||
} from "@calcom/lib/schedules/transformers";
|
||||
import type { ScheduleOutput_2024_06_11 } from "@calcom/platform-types";
|
||||
import type { User } from "@calcom/prisma/client";
|
||||
|
||||
export function transformApiScheduleForAtom(
|
||||
user: Pick<User, "id" | "defaultScheduleId" | "timeZone"> | undefined,
|
||||
schedule: ScheduleOutput_2024_06_11 | null | undefined,
|
||||
userSchedulesCount: number
|
||||
) {
|
||||
if (!user || !schedule) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const transformedSchedule = {
|
||||
...schedule,
|
||||
availability: transformApiScheduleAvailability(schedule.availability),
|
||||
overrides: transformApiScheduleOverrides(schedule.overrides),
|
||||
};
|
||||
|
||||
const combined = [...transformedSchedule.availability, ...transformedSchedule.overrides];
|
||||
const availability = combined.map((entry) => {
|
||||
return {
|
||||
...entry,
|
||||
userId: schedule.ownerId,
|
||||
scheduleId: schedule.id,
|
||||
days: "days" in entry ? entry.days : [],
|
||||
date: "date" in entry ? entry.date : null,
|
||||
};
|
||||
});
|
||||
|
||||
const atomSchedule = {
|
||||
...schedule,
|
||||
availability,
|
||||
userId: schedule.ownerId,
|
||||
};
|
||||
|
||||
const timeZone = schedule.timeZone || user.timeZone;
|
||||
const defaultScheduleId = user.defaultScheduleId;
|
||||
|
||||
return {
|
||||
id: schedule.id,
|
||||
name: schedule.name,
|
||||
isManaged: schedule.ownerId !== user.id,
|
||||
workingHours: transformWorkingHoursForAtom(atomSchedule),
|
||||
schedule: availability,
|
||||
availability: transformAvailabilityForAtom(atomSchedule),
|
||||
timeZone,
|
||||
dateOverrides: transformDateOverridesForAtom(atomSchedule, timeZone),
|
||||
isDefault: defaultScheduleId === schedule.id,
|
||||
isLastSchedule: userSchedulesCount <= 1,
|
||||
readOnly: schedule.ownerId !== user.id,
|
||||
};
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
import type { UpdateScheduleInput_2024_06_11 } from "@calcom/platform-types";
|
||||
|
||||
import type { AvailabilityFormValues } from "../types";
|
||||
import { transformAtomScheduleForApi } from "./transformAtomScheduleForApi";
|
||||
|
||||
describe("transformAtomScheduleForApi", () => {
|
||||
it("should transform atom schedule correctly to API format", () => {
|
||||
const input: AvailabilityFormValues = {
|
||||
name: "Default",
|
||||
schedule: [
|
||||
[],
|
||||
[
|
||||
{
|
||||
start: new Date("2024-05-14T09:00:00.000Z"),
|
||||
end: new Date("2024-05-14T17:00:00.000Z"),
|
||||
},
|
||||
],
|
||||
[
|
||||
{
|
||||
start: new Date("2024-05-14T09:00:00.000Z"),
|
||||
end: new Date("2024-05-14T17:00:00.000Z"),
|
||||
},
|
||||
],
|
||||
[
|
||||
{
|
||||
start: new Date("2024-05-14T09:00:00.000Z"),
|
||||
end: new Date("2024-05-14T17:00:00.000Z"),
|
||||
},
|
||||
],
|
||||
[
|
||||
{
|
||||
start: new Date("2024-05-14T09:00:00.000Z"),
|
||||
end: new Date("2024-05-14T17:00:00.000Z"),
|
||||
},
|
||||
],
|
||||
[
|
||||
{
|
||||
start: new Date("2024-05-14T11:00:00.000Z"),
|
||||
end: new Date("2024-05-14T12:00:00.000Z"),
|
||||
},
|
||||
],
|
||||
[],
|
||||
],
|
||||
dateOverrides: [],
|
||||
timeZone: "America/Cancun",
|
||||
isDefault: true,
|
||||
};
|
||||
|
||||
const expectedOutput: UpdateScheduleInput_2024_06_11 = {
|
||||
name: "Default",
|
||||
timeZone: "America/Cancun",
|
||||
isDefault: true,
|
||||
availability: [
|
||||
{
|
||||
days: ["Monday", "Tuesday", "Wednesday", "Thursday"],
|
||||
startTime: "09:00",
|
||||
endTime: "17:00",
|
||||
},
|
||||
{
|
||||
days: ["Friday"],
|
||||
startTime: "11:00",
|
||||
endTime: "12:00",
|
||||
},
|
||||
],
|
||||
overrides: [],
|
||||
};
|
||||
|
||||
const result = transformAtomScheduleForApi(input);
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
});
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
import type {
|
||||
ScheduleAvailabilityInput_2024_06_11,
|
||||
UpdateScheduleInput_2024_06_11,
|
||||
WeekDay,
|
||||
} from "@calcom/platform-types";
|
||||
|
||||
import type { AvailabilityFormValues } from "../types";
|
||||
|
||||
export function transformAtomScheduleForApi(body: AvailabilityFormValues): UpdateScheduleInput_2024_06_11 {
|
||||
const { name, schedule, dateOverrides, timeZone, isDefault } = body;
|
||||
|
||||
const overrides =
|
||||
dateOverrides.flatMap(
|
||||
(dateOverridesRanges) =>
|
||||
dateOverridesRanges?.ranges?.map((range) => ({
|
||||
date: `${range.start.getUTCFullYear}-${range.start.getUTCMonth}-${range.start.getUTCDate}`,
|
||||
startTime: `${range.start.getUTCHours}-${range.start.getUTCMinutes}`,
|
||||
endTime: `${range.end.getUTCHours}-${range.end.getUTCMinutes}`,
|
||||
})) ?? []
|
||||
) ?? [];
|
||||
|
||||
const availability = formatScheduleTime(schedule);
|
||||
|
||||
return { name, timeZone, isDefault, availability, overrides };
|
||||
}
|
||||
|
||||
function formatScheduleTime(
|
||||
weekSchedule: AvailabilityFormValues["schedule"]
|
||||
): UpdateScheduleInput_2024_06_11["availability"] {
|
||||
const daysOfWeek: WeekDay[] = [
|
||||
"Sunday",
|
||||
"Monday",
|
||||
"Tuesday",
|
||||
"Wednesday",
|
||||
"Thursday",
|
||||
"Friday",
|
||||
"Saturday",
|
||||
];
|
||||
|
||||
const formattedSchedule = weekSchedule.map((daySchedule, index) =>
|
||||
daySchedule.map((event) => ({
|
||||
startTime: convertToHHMM(event.start.toISOString()),
|
||||
endTime: convertToHHMM(event.end.toISOString()),
|
||||
days: [daysOfWeek[index]],
|
||||
}))
|
||||
);
|
||||
|
||||
const timeMap: { [key: string]: ScheduleAvailabilityInput_2024_06_11 } = {};
|
||||
|
||||
formattedSchedule.flat().forEach((event) => {
|
||||
const timeKey = `${event.startTime}-${event.endTime}`;
|
||||
if (!timeMap[timeKey]) {
|
||||
timeMap[timeKey] = { startTime: event.startTime, endTime: event.endTime, days: [] };
|
||||
}
|
||||
timeMap[timeKey].days.push(...event.days);
|
||||
});
|
||||
|
||||
return Object.values(timeMap);
|
||||
}
|
||||
|
||||
function convertToHHMM(isoDate: string): string {
|
||||
const date = new Date(isoDate);
|
||||
const hours = date.getUTCHours().toString().padStart(2, "0");
|
||||
const minutes = date.getUTCMinutes().toString().padStart(2, "0");
|
||||
return `${hours}:${minutes}`;
|
||||
}
|
||||
+29
-32
@@ -1,16 +1,18 @@
|
||||
import type { ScheduleLabelsType } from "@calcom/features/schedules/components/Schedule";
|
||||
import type { ScheduleWithAvailabilitiesForWeb, UpdateScheduleOutputType } from "@calcom/platform-libraries";
|
||||
import type { ApiErrorResponse, ApiResponse, ApiSuccessResponse } from "@calcom/platform-types";
|
||||
import type { ApiErrorResponse, ApiResponse, ScheduleOutput_2024_06_11 } from "@calcom/platform-types";
|
||||
|
||||
import useClientSchedule from "../../hooks/useClientSchedule";
|
||||
import useDeleteSchedule from "../../hooks/useDeleteSchedule";
|
||||
import useDeleteSchedule from "../../hooks/schedules/useDeleteSchedule";
|
||||
import { useSchedule } from "../../hooks/schedules/useSchedule";
|
||||
import { useSchedules } from "../../hooks/schedules/useSchedules";
|
||||
import useUpdateSchedule from "../../hooks/schedules/useUpdateSchedule";
|
||||
import { useMe } from "../../hooks/useMe";
|
||||
import useUpdateSchedule from "../../hooks/useUpdateSchedule";
|
||||
import { AtomsWrapper } from "../../src/components/atoms-wrapper";
|
||||
import { useToast } from "../../src/components/ui/use-toast";
|
||||
import type { Schedule } from "../AvailabilitySettings";
|
||||
import type { Availability } from "../AvailabilitySettings";
|
||||
import type { CustomClassNames } from "../AvailabilitySettings";
|
||||
import { AvailabilitySettings } from "../AvailabilitySettings";
|
||||
import { transformApiScheduleForAtom } from "../atom-api-transformers/transformApiScheduleForAtom";
|
||||
import { transformAtomScheduleForApi } from "../atom-api-transformers/transformAtomScheduleForApi";
|
||||
import type { AvailabilityFormValues } from "../types";
|
||||
|
||||
type AvailabilitySettingsPlatformWrapperProps = {
|
||||
@@ -19,7 +21,7 @@ type AvailabilitySettingsPlatformWrapperProps = {
|
||||
tooltips: Partial<ScheduleLabelsType>;
|
||||
};
|
||||
customClassNames?: Partial<CustomClassNames>;
|
||||
onUpdateSuccess?: (res: ApiResponse<UpdateScheduleOutputType>) => void;
|
||||
onUpdateSuccess?: (res: ApiResponse<ScheduleOutput_2024_06_11>) => void;
|
||||
onUpdateError?: (err: ApiErrorResponse) => void;
|
||||
onDeleteSuccess?: (res: ApiResponse) => void;
|
||||
onDeleteError?: (err: ApiErrorResponse) => void;
|
||||
@@ -35,10 +37,10 @@ export const AvailabilitySettingsPlatformWrapper = ({
|
||||
onUpdateSuccess,
|
||||
disableEditableHeading = false,
|
||||
}: AvailabilitySettingsPlatformWrapperProps) => {
|
||||
const { isLoading, data: schedule } = useClientSchedule(id);
|
||||
const mySchedule = schedule as ApiSuccessResponse<ScheduleWithAvailabilitiesForWeb>;
|
||||
const { isLoading, data: schedule } = useSchedule(id);
|
||||
const { data: schedules } = useSchedules();
|
||||
const { data: me } = useMe();
|
||||
const userSchedule = mySchedule?.data;
|
||||
const atomSchedule = transformApiScheduleForAtom(me?.data, schedule, schedules?.length || 0);
|
||||
const { timeFormat } = me?.data || { timeFormat: null };
|
||||
const { toast } = useToast();
|
||||
|
||||
@@ -77,48 +79,43 @@ export const AvailabilitySettingsPlatformWrapper = ({
|
||||
};
|
||||
|
||||
const handleUpdate = async (id: number, body: AvailabilityFormValues) => {
|
||||
const transformedDateOverrides =
|
||||
body.dateOverrides.flatMap(
|
||||
(dateOverridesRanges) =>
|
||||
dateOverridesRanges?.ranges?.map((range) => ({ start: range.start, end: range.end })) ?? []
|
||||
) ?? [];
|
||||
|
||||
await updateSchedule({ ...body, scheduleId: id, dateOverrides: transformedDateOverrides });
|
||||
const updateBody = transformAtomScheduleForApi(body);
|
||||
updateSchedule({ id, ...updateBody });
|
||||
};
|
||||
|
||||
if (isLoading) return <div className="px-10 py-4 text-xl">Loading...</div>;
|
||||
|
||||
if (!userSchedule) return <div className="px-10 py-4 text-xl">No user schedule present</div>;
|
||||
if (!atomSchedule) return <div className="px-10 py-4 text-xl">No user schedule present</div>;
|
||||
|
||||
return (
|
||||
<AtomsWrapper>
|
||||
<AvailabilitySettings
|
||||
disableEditableHeading={disableEditableHeading}
|
||||
handleDelete={() => {
|
||||
userSchedule.id && handleDelete(userSchedule.id);
|
||||
atomSchedule.id && handleDelete(atomSchedule.id);
|
||||
}}
|
||||
handleSubmit={async (data) => {
|
||||
userSchedule.id && handleUpdate(userSchedule.id, data);
|
||||
atomSchedule.id && handleUpdate(atomSchedule.id, data);
|
||||
}}
|
||||
weekStart="Sunday"
|
||||
timeFormat={timeFormat}
|
||||
isLoading={isLoading}
|
||||
schedule={{
|
||||
name: userSchedule.name,
|
||||
id: userSchedule.id,
|
||||
isLastSchedule: userSchedule.isLastSchedule,
|
||||
isDefault: userSchedule.isDefault,
|
||||
workingHours: userSchedule.workingHours,
|
||||
dateOverrides: userSchedule.dateOverrides,
|
||||
timeZone: userSchedule.timeZone,
|
||||
availability: userSchedule.availability,
|
||||
name: atomSchedule.name,
|
||||
id: atomSchedule.id,
|
||||
isLastSchedule: atomSchedule.isLastSchedule,
|
||||
isDefault: atomSchedule.isDefault,
|
||||
workingHours: atomSchedule.workingHours,
|
||||
dateOverrides: atomSchedule.dateOverrides,
|
||||
timeZone: atomSchedule.timeZone,
|
||||
availability: atomSchedule.availability,
|
||||
schedule:
|
||||
userSchedule.schedule.reduce(
|
||||
(acc: Schedule[], avail: Schedule) => [
|
||||
atomSchedule.schedule.reduce(
|
||||
(acc: Availability[], avail: Availability) => [
|
||||
...acc,
|
||||
{ ...avail, startTime: new Date(avail.startTime), endTime: new Date(avail.endTime) },
|
||||
{ days: avail.days, startTime: new Date(avail.startTime), endTime: new Date(avail.endTime) },
|
||||
],
|
||||
[] as Schedule[]
|
||||
[]
|
||||
) || [],
|
||||
}}
|
||||
isDeleting={isDeletionInProgress}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||
import { useEffect, type ReactNode } from "react";
|
||||
|
||||
import type { API_VERSIONS_ENUM } from "@calcom/platform-constants";
|
||||
import { VERSION_2024_04_15 } from "@calcom/platform-constants";
|
||||
import { VERSION_2024_06_11 } from "@calcom/platform-constants";
|
||||
|
||||
import http from "../lib/http";
|
||||
import { BaseCalProvider } from "./BaseCalProvider";
|
||||
@@ -40,7 +40,7 @@ export function CalProvider({
|
||||
children,
|
||||
autoUpdateTimezone = true,
|
||||
onTimezoneChange,
|
||||
version = VERSION_2024_04_15,
|
||||
version = VERSION_2024_06_11,
|
||||
}: CalProviderProps) {
|
||||
useEffect(() => {
|
||||
http.setVersionHeader(version);
|
||||
|
||||
+3
-3
@@ -4,8 +4,8 @@ import { SUCCESS_STATUS } from "@calcom/platform-constants";
|
||||
import { V2_ENDPOINTS } from "@calcom/platform-constants";
|
||||
import type { ApiResponse, ApiErrorResponse } from "@calcom/platform-types";
|
||||
|
||||
import http from "../lib/http";
|
||||
import { QUERY_KEY } from "./useClientSchedule";
|
||||
import http from "../../lib/http";
|
||||
import { QUERY_KEY } from "./useSchedule";
|
||||
|
||||
interface IUseDeleteScheduleProps {
|
||||
onSuccess?: (res: ApiResponse) => void;
|
||||
@@ -31,7 +31,7 @@ const useDeleteSchedule = (
|
||||
const mutation = useMutation<ApiResponse<undefined>, unknown, DeleteScheduleInput>({
|
||||
mutationFn: (data) => {
|
||||
const { id } = data;
|
||||
const pathname = `/${V2_ENDPOINTS.availability}/${id}?for=atom`;
|
||||
const pathname = `/${V2_ENDPOINTS.availability}/${id}`;
|
||||
|
||||
return http?.delete(pathname).then((res) => res.data);
|
||||
},
|
||||
@@ -0,0 +1,26 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
|
||||
import { V2_ENDPOINTS, SUCCESS_STATUS } from "@calcom/platform-constants";
|
||||
import type { GetScheduleOutput_2024_06_11 } from "@calcom/platform-types";
|
||||
|
||||
import http from "../../lib/http";
|
||||
|
||||
export const QUERY_KEY = "user-schedule";
|
||||
|
||||
export const useSchedule = (id?: string) => {
|
||||
const pathname = id ? `/${V2_ENDPOINTS.availability}/${id}` : `/${V2_ENDPOINTS.availability}/default`;
|
||||
|
||||
const { isLoading, error, data } = useQuery({
|
||||
queryKey: [QUERY_KEY, id],
|
||||
queryFn: () => {
|
||||
return http.get<GetScheduleOutput_2024_06_11>(pathname).then((res) => {
|
||||
if (res.data.status === SUCCESS_STATUS) {
|
||||
return res.data.data;
|
||||
}
|
||||
throw new Error(res.data.error?.message);
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
return { isLoading, error, data };
|
||||
};
|
||||
@@ -0,0 +1,26 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
|
||||
import { V2_ENDPOINTS, SUCCESS_STATUS } from "@calcom/platform-constants";
|
||||
import type { GetSchedulesOutput_2024_06_11 } from "@calcom/platform-types";
|
||||
|
||||
import http from "../../lib/http";
|
||||
|
||||
export const QUERY_KEY = "user-schedules";
|
||||
|
||||
export const useSchedules = () => {
|
||||
const pathname = `/${V2_ENDPOINTS.availability}`;
|
||||
|
||||
const { isLoading, error, data } = useQuery({
|
||||
queryKey: [QUERY_KEY],
|
||||
queryFn: () => {
|
||||
return http.get<GetSchedulesOutput_2024_06_11>(pathname).then((res) => {
|
||||
if (res.data.status === SUCCESS_STATUS) {
|
||||
return res.data.data;
|
||||
}
|
||||
throw new Error(res.data.error?.message);
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
return { isLoading, error, data };
|
||||
};
|
||||
+9
-9
@@ -2,14 +2,14 @@ import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
|
||||
import { SUCCESS_STATUS } from "@calcom/platform-constants";
|
||||
import { V2_ENDPOINTS } from "@calcom/platform-constants";
|
||||
import type { UpdateScheduleOutputType } from "@calcom/platform-libraries";
|
||||
import type { ApiResponse, UpdateScheduleInput, ApiErrorResponse } from "@calcom/platform-types";
|
||||
import type { ApiResponse, UpdateScheduleInput_2024_06_11, ApiErrorResponse } from "@calcom/platform-types";
|
||||
import type { ScheduleOutput_2024_06_11 } from "@calcom/platform-types";
|
||||
|
||||
import http from "../lib/http";
|
||||
import { QUERY_KEY as ScheduleQueryKey } from "./useClientSchedule";
|
||||
import http from "../../lib/http";
|
||||
import { QUERY_KEY as ScheduleQueryKey } from "./useSchedule";
|
||||
|
||||
interface IPUpdateOAuthClient {
|
||||
onSuccess?: (res: ApiResponse<UpdateScheduleOutputType>) => void;
|
||||
onSuccess?: (res: ApiResponse<ScheduleOutput_2024_06_11>) => void;
|
||||
onError?: (err: ApiErrorResponse) => void;
|
||||
}
|
||||
|
||||
@@ -26,14 +26,14 @@ const useUpdateSchedule = (
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
const mutation = useMutation<
|
||||
ApiResponse<UpdateScheduleOutputType>,
|
||||
ApiResponse<ScheduleOutput_2024_06_11>,
|
||||
unknown,
|
||||
UpdateScheduleInput & { scheduleId: number }
|
||||
UpdateScheduleInput_2024_06_11 & { id: number }
|
||||
>({
|
||||
mutationFn: (data) => {
|
||||
const pathname = `/${V2_ENDPOINTS.availability}/${data.scheduleId}?for=atom`;
|
||||
const pathname = `/${V2_ENDPOINTS.availability}/${data.id}`;
|
||||
|
||||
return http.patch<ApiResponse<UpdateScheduleOutputType>>(pathname, data).then((res) => {
|
||||
return http.patch<ApiResponse<ScheduleOutput_2024_06_11>>(pathname, data).then((res) => {
|
||||
return res.data;
|
||||
});
|
||||
},
|
||||
@@ -1,31 +0,0 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
|
||||
import { V2_ENDPOINTS, SUCCESS_STATUS } from "@calcom/platform-constants";
|
||||
import type { ScheduleWithAvailabilitiesForWeb } from "@calcom/platform-libraries";
|
||||
import type { ApiResponse } from "@calcom/platform-types";
|
||||
|
||||
import http from "../lib/http";
|
||||
|
||||
export const QUERY_KEY = "user-schedule";
|
||||
|
||||
const useClientSchedule = (id?: string) => {
|
||||
const pathname = id
|
||||
? `/${V2_ENDPOINTS.availability}/${id}?for=atom`
|
||||
: `/${V2_ENDPOINTS.availability}/default?for=atom`;
|
||||
|
||||
const { isLoading, error, data } = useQuery({
|
||||
queryKey: [QUERY_KEY, id],
|
||||
queryFn: () => {
|
||||
return http.get<ApiResponse<ScheduleWithAvailabilitiesForWeb>>(pathname).then((res) => {
|
||||
if (res.data.status === SUCCESS_STATUS) {
|
||||
return res.data;
|
||||
}
|
||||
throw new Error(res.data.error.message);
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
return { isLoading, error, data };
|
||||
};
|
||||
|
||||
export default useClientSchedule;
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"moduleFileExtensions": ["js", "json", "ts"],
|
||||
"rootDir": ".",
|
||||
"testEnvironment": "node",
|
||||
"testRegex": ".*\\.spec\\.ts$",
|
||||
"transform": {
|
||||
"^.+\\.ts$": "ts-jest"
|
||||
}
|
||||
}
|
||||
@@ -8,22 +8,26 @@
|
||||
"scripts": {
|
||||
"dev": "yarn vite build --watch & npx tailwindcss -i ./globals.css -o ./globals.min.css --postcss --minify --watch",
|
||||
"build": "yarn vite build && npx tailwindcss -i ./globals.css -o ./globals.min.css --postcss --minify && mkdir ./dist/packages/prisma-client && cp -rf ../../../node_modules/.prisma/client/*.d.ts ./dist/packages/prisma-client",
|
||||
"publish": "rm -rf dist && yarn build && npm publish --access public"
|
||||
"publish": "rm -rf dist && yarn build && npm publish --access public",
|
||||
"test": "jest"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@calcom/platform-libraries": "0.0.2",
|
||||
"@rollup/plugin-node-resolve": "^15.0.1",
|
||||
"@types/jest": "^29.5.12",
|
||||
"@types/node": "^20.3.1",
|
||||
"@types/react": "18.0.26",
|
||||
"@types/react-dom": "^18.0.9",
|
||||
"@vitejs/plugin-react": "^2.2.0",
|
||||
"@vitejs/plugin-react-swc": "^3.7.0",
|
||||
"autoprefixer": "^10.4.19",
|
||||
"jest": "^29.7.0",
|
||||
"postcss": "^8.4.38",
|
||||
"postcss-import": "^16.1.0",
|
||||
"postcss-prefixer": "^3.0.0",
|
||||
"postcss-prefixwrap": "1.46.0",
|
||||
"rollup-plugin-node-builtins": "^2.1.2",
|
||||
"ts-jest": "^29.1.2",
|
||||
"typescript": "^4.9.4",
|
||||
"vite": "^5.0.10",
|
||||
"vite-plugin-dts": "^3.7.3",
|
||||
|
||||
@@ -51,9 +51,10 @@ export const X_CAL_CLIENT_ID = "x-cal-client-id";
|
||||
// HTTP status codes
|
||||
export const HTTP_CODE_TOKEN_EXPIRED = 498;
|
||||
|
||||
export const VERSION_2024_04_15 = "2024-04-15";
|
||||
export const VERSION_2024_06_11 = "2024-06-11";
|
||||
export const VERSION_2024_05_21 = "2024-05-21";
|
||||
export const API_VERSIONS = [VERSION_2024_04_15, VERSION_2024_05_21] as const;
|
||||
export const VERSION_2024_04_15 = "2024-04-15";
|
||||
export const API_VERSIONS = [VERSION_2024_06_11, VERSION_2024_04_15, VERSION_2024_05_21] as const;
|
||||
export type API_VERSIONS_ENUM = (typeof API_VERSIONS)[number];
|
||||
export type API_VERSIONS_TYPE = typeof API_VERSIONS;
|
||||
export const CAL_API_VERSION_HEADER = "cal-api-version";
|
||||
@@ -48,14 +48,13 @@ export type { ConnectedDestinationCalendars } from "@calcom/lib/getConnectedDest
|
||||
export { getBusyCalendarTimes } from "@calcom/core/CalendarManager";
|
||||
|
||||
export {
|
||||
transformWorkingHoursForClient,
|
||||
transformAvailabilityForClient,
|
||||
transformDateOverridesForClient,
|
||||
} from "@calcom/lib/schedules/client/transformers";
|
||||
export type {
|
||||
ScheduleWithAvailabilities,
|
||||
ScheduleWithAvailabilitiesForWeb,
|
||||
} from "@calcom/lib/schedules/client/transformers";
|
||||
transformWorkingHoursForAtom,
|
||||
transformAvailabilityForAtom,
|
||||
transformDateOverridesForAtom,
|
||||
transformApiScheduleAvailability,
|
||||
transformApiScheduleOverrides,
|
||||
} from "@calcom/lib/schedules/transformers";
|
||||
|
||||
export type {
|
||||
BookingCreateBody,
|
||||
BookingResponse,
|
||||
|
||||
@@ -3,6 +3,6 @@ export * from "./api";
|
||||
export * from "./oauth-clients";
|
||||
export * from "./slots";
|
||||
export * from "./calendars";
|
||||
export * from "./schedules";
|
||||
export * from "./bookings";
|
||||
export * from "./billing";
|
||||
export * from "./schedules";
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from "./schedules-2024-06-11";
|
||||
export * from "./schedules-2024-04-15";
|
||||
@@ -0,0 +1 @@
|
||||
export * from "./schedules";
|
||||
+7
-7
@@ -4,27 +4,27 @@ import { IsString, IsBoolean, IsOptional, ValidateNested, IsArray, IsDate } from
|
||||
import { DateTime } from "luxon";
|
||||
import { z } from "zod";
|
||||
|
||||
const scheduleSchema = z.object({
|
||||
const scheduleSchema_2024_04_15 = z.object({
|
||||
id: z.number().int(),
|
||||
userId: z.number().int(),
|
||||
name: z.string(),
|
||||
timeZone: z.string().nullish(),
|
||||
});
|
||||
|
||||
const availabilitySchema = z.object({
|
||||
const availabilitySchema_2024_04_15 = z.object({
|
||||
id: z.number().int(),
|
||||
days: z.number().int().array(),
|
||||
startTime: z.date(),
|
||||
endTime: z.date(),
|
||||
});
|
||||
|
||||
export const schemaScheduleResponse = z
|
||||
export const schemaScheduleResponse_2024_04_15 = z
|
||||
.object({})
|
||||
.merge(scheduleSchema)
|
||||
.merge(scheduleSchema_2024_04_15)
|
||||
.merge(
|
||||
z.object({
|
||||
availability: z
|
||||
.array(availabilitySchema)
|
||||
.array(availabilitySchema_2024_04_15)
|
||||
.transform((availabilities) =>
|
||||
availabilities.map((availability) => ({
|
||||
...availability,
|
||||
@@ -36,7 +36,7 @@ export const schemaScheduleResponse = z
|
||||
})
|
||||
);
|
||||
|
||||
export type ScheduleResponse = z.infer<typeof schemaScheduleResponse>;
|
||||
export type ScheduleResponse = z.infer<typeof schemaScheduleResponse_2024_04_15>;
|
||||
|
||||
class ScheduleItem {
|
||||
@IsString()
|
||||
@@ -56,7 +56,7 @@ class DateOverride {
|
||||
end!: Date;
|
||||
}
|
||||
|
||||
export class UpdateScheduleInput {
|
||||
export class UpdateScheduleInput_2024_04_15 {
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@DocsProperty()
|
||||
@@ -0,0 +1,13 @@
|
||||
export const WEEK_DAYS = [
|
||||
"Monday",
|
||||
"Tuesday",
|
||||
"Wednesday",
|
||||
"Thursday",
|
||||
"Friday",
|
||||
"Saturday",
|
||||
"Sunday",
|
||||
] as const;
|
||||
|
||||
export type WeekDay = (typeof WEEK_DAYS)[number];
|
||||
|
||||
export const TIME_FORMAT_HH_MM = /^([01]\d|2[0-3]):([0-5]\d)$/;
|
||||
@@ -0,0 +1,3 @@
|
||||
export * from "./inputs";
|
||||
export * from "./outputs";
|
||||
export * from "./constants";
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
import { ApiProperty } from "@nestjs/swagger";
|
||||
import { Type } from "class-transformer";
|
||||
import {
|
||||
IsBoolean,
|
||||
IsOptional,
|
||||
IsString,
|
||||
ValidateNested,
|
||||
IsArray,
|
||||
Matches,
|
||||
IsISO8601,
|
||||
IsTimeZone,
|
||||
IsIn,
|
||||
} from "class-validator";
|
||||
|
||||
import type { WeekDay } from "../constants";
|
||||
import { TIME_FORMAT_HH_MM, WEEK_DAYS } from "../constants";
|
||||
|
||||
export class ScheduleAvailabilityInput_2024_06_11 {
|
||||
@IsArray()
|
||||
@IsIn(WEEK_DAYS, { each: true })
|
||||
@ApiProperty({ example: ["Monday", "Tuesday"] })
|
||||
days!: WeekDay[];
|
||||
|
||||
@IsString()
|
||||
@Matches(TIME_FORMAT_HH_MM, { message: "startTime must be a valid time format HH:MM" })
|
||||
@ApiProperty({ example: "09:00" })
|
||||
startTime!: string;
|
||||
|
||||
@IsString()
|
||||
@Matches(TIME_FORMAT_HH_MM, { message: "endTime must be a valid time format HH:MM" })
|
||||
@ApiProperty({ example: "10:00" })
|
||||
endTime!: string;
|
||||
}
|
||||
|
||||
export class ScheduleOverrideInput_2024_06_11 {
|
||||
@IsISO8601({ strict: true })
|
||||
@ApiProperty({ example: "2024-05-20" })
|
||||
date!: string;
|
||||
|
||||
@IsString()
|
||||
@Matches(TIME_FORMAT_HH_MM, { message: "startTime must be a valid time format HH:MM" })
|
||||
@ApiProperty({ example: "12:00" })
|
||||
startTime!: string;
|
||||
|
||||
@IsString()
|
||||
@Matches(TIME_FORMAT_HH_MM, { message: "endTime must be a valid time format HH:MM" })
|
||||
@ApiProperty({ example: "13:00" })
|
||||
endTime!: string;
|
||||
}
|
||||
|
||||
export class CreateScheduleInput_2024_06_11 {
|
||||
@IsString()
|
||||
@ApiProperty({ example: "One-on-one coaching" })
|
||||
name!: string;
|
||||
|
||||
@IsTimeZone()
|
||||
@ApiProperty({ example: "Europe/Rome" })
|
||||
timeZone!: string;
|
||||
|
||||
@IsArray()
|
||||
@IsOptional()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => ScheduleAvailabilityInput_2024_06_11)
|
||||
@ApiProperty({
|
||||
type: [ScheduleAvailabilityInput_2024_06_11],
|
||||
example: [
|
||||
{
|
||||
days: ["Monday", "Tuesday"],
|
||||
startTime: "09:00",
|
||||
endTime: "10:00",
|
||||
},
|
||||
],
|
||||
required: false,
|
||||
})
|
||||
availability?: ScheduleAvailabilityInput_2024_06_11[];
|
||||
|
||||
@IsBoolean()
|
||||
@ApiProperty({ example: true })
|
||||
isDefault!: boolean;
|
||||
|
||||
@IsArray()
|
||||
@IsOptional()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => ScheduleOverrideInput_2024_06_11)
|
||||
@ApiProperty({
|
||||
type: [ScheduleOverrideInput_2024_06_11],
|
||||
example: [
|
||||
{
|
||||
date: "2024-05-20",
|
||||
startTime: "12:00",
|
||||
endTime: "14:00",
|
||||
},
|
||||
],
|
||||
required: false,
|
||||
})
|
||||
overrides?: ScheduleOverrideInput_2024_06_11[];
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from "./create-schedule.input";
|
||||
export * from "./update-schedule.input";
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
import { ApiProperty } from "@nestjs/swagger";
|
||||
import { Type } from "class-transformer";
|
||||
import { IsString, IsBoolean, IsOptional, ValidateNested, IsArray, IsTimeZone } from "class-validator";
|
||||
|
||||
import {
|
||||
ScheduleAvailabilityInput_2024_06_11,
|
||||
ScheduleOverrideInput_2024_06_11,
|
||||
} from "./create-schedule.input";
|
||||
|
||||
export class UpdateScheduleInput_2024_06_11 {
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@ApiProperty({ example: "One-on-one coaching", required: false })
|
||||
name?: string;
|
||||
|
||||
@IsTimeZone()
|
||||
@IsOptional()
|
||||
@ApiProperty({ example: "Europe/Rome", required: false })
|
||||
timeZone?: string;
|
||||
|
||||
@IsArray()
|
||||
@IsOptional()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => ScheduleAvailabilityInput_2024_06_11)
|
||||
@ApiProperty({
|
||||
type: [ScheduleAvailabilityInput_2024_06_11],
|
||||
example: [
|
||||
{
|
||||
days: ["Monday", "Tuesday"],
|
||||
startTime: "09:00",
|
||||
endTime: "10:00",
|
||||
},
|
||||
],
|
||||
required: false,
|
||||
})
|
||||
availability?: ScheduleAvailabilityInput_2024_06_11[];
|
||||
|
||||
@IsBoolean()
|
||||
@IsOptional()
|
||||
@ApiProperty({ example: true, required: false })
|
||||
isDefault?: boolean;
|
||||
|
||||
@IsArray()
|
||||
@IsOptional()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => ScheduleOverrideInput_2024_06_11)
|
||||
@ApiProperty({
|
||||
type: [ScheduleOverrideInput_2024_06_11],
|
||||
example: [
|
||||
{
|
||||
date: "2024-05-20",
|
||||
startTime: "12:00",
|
||||
endTime: "14:00",
|
||||
},
|
||||
],
|
||||
required: false,
|
||||
})
|
||||
overrides?: ScheduleOverrideInput_2024_06_11[];
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
import { ApiProperty } from "@nestjs/swagger";
|
||||
import { Type } from "class-transformer";
|
||||
import { IsEnum, IsNotEmptyObject, ValidateNested } from "class-validator";
|
||||
|
||||
import { SUCCESS_STATUS, ERROR_STATUS } from "@calcom/platform-constants";
|
||||
|
||||
import { ScheduleOutput_2024_06_11 } from "./schedule.output";
|
||||
|
||||
export class CreateScheduleOutput_2024_06_11 {
|
||||
@ApiProperty({ example: SUCCESS_STATUS, enum: [SUCCESS_STATUS, ERROR_STATUS] })
|
||||
@IsEnum([SUCCESS_STATUS, ERROR_STATUS])
|
||||
status!: typeof SUCCESS_STATUS | typeof ERROR_STATUS;
|
||||
@ApiProperty({
|
||||
type: ScheduleOutput_2024_06_11,
|
||||
})
|
||||
@IsNotEmptyObject()
|
||||
@ValidateNested()
|
||||
@Type(() => ScheduleOutput_2024_06_11)
|
||||
data!: ScheduleOutput_2024_06_11;
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
import { ApiProperty } from "@nestjs/swagger";
|
||||
import { IsEnum } from "class-validator";
|
||||
|
||||
import { SUCCESS_STATUS, ERROR_STATUS } from "@calcom/platform-constants";
|
||||
|
||||
export class DeleteScheduleOutput_2024_06_11 {
|
||||
@ApiProperty({ example: SUCCESS_STATUS, enum: [SUCCESS_STATUS, ERROR_STATUS] })
|
||||
@IsEnum([SUCCESS_STATUS, ERROR_STATUS])
|
||||
status!: typeof SUCCESS_STATUS | typeof ERROR_STATUS;
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
import { ApiProperty } from "@nestjs/swagger";
|
||||
import { Type } from "class-transformer";
|
||||
import { IsEnum, IsNotEmptyObject, ValidateNested } from "class-validator";
|
||||
|
||||
import { SUCCESS_STATUS, ERROR_STATUS } from "@calcom/platform-constants";
|
||||
|
||||
import { ScheduleOutput_2024_06_11 } from "./schedule.output";
|
||||
|
||||
export class GetDefaultScheduleOutput_2024_06_11 {
|
||||
@ApiProperty({ example: SUCCESS_STATUS, enum: [SUCCESS_STATUS, ERROR_STATUS] })
|
||||
@IsEnum([SUCCESS_STATUS, ERROR_STATUS])
|
||||
status!: typeof SUCCESS_STATUS | typeof ERROR_STATUS;
|
||||
@ApiProperty({
|
||||
type: ScheduleOutput_2024_06_11,
|
||||
})
|
||||
@IsNotEmptyObject()
|
||||
@ValidateNested()
|
||||
@Type(() => ScheduleOutput_2024_06_11)
|
||||
data!: ScheduleOutput_2024_06_11 | null;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import { ApiProperty } from "@nestjs/swagger";
|
||||
import { Type } from "class-transformer";
|
||||
import { IsEnum, IsNotEmptyObject, ValidateNested } from "class-validator";
|
||||
|
||||
import { SUCCESS_STATUS, ERROR_STATUS } from "@calcom/platform-constants";
|
||||
|
||||
import { ScheduleOutput_2024_06_11 } from "./schedule.output";
|
||||
|
||||
export class GetScheduleOutput_2024_06_11 {
|
||||
@ApiProperty({ example: SUCCESS_STATUS, enum: [SUCCESS_STATUS, ERROR_STATUS] })
|
||||
@IsEnum([SUCCESS_STATUS, ERROR_STATUS])
|
||||
status!: typeof SUCCESS_STATUS | typeof ERROR_STATUS;
|
||||
|
||||
@ApiProperty({
|
||||
type: ScheduleOutput_2024_06_11,
|
||||
})
|
||||
@IsNotEmptyObject()
|
||||
@ValidateNested()
|
||||
@Type(() => ScheduleOutput_2024_06_11)
|
||||
data!: ScheduleOutput_2024_06_11 | null;
|
||||
|
||||
error?: Error;
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
import { ApiProperty } from "@nestjs/swagger";
|
||||
import { Type } from "class-transformer";
|
||||
import { IsArray, IsEnum, IsNotEmptyObject, ValidateNested } from "class-validator";
|
||||
|
||||
import { SUCCESS_STATUS, ERROR_STATUS } from "@calcom/platform-constants";
|
||||
|
||||
import { ScheduleOutput_2024_06_11 } from "./schedule.output";
|
||||
|
||||
export class GetSchedulesOutput_2024_06_11 {
|
||||
@ApiProperty({ example: SUCCESS_STATUS, enum: [SUCCESS_STATUS, ERROR_STATUS] })
|
||||
@IsEnum([SUCCESS_STATUS, ERROR_STATUS])
|
||||
status!: typeof SUCCESS_STATUS | typeof ERROR_STATUS;
|
||||
|
||||
@ApiProperty({ type: [ScheduleOutput_2024_06_11] })
|
||||
@IsNotEmptyObject()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => ScheduleOutput_2024_06_11)
|
||||
@IsArray()
|
||||
data!: ScheduleOutput_2024_06_11[];
|
||||
|
||||
error?: Error;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
export * from "./schedule.output";
|
||||
export * from "./get-schedule.output";
|
||||
export * from "./get-schedules.output";
|
||||
export * from "./get-default-schedule.output";
|
||||
export * from "./create-schedule.output";
|
||||
export * from "./update-schedule.output";
|
||||
export * from "./delete-schedule.output";
|
||||
@@ -0,0 +1,69 @@
|
||||
import { ApiProperty } from "@nestjs/swagger";
|
||||
import { Type } from "class-transformer";
|
||||
import {
|
||||
IsBoolean,
|
||||
IsOptional,
|
||||
IsString,
|
||||
ValidateNested,
|
||||
IsArray,
|
||||
IsTimeZone,
|
||||
IsNumber,
|
||||
} from "class-validator";
|
||||
|
||||
import {
|
||||
ScheduleAvailabilityInput_2024_06_11,
|
||||
ScheduleOverrideInput_2024_06_11,
|
||||
} from "../inputs/create-schedule.input";
|
||||
|
||||
export class ScheduleOutput_2024_06_11 {
|
||||
@IsNumber()
|
||||
@ApiProperty({ example: 254 })
|
||||
id!: number;
|
||||
|
||||
@IsNumber()
|
||||
@ApiProperty({ example: 478 })
|
||||
ownerId!: number;
|
||||
|
||||
@IsString()
|
||||
@ApiProperty({ example: "One-on-one coaching" })
|
||||
name!: string;
|
||||
|
||||
@IsTimeZone()
|
||||
@ApiProperty({ example: "Europe/Rome" })
|
||||
timeZone!: string;
|
||||
|
||||
@IsArray()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => ScheduleAvailabilityInput_2024_06_11)
|
||||
@ApiProperty({
|
||||
type: [ScheduleAvailabilityInput_2024_06_11],
|
||||
example: [
|
||||
{
|
||||
days: ["Monday", "Tuesday"],
|
||||
startTime: "09:00",
|
||||
endTime: "10:00",
|
||||
},
|
||||
],
|
||||
})
|
||||
availability!: ScheduleAvailabilityInput_2024_06_11[];
|
||||
|
||||
@IsBoolean()
|
||||
@ApiProperty({ example: true })
|
||||
isDefault!: boolean;
|
||||
|
||||
@IsArray()
|
||||
@IsOptional()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => ScheduleOverrideInput_2024_06_11)
|
||||
@ApiProperty({
|
||||
type: [ScheduleOverrideInput_2024_06_11],
|
||||
example: [
|
||||
{
|
||||
date: "2024-05-20",
|
||||
startTime: "12:00",
|
||||
endTime: "13:00",
|
||||
},
|
||||
],
|
||||
})
|
||||
overrides!: ScheduleOverrideInput_2024_06_11[];
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
import { ApiProperty } from "@nestjs/swagger";
|
||||
import { Type } from "class-transformer";
|
||||
import { IsEnum, IsNotEmptyObject, ValidateNested } from "class-validator";
|
||||
|
||||
import { SUCCESS_STATUS, ERROR_STATUS } from "@calcom/platform-constants";
|
||||
|
||||
import { ScheduleOutput_2024_06_11 } from "./schedule.output";
|
||||
|
||||
export class UpdateScheduleOutput_2024_06_11 {
|
||||
@ApiProperty({ example: SUCCESS_STATUS, enum: [SUCCESS_STATUS, ERROR_STATUS] })
|
||||
@IsEnum([SUCCESS_STATUS, ERROR_STATUS])
|
||||
status!: typeof SUCCESS_STATUS | typeof ERROR_STATUS;
|
||||
|
||||
@ApiProperty({
|
||||
type: ScheduleOutput_2024_06_11,
|
||||
})
|
||||
@IsNotEmptyObject()
|
||||
@ValidateNested()
|
||||
@Type(() => ScheduleOutput_2024_06_11)
|
||||
data!: ScheduleOutput_2024_06_11;
|
||||
|
||||
error?: Error;
|
||||
}
|
||||
@@ -1,8 +1,7 @@
|
||||
import type { ScheduleWithAvailabilitiesForWeb } from "@calcom/lib";
|
||||
import {
|
||||
transformAvailabilityForClient,
|
||||
transformDateOverridesForClient,
|
||||
transformWorkingHoursForClient,
|
||||
transformAvailabilityForAtom,
|
||||
transformDateOverridesForAtom,
|
||||
transformWorkingHoursForAtom,
|
||||
} from "@calcom/lib";
|
||||
import { hasReadPermissionsForUserId } from "@calcom/lib/hasEditPermissionForUser";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
@@ -20,7 +19,7 @@ type GetOptions = {
|
||||
input: TGetInputSchema;
|
||||
};
|
||||
|
||||
export const getHandler = async ({ ctx, input }: GetOptions): Promise<ScheduleWithAvailabilitiesForWeb> => {
|
||||
export const getHandler = async ({ ctx, input }: GetOptions) => {
|
||||
const { user } = ctx;
|
||||
|
||||
const schedule = await prisma.schedule.findUnique({
|
||||
@@ -66,11 +65,11 @@ export const getHandler = async ({ ctx, input }: GetOptions): Promise<ScheduleWi
|
||||
id: schedule.id,
|
||||
name: schedule.name,
|
||||
isManaged: schedule.userId !== user.id,
|
||||
workingHours: transformWorkingHoursForClient(schedule),
|
||||
workingHours: transformWorkingHoursForAtom(schedule),
|
||||
schedule: schedule.availability,
|
||||
availability: transformAvailabilityForClient(schedule),
|
||||
availability: transformAvailabilityForAtom(schedule),
|
||||
timeZone,
|
||||
dateOverrides: transformDateOverridesForClient(schedule, timeZone),
|
||||
dateOverrides: transformDateOverridesForAtom(schedule, timeZone),
|
||||
isDefault: !input.scheduleId || user.defaultScheduleId === schedule.id,
|
||||
isLastSchedule: schedulesCount <= 1,
|
||||
readOnly: schedule.userId !== user.id && !input.isManagedEventType,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { transformScheduleToAvailabilityForClient } from "@calcom/lib";
|
||||
import { transformScheduleToAvailabilityForAtom } from "@calcom/lib";
|
||||
import { getAvailabilityFromSchedule } from "@calcom/lib/availability";
|
||||
import { hasEditPermissionForUserID } from "@calcom/lib/hasEditPermissionForUser";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
@@ -118,7 +118,7 @@ export const updateHandler = async ({ input, ctx }: UpdateOptions) => {
|
||||
},
|
||||
});
|
||||
|
||||
const userAvailability = transformScheduleToAvailabilityForClient(schedule);
|
||||
const userAvailability = transformScheduleToAvailabilityForAtom(schedule);
|
||||
|
||||
return {
|
||||
schedule,
|
||||
|
||||
Reference in new issue
Block a user