refactor: Deprecate Legacy v2 Booker Atom Endpoints (#20939)
* feat: split atoms endpoints and add public event type endpoint * Update ConnectedDestinationCalendars import path across platform/atoms components * refactor: update BookingResponse import path from platform-libraries to features/bookings * Move AvailableSlotsType to util.ts and update imports to use GetAvailableSlotsResponse * Refactor import path for RecurringBookingCreateBody type from libraries to types * Fix import path for getBookingForReschedule type from platform-libraries to features * Refactor PublicEventType export location and update import references * Remove @calcom/platform-libraries dependency from atoms package.json * chore(deps): update yarn.lock dependencies * Remove console.log statements and fix indentation in event type hooks * Migrate event type transformers from platform/libraries to api/v2 directory * Remove console.log * Update BookerPlatformWrapper.tsx * Add script to populate empty team slugs with slugified team names * Remove vitest imports * reset platform libraries version * Remove unused orgId comment from useAtomGetPublicEvent hook params * Update useApiV2AvailableSlots.ts * refactor: remove unused exports from lib package index file * Undo: @SomayChauhan Add script to populate empty team slugs with slugified team names * Update booking.tsx * chore: upgrade @calcom/platform-libraries from 0.0.202 to 0.0.205 * chore: bump @calcom/platform-libraries from 0.0.205 to 0.0.206 * chore: configure babel and jest for node module transpilation in api v2 * fix: type errors * Revert "chore: configure babel and jest for node module transpilation in api v2" This reverts commit b2cf172a84fe8953f9497bf6e43874f476fbc04b. * Update calendars.service.ts * chore: bump @calcom/platform-libraries from 0.0.208 to 0.0.209 * fix: add proper type definition for calendar busy times to resolve ts-expect-error * refactor: deprecate v2 old availability endpoints (#21075) Co-authored-by: Morgan <[email protected]> * chore: publish platform librareis * feat: add delegation credential fields to calendar service mock * chore: update @calcom/platform-libraries from 0.0.211 to 0.0.213 * fix: skip failing calendar integration test * chore: bump @calcom/platform-libraries from 0.0.213 to 0.0.214 * fix: api/v2 build error * fix: e2e tests --------- Co-authored-by: Morgan <[email protected]> Co-authored-by: supalarry <[email protected]> Co-authored-by: Lauris Skraucis <[email protected]>
This commit is contained in:
105 files changed
+6611
-1552
No files matched your search
@@ -221,6 +221,7 @@ function isAvailableInTimeSlot(
|
||||
return isWithinPeriod;
|
||||
}
|
||||
|
||||
export type PublicEventType = Awaited<ReturnType<typeof getPublicEvent>>;
|
||||
// TODO: Convert it to accept a single parameter with structured data
|
||||
export const getPublicEvent = async (
|
||||
username: string,
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import axios from "axios";
|
||||
|
||||
import type { AvailableSlotsType } from "@calcom/platform-libraries";
|
||||
import type {
|
||||
GetAvailableSlotsInput_2024_04_15,
|
||||
ApiResponse,
|
||||
ApiSuccessResponse,
|
||||
} from "@calcom/platform-types";
|
||||
import type { GetAvailableSlotsResponse } from "@calcom/trpc/server/routers/viewer/slots/util";
|
||||
|
||||
export const QUERY_KEY = "get-available-slots";
|
||||
|
||||
@@ -32,12 +32,15 @@ export const useApiV2AvailableSlots = ({
|
||||
],
|
||||
queryFn: () => {
|
||||
return axios
|
||||
.get<ApiResponse<AvailableSlotsType>>(`${process.env.NEXT_PUBLIC_API_V2_URL}/slots/available`, {
|
||||
params: rest,
|
||||
})
|
||||
.get<ApiResponse<GetAvailableSlotsResponse>>(
|
||||
`${process.env.NEXT_PUBLIC_API_V2_URL}/slots/available`,
|
||||
{
|
||||
params: rest,
|
||||
}
|
||||
)
|
||||
.then((res) => {
|
||||
if (res.data.status === "success") {
|
||||
return (res.data as ApiSuccessResponse<AvailableSlotsType>).data;
|
||||
return (res.data as ApiSuccessResponse<GetAvailableSlotsResponse>).data;
|
||||
}
|
||||
throw new Error(res.data.error.message);
|
||||
});
|
||||
|
||||
@@ -133,6 +133,13 @@ const commons = {
|
||||
rrTimestampBasis: null,
|
||||
interfaceLanguage: null,
|
||||
customReplyToEmail: null,
|
||||
profileId: null,
|
||||
requiresConfirmationWillBlockSlot: false,
|
||||
canSendCalVideoTranscriptionEmails: false,
|
||||
instantMeetingExpiryTimeOffsetInSeconds: 0,
|
||||
instantMeetingScheduleId: null,
|
||||
instantMeetingParameters: [],
|
||||
eventTypeColor: null,
|
||||
};
|
||||
|
||||
export const dynamicEvent = {
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
export * from "./transformers";
|
||||
@@ -1,944 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
BookerLayoutsInputEnum_2024_06_14,
|
||||
BookerLayoutsOutputEnum_2024_06_14,
|
||||
ConfirmationPolicyEnum,
|
||||
NoticeThresholdUnitEnum,
|
||||
FrequencyInput,
|
||||
} from "@calcom/platform-enums/monorepo";
|
||||
import type {
|
||||
InputBookingField_2024_06_14,
|
||||
InputLocation_2024_06_14,
|
||||
BookingLimitsCount_2024_06_14,
|
||||
BookingWindow_2024_06_14,
|
||||
BookerLayouts_2024_06_14,
|
||||
ConfirmationPolicy_2024_06_14,
|
||||
EventTypeColor_2024_06_14,
|
||||
Recurrence_2024_06_14,
|
||||
CreateEventTypeInput_2024_06_14,
|
||||
SeatOptionsTransformedSchema,
|
||||
SeatOptionsDisabledSchema,
|
||||
InputAttendeeAddressLocation_2024_06_14,
|
||||
InputAttendeePhoneLocation_2024_06_14,
|
||||
InputAttendeeDefinedLocation_2024_06_14,
|
||||
InputTeamLocation_2024_06_14,
|
||||
} from "@calcom/platform-types";
|
||||
|
||||
import {
|
||||
systemBeforeFieldEmail,
|
||||
systemBeforeFieldName,
|
||||
type CustomField,
|
||||
type SystemField,
|
||||
} from "../internal-to-api/booking-fields";
|
||||
import {
|
||||
transformLocationsApiToInternal,
|
||||
transformBookingFieldsApiToInternal,
|
||||
transformSelectOptionsApiToInternal,
|
||||
transformIntervalLimitsApiToInternal,
|
||||
transformFutureBookingLimitsApiToInternal,
|
||||
transformRecurrenceApiToInternal,
|
||||
transformSeatsApiToInternal,
|
||||
transformEventColorsApiToInternal,
|
||||
transformBookerLayoutsApiToInternal,
|
||||
transformConfirmationPolicyApiToInternal,
|
||||
transformTeamLocationsApiToInternal,
|
||||
} from "./index";
|
||||
|
||||
describe("transformLocationsApiToInternal", () => {
|
||||
it("should transform address", () => {
|
||||
const input: InputLocation_2024_06_14[] = [
|
||||
{
|
||||
type: "address",
|
||||
address: "London road 10-1",
|
||||
public: true,
|
||||
},
|
||||
];
|
||||
|
||||
const expectedOutput = [{ type: "inPerson", address: "London road 10-1", displayLocationPublicly: true }];
|
||||
|
||||
const result = transformLocationsApiToInternal(input);
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
|
||||
it("should transform link", () => {
|
||||
const input: InputLocation_2024_06_14[] = [
|
||||
{
|
||||
type: "link",
|
||||
link: "https://customvideo.com/join/123456",
|
||||
public: true,
|
||||
},
|
||||
];
|
||||
|
||||
const expectedOutput = [
|
||||
{ type: "link", link: "https://customvideo.com/join/123456", displayLocationPublicly: true },
|
||||
];
|
||||
|
||||
const result = transformLocationsApiToInternal(input);
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
|
||||
it("should transform integration", () => {
|
||||
const input: InputLocation_2024_06_14[] = [
|
||||
{
|
||||
type: "integration",
|
||||
integration: "cal-video",
|
||||
},
|
||||
];
|
||||
|
||||
const expectedOutput = [{ type: "integrations:daily" }];
|
||||
|
||||
const result = transformLocationsApiToInternal(input);
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
|
||||
it("should transform phone", () => {
|
||||
const input: InputLocation_2024_06_14[] = [
|
||||
{
|
||||
type: "phone",
|
||||
phone: "+37120993151",
|
||||
public: true,
|
||||
},
|
||||
];
|
||||
|
||||
const expectedOutput = [
|
||||
{ type: "userPhone", hostPhoneNumber: "+37120993151", displayLocationPublicly: true },
|
||||
];
|
||||
|
||||
const result = transformLocationsApiToInternal(input);
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
|
||||
it("should transform OrganizersDefaultApp", () => {
|
||||
const input: InputTeamLocation_2024_06_14[] = [
|
||||
{
|
||||
type: "organizersDefaultApp",
|
||||
},
|
||||
];
|
||||
|
||||
const expectedOutput = [{ type: "conferencing" }];
|
||||
|
||||
const result = transformTeamLocationsApiToInternal(input);
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
|
||||
it("should transform attendee address", () => {
|
||||
const input: InputAttendeeAddressLocation_2024_06_14[] = [
|
||||
{
|
||||
type: "attendeeAddress",
|
||||
},
|
||||
];
|
||||
|
||||
const expectedOutput = [{ type: "attendeeInPerson" }];
|
||||
|
||||
const result = transformLocationsApiToInternal(input);
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
|
||||
it("should transform attendee phone", () => {
|
||||
const input: InputAttendeePhoneLocation_2024_06_14[] = [
|
||||
{
|
||||
type: "attendeePhone",
|
||||
},
|
||||
];
|
||||
|
||||
const expectedOutput = [{ type: "phone" }];
|
||||
|
||||
const result = transformLocationsApiToInternal(input);
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
|
||||
it("should transform attendee defined", () => {
|
||||
const input: InputAttendeeDefinedLocation_2024_06_14[] = [
|
||||
{
|
||||
type: "attendeeDefined",
|
||||
},
|
||||
];
|
||||
|
||||
const expectedOutput = [{ type: "somewhereElse" }];
|
||||
|
||||
const result = transformLocationsApiToInternal(input);
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
});
|
||||
|
||||
describe("transformBookingFieldsApiToInternal", () => {
|
||||
it("should transform name field", () => {
|
||||
const bookingField: InputBookingField_2024_06_14 = {
|
||||
type: "name",
|
||||
label: "Your name number",
|
||||
placeholder: "123456789",
|
||||
disableOnPrefill: true,
|
||||
};
|
||||
const input: InputBookingField_2024_06_14[] = [bookingField];
|
||||
|
||||
const expectedField = {
|
||||
...systemBeforeFieldName,
|
||||
label: "Your name number",
|
||||
placeholder: "123456789",
|
||||
disableOnPrefill: true,
|
||||
};
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
expectedField.variantsConfig.variants.fullName.fields[0].label = "Your name number";
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
expectedField.variantsConfig.variants.fullName.fields[0].placeholder = "123456789";
|
||||
|
||||
const expectedOutput: SystemField[] = [expectedField];
|
||||
|
||||
const result = transformBookingFieldsApiToInternal(input);
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
|
||||
it("should transform email field", () => {
|
||||
const bookingField: InputBookingField_2024_06_14 = {
|
||||
type: "email",
|
||||
label: "Your email",
|
||||
placeholder: "[email protected]",
|
||||
disableOnPrefill: true,
|
||||
required: true,
|
||||
};
|
||||
|
||||
const input: InputBookingField_2024_06_14[] = [bookingField];
|
||||
|
||||
const expectedOutput: SystemField[] = [
|
||||
{
|
||||
...systemBeforeFieldEmail,
|
||||
label: "Your email",
|
||||
placeholder: "[email protected]",
|
||||
disableOnPrefill: true,
|
||||
hidden: false,
|
||||
},
|
||||
];
|
||||
|
||||
const result = transformBookingFieldsApiToInternal(input);
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
|
||||
it("should transform phone field", () => {
|
||||
const bookingField: InputBookingField_2024_06_14 = {
|
||||
type: "phone",
|
||||
slug: "phone",
|
||||
label: "Your phone number",
|
||||
required: true,
|
||||
placeholder: "123456789",
|
||||
};
|
||||
|
||||
const input: InputBookingField_2024_06_14[] = [bookingField];
|
||||
|
||||
const expectedOutput: CustomField[] = [
|
||||
{
|
||||
name: bookingField.slug,
|
||||
type: bookingField.type,
|
||||
label: bookingField.label,
|
||||
sources: [
|
||||
{
|
||||
id: "user",
|
||||
type: "user",
|
||||
label: "User",
|
||||
fieldRequired: true,
|
||||
},
|
||||
],
|
||||
editable: "user",
|
||||
required: bookingField.required,
|
||||
placeholder: bookingField.placeholder,
|
||||
disableOnPrefill: false,
|
||||
hidden: false,
|
||||
},
|
||||
];
|
||||
|
||||
const result = transformBookingFieldsApiToInternal(input);
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
|
||||
it("should transform address field", () => {
|
||||
const bookingField: InputBookingField_2024_06_14 = {
|
||||
type: "address",
|
||||
slug: "address",
|
||||
label: "Your address",
|
||||
required: true,
|
||||
placeholder: "1234 Main St",
|
||||
};
|
||||
|
||||
const input: InputBookingField_2024_06_14[] = [bookingField];
|
||||
|
||||
const expectedOutput: CustomField[] = [
|
||||
{
|
||||
name: bookingField.slug,
|
||||
type: bookingField.type,
|
||||
label: bookingField.label,
|
||||
sources: [
|
||||
{
|
||||
id: "user",
|
||||
type: "user",
|
||||
label: "User",
|
||||
fieldRequired: true,
|
||||
},
|
||||
],
|
||||
editable: "user",
|
||||
required: bookingField.required,
|
||||
placeholder: bookingField.placeholder,
|
||||
disableOnPrefill: false,
|
||||
hidden: false,
|
||||
},
|
||||
];
|
||||
|
||||
const result = transformBookingFieldsApiToInternal(input);
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
|
||||
it("should transform text field", () => {
|
||||
const bookingField: InputBookingField_2024_06_14 = {
|
||||
type: "text",
|
||||
slug: "text",
|
||||
label: "Your text",
|
||||
required: true,
|
||||
placeholder: "Enter your text",
|
||||
};
|
||||
|
||||
const input: InputBookingField_2024_06_14[] = [bookingField];
|
||||
|
||||
const expectedOutput: CustomField[] = [
|
||||
{
|
||||
name: bookingField.slug,
|
||||
type: bookingField.type,
|
||||
label: bookingField.label,
|
||||
sources: [
|
||||
{
|
||||
id: "user",
|
||||
type: "user",
|
||||
label: "User",
|
||||
fieldRequired: true,
|
||||
},
|
||||
],
|
||||
editable: "user",
|
||||
required: bookingField.required,
|
||||
placeholder: bookingField.placeholder,
|
||||
disableOnPrefill: false,
|
||||
hidden: false,
|
||||
},
|
||||
];
|
||||
|
||||
const result = transformBookingFieldsApiToInternal(input);
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
|
||||
it("should transform number field", () => {
|
||||
const bookingField: InputBookingField_2024_06_14 = {
|
||||
type: "number",
|
||||
slug: "number",
|
||||
label: "Your number",
|
||||
required: true,
|
||||
placeholder: "100",
|
||||
};
|
||||
|
||||
const input: InputBookingField_2024_06_14[] = [bookingField];
|
||||
|
||||
const expectedOutput: CustomField[] = [
|
||||
{
|
||||
name: bookingField.slug,
|
||||
type: bookingField.type,
|
||||
label: bookingField.label,
|
||||
sources: [
|
||||
{
|
||||
id: "user",
|
||||
type: "user",
|
||||
label: "User",
|
||||
fieldRequired: true,
|
||||
},
|
||||
],
|
||||
editable: "user",
|
||||
required: bookingField.required,
|
||||
placeholder: bookingField.placeholder,
|
||||
disableOnPrefill: false,
|
||||
hidden: false,
|
||||
},
|
||||
];
|
||||
|
||||
const result = transformBookingFieldsApiToInternal(input);
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
|
||||
it("should transform textarea field", () => {
|
||||
const bookingField: InputBookingField_2024_06_14 = {
|
||||
type: "textarea",
|
||||
slug: "textarea",
|
||||
label: "Your detailed information",
|
||||
required: true,
|
||||
placeholder: "Detailed description here...",
|
||||
};
|
||||
|
||||
const input: InputBookingField_2024_06_14[] = [bookingField];
|
||||
|
||||
const expectedOutput: CustomField[] = [
|
||||
{
|
||||
name: bookingField.slug,
|
||||
type: bookingField.type,
|
||||
label: bookingField.label,
|
||||
sources: [
|
||||
{
|
||||
id: "user",
|
||||
type: "user",
|
||||
label: "User",
|
||||
fieldRequired: true,
|
||||
},
|
||||
],
|
||||
editable: "user",
|
||||
required: bookingField.required,
|
||||
placeholder: bookingField.placeholder,
|
||||
disableOnPrefill: false,
|
||||
hidden: false,
|
||||
},
|
||||
];
|
||||
|
||||
const result = transformBookingFieldsApiToInternal(input);
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
|
||||
it("should transform select field", () => {
|
||||
const bookingField: InputBookingField_2024_06_14 = {
|
||||
type: "select",
|
||||
slug: "select",
|
||||
label: "Your selection",
|
||||
required: true,
|
||||
placeholder: "Select...",
|
||||
options: ["Option 1", "Option 2"],
|
||||
};
|
||||
|
||||
const input: InputBookingField_2024_06_14[] = [bookingField];
|
||||
|
||||
const expectedOutput: CustomField[] = [
|
||||
{
|
||||
name: bookingField.slug,
|
||||
type: bookingField.type,
|
||||
label: bookingField.label,
|
||||
sources: [
|
||||
{
|
||||
id: "user",
|
||||
type: "user",
|
||||
label: "User",
|
||||
fieldRequired: true,
|
||||
},
|
||||
],
|
||||
editable: "user",
|
||||
required: bookingField.required,
|
||||
placeholder: bookingField.placeholder,
|
||||
options: transformSelectOptionsApiToInternal(bookingField.options),
|
||||
disableOnPrefill: false,
|
||||
hidden: false,
|
||||
},
|
||||
];
|
||||
|
||||
const result = transformBookingFieldsApiToInternal(input);
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
|
||||
it("should transform multiselect field", () => {
|
||||
const bookingField: InputBookingField_2024_06_14 = {
|
||||
type: "multiselect",
|
||||
slug: "multiselect",
|
||||
label: "Your multiple selections",
|
||||
required: true,
|
||||
options: ["Option 1", "Option 2"],
|
||||
};
|
||||
|
||||
const input: InputBookingField_2024_06_14[] = [bookingField];
|
||||
|
||||
const expectedOutput: CustomField[] = [
|
||||
{
|
||||
name: bookingField.slug,
|
||||
type: bookingField.type,
|
||||
label: bookingField.label,
|
||||
sources: [
|
||||
{
|
||||
id: "user",
|
||||
type: "user",
|
||||
label: "User",
|
||||
fieldRequired: true,
|
||||
},
|
||||
],
|
||||
editable: "user",
|
||||
required: bookingField.required,
|
||||
options: transformSelectOptionsApiToInternal(bookingField.options),
|
||||
disableOnPrefill: false,
|
||||
hidden: false,
|
||||
},
|
||||
];
|
||||
|
||||
const result = transformBookingFieldsApiToInternal(input);
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
|
||||
it("should transform multiemail field", () => {
|
||||
const bookingField: InputBookingField_2024_06_14 = {
|
||||
type: "multiemail",
|
||||
slug: "multiemail",
|
||||
label: "Your multiple emails",
|
||||
required: true,
|
||||
placeholder: "[email protected]",
|
||||
};
|
||||
|
||||
const input: InputBookingField_2024_06_14[] = [bookingField];
|
||||
|
||||
const expectedOutput: CustomField[] = [
|
||||
{
|
||||
name: bookingField.slug,
|
||||
type: bookingField.type,
|
||||
label: bookingField.label,
|
||||
sources: [
|
||||
{
|
||||
id: "user",
|
||||
type: "user",
|
||||
label: "User",
|
||||
fieldRequired: true,
|
||||
},
|
||||
],
|
||||
editable: "user",
|
||||
required: bookingField.required,
|
||||
placeholder: bookingField.placeholder,
|
||||
disableOnPrefill: false,
|
||||
hidden: false,
|
||||
},
|
||||
];
|
||||
|
||||
const result = transformBookingFieldsApiToInternal(input);
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
|
||||
it("should transform checkbox field", () => {
|
||||
const bookingField: InputBookingField_2024_06_14 = {
|
||||
type: "checkbox",
|
||||
slug: "checkbox",
|
||||
label: "Your checkboxes",
|
||||
required: true,
|
||||
options: ["Checkbox 1", "Checkbox 2"],
|
||||
};
|
||||
|
||||
const input: InputBookingField_2024_06_14[] = [bookingField];
|
||||
|
||||
const expectedOutput: CustomField[] = [
|
||||
{
|
||||
name: bookingField.slug,
|
||||
type: bookingField.type,
|
||||
label: bookingField.label,
|
||||
sources: [
|
||||
{
|
||||
id: "user",
|
||||
type: "user",
|
||||
label: "User",
|
||||
fieldRequired: true,
|
||||
},
|
||||
],
|
||||
editable: "user",
|
||||
required: bookingField.required,
|
||||
options: transformSelectOptionsApiToInternal(bookingField.options),
|
||||
disableOnPrefill: false,
|
||||
hidden: false,
|
||||
},
|
||||
];
|
||||
|
||||
const result = transformBookingFieldsApiToInternal(input);
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
|
||||
it("should transform radio field", () => {
|
||||
const bookingField: InputBookingField_2024_06_14 = {
|
||||
type: "radio",
|
||||
slug: "radio",
|
||||
label: "Your radio buttons",
|
||||
required: true,
|
||||
options: ["Radio 1", "Radio 2"],
|
||||
};
|
||||
|
||||
const input: InputBookingField_2024_06_14[] = [bookingField];
|
||||
|
||||
const expectedOutput: CustomField[] = [
|
||||
{
|
||||
name: bookingField.slug,
|
||||
type: bookingField.type,
|
||||
label: bookingField.label,
|
||||
sources: [
|
||||
{
|
||||
id: "user",
|
||||
type: "user",
|
||||
label: "User",
|
||||
fieldRequired: true,
|
||||
},
|
||||
],
|
||||
editable: "user",
|
||||
required: bookingField.required,
|
||||
options: transformSelectOptionsApiToInternal(bookingField.options),
|
||||
disableOnPrefill: false,
|
||||
hidden: false,
|
||||
},
|
||||
];
|
||||
|
||||
const result = transformBookingFieldsApiToInternal(input);
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
|
||||
it("should transform boolean field", () => {
|
||||
const bookingField: InputBookingField_2024_06_14 = {
|
||||
type: "boolean",
|
||||
slug: "boolean",
|
||||
label: "Agree to terms?",
|
||||
required: true,
|
||||
};
|
||||
|
||||
const input: InputBookingField_2024_06_14[] = [bookingField];
|
||||
|
||||
const expectedOutput: CustomField[] = [
|
||||
{
|
||||
name: bookingField.slug,
|
||||
type: bookingField.type,
|
||||
label: bookingField.label,
|
||||
labelAsSafeHtml: `<p>${bookingField.label}</p>\n`,
|
||||
sources: [
|
||||
{
|
||||
id: "user",
|
||||
type: "user",
|
||||
label: "User",
|
||||
fieldRequired: true,
|
||||
},
|
||||
],
|
||||
editable: "user",
|
||||
required: bookingField.required,
|
||||
disableOnPrefill: false,
|
||||
hidden: false,
|
||||
},
|
||||
];
|
||||
|
||||
const result = transformBookingFieldsApiToInternal(input);
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
|
||||
it("should keep disableOnPrefill property", () => {
|
||||
const disableOnPrefill = true;
|
||||
|
||||
const bookingField: InputBookingField_2024_06_14 = {
|
||||
type: "radio",
|
||||
slug: "radio",
|
||||
label: "Your radio buttons",
|
||||
required: true,
|
||||
options: ["Radio 1", "Radio 2"],
|
||||
disableOnPrefill,
|
||||
};
|
||||
|
||||
const input: InputBookingField_2024_06_14[] = [bookingField];
|
||||
|
||||
const expectedOutput: CustomField[] = [
|
||||
{
|
||||
name: bookingField.slug,
|
||||
type: bookingField.type,
|
||||
label: bookingField.label,
|
||||
sources: [
|
||||
{
|
||||
id: "user",
|
||||
type: "user",
|
||||
label: "User",
|
||||
fieldRequired: true,
|
||||
},
|
||||
],
|
||||
editable: "user",
|
||||
required: bookingField.required,
|
||||
options: transformSelectOptionsApiToInternal(bookingField.options),
|
||||
disableOnPrefill,
|
||||
hidden: false,
|
||||
},
|
||||
];
|
||||
|
||||
const result = transformBookingFieldsApiToInternal(input);
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
});
|
||||
|
||||
describe("transformIntervalLimitsApiToInternal", () => {
|
||||
it("should transform booking limits count or booking limits duration", () => {
|
||||
const input: BookingLimitsCount_2024_06_14 = {
|
||||
day: 2,
|
||||
week: 11,
|
||||
month: 22,
|
||||
year: 33,
|
||||
};
|
||||
|
||||
const expectedOutput = {
|
||||
PER_DAY: 2,
|
||||
PER_WEEK: 11,
|
||||
PER_MONTH: 22,
|
||||
PER_YEAR: 33,
|
||||
};
|
||||
const result = transformIntervalLimitsApiToInternal(input);
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
});
|
||||
|
||||
describe("transformFutureBookingLimitsApiToInternal", () => {
|
||||
it("should transform range type", () => {
|
||||
const input: BookingWindow_2024_06_14 = {
|
||||
type: "range",
|
||||
value: ["2024-08-06", "2024-08-28"],
|
||||
};
|
||||
|
||||
const expectedOutput = {
|
||||
periodType: "RANGE",
|
||||
periodStartDate: new Date("2024-08-06"),
|
||||
periodEndDate: new Date("2024-08-28"),
|
||||
};
|
||||
|
||||
const result = transformFutureBookingLimitsApiToInternal(input);
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
it("should transform calendar days", () => {
|
||||
const input: BookingWindow_2024_06_14 = {
|
||||
type: "calendarDays",
|
||||
value: 30,
|
||||
rolling: false,
|
||||
};
|
||||
|
||||
const expectedOutput = {
|
||||
periodType: "ROLLING",
|
||||
periodDays: 30,
|
||||
periodCountCalendarDays: true,
|
||||
};
|
||||
|
||||
const result = transformFutureBookingLimitsApiToInternal(input);
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
it("should transform calendar days rolling-window", () => {
|
||||
const input: BookingWindow_2024_06_14 = {
|
||||
type: "calendarDays",
|
||||
value: 30,
|
||||
rolling: true,
|
||||
};
|
||||
|
||||
const expectedOutput = {
|
||||
periodType: "ROLLING_WINDOW",
|
||||
periodDays: 30,
|
||||
periodCountCalendarDays: true,
|
||||
};
|
||||
|
||||
const result = transformFutureBookingLimitsApiToInternal(input);
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
it("should transform Business days", () => {
|
||||
const input: BookingWindow_2024_06_14 = {
|
||||
type: "businessDays",
|
||||
value: 30,
|
||||
rolling: false,
|
||||
};
|
||||
|
||||
const expectedOutput = {
|
||||
periodType: "ROLLING",
|
||||
periodDays: 30,
|
||||
periodCountCalendarDays: false,
|
||||
};
|
||||
|
||||
const result = transformFutureBookingLimitsApiToInternal(input);
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
it("should transform Business days rolling-window", () => {
|
||||
const input: BookingWindow_2024_06_14 = {
|
||||
type: "businessDays",
|
||||
value: 30,
|
||||
rolling: true,
|
||||
};
|
||||
|
||||
const expectedOutput = {
|
||||
periodType: "ROLLING_WINDOW",
|
||||
periodDays: 30,
|
||||
periodCountCalendarDays: false,
|
||||
};
|
||||
|
||||
const result = transformFutureBookingLimitsApiToInternal(input);
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
|
||||
it("should transform disabled", () => {
|
||||
const input: BookingWindow_2024_06_14 = {
|
||||
disabled: true,
|
||||
};
|
||||
|
||||
const expectedOutput = {
|
||||
periodType: "UNLIMITED",
|
||||
};
|
||||
|
||||
const result = transformFutureBookingLimitsApiToInternal(input);
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
});
|
||||
|
||||
describe("transformBookerLayoutsApiToInternal", () => {
|
||||
it("should transform booker layouts", () => {
|
||||
const input: BookerLayouts_2024_06_14 = {
|
||||
enabledLayouts: [
|
||||
BookerLayoutsInputEnum_2024_06_14.column,
|
||||
BookerLayoutsInputEnum_2024_06_14.month,
|
||||
BookerLayoutsInputEnum_2024_06_14.week,
|
||||
],
|
||||
defaultLayout: BookerLayoutsInputEnum_2024_06_14.week,
|
||||
};
|
||||
|
||||
const expectedOutput = {
|
||||
enabledLayouts: [
|
||||
BookerLayoutsOutputEnum_2024_06_14.column_view,
|
||||
BookerLayoutsOutputEnum_2024_06_14.month_view,
|
||||
BookerLayoutsOutputEnum_2024_06_14.week_view,
|
||||
],
|
||||
defaultLayout: BookerLayoutsOutputEnum_2024_06_14.week_view,
|
||||
};
|
||||
const result = transformBookerLayoutsApiToInternal(input);
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
});
|
||||
|
||||
describe("transformConfirmationPolicyApiToInternal", () => {
|
||||
it("should transform requires confirmation - time", () => {
|
||||
const input: ConfirmationPolicy_2024_06_14 = {
|
||||
type: ConfirmationPolicyEnum.TIME,
|
||||
noticeThreshold: {
|
||||
count: 60,
|
||||
unit: NoticeThresholdUnitEnum.MINUTES,
|
||||
},
|
||||
blockUnconfirmedBookingsInBooker: true,
|
||||
};
|
||||
|
||||
const expectedOutput = {
|
||||
requiresConfirmation: true,
|
||||
requiresConfirmationThreshold: {
|
||||
time: 60,
|
||||
unit: NoticeThresholdUnitEnum.MINUTES,
|
||||
},
|
||||
requiresConfirmationWillBlockSlot: true,
|
||||
};
|
||||
const result = transformConfirmationPolicyApiToInternal(input);
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
|
||||
it("should transform requires confirmation - always", () => {
|
||||
const input: ConfirmationPolicy_2024_06_14 = {
|
||||
type: ConfirmationPolicyEnum.ALWAYS,
|
||||
blockUnconfirmedBookingsInBooker: true,
|
||||
};
|
||||
|
||||
const expectedOutput = {
|
||||
requiresConfirmation: true,
|
||||
requiresConfirmationWillBlockSlot: true,
|
||||
};
|
||||
const result = transformConfirmationPolicyApiToInternal(input);
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
|
||||
it("should transform requires confirmation - disabled", () => {
|
||||
const input: ConfirmationPolicy_2024_06_14 = {
|
||||
disabled: true,
|
||||
};
|
||||
|
||||
const expectedOutput = {
|
||||
requiresConfirmation: false,
|
||||
requiresConfirmationWillBlockSlot: false,
|
||||
requiresConfirmationThreshold: undefined,
|
||||
};
|
||||
const result = transformConfirmationPolicyApiToInternal(input);
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
});
|
||||
|
||||
describe("transformEventColorsApiToInternal", () => {
|
||||
it("should transform event type colors", () => {
|
||||
const input: EventTypeColor_2024_06_14 = {
|
||||
darkThemeHex: "#292929",
|
||||
lightThemeHex: "#fafafa",
|
||||
};
|
||||
|
||||
const expectedOutput = {
|
||||
darkEventTypeColor: "#292929",
|
||||
lightEventTypeColor: "#fafafa",
|
||||
};
|
||||
|
||||
const result = transformEventColorsApiToInternal(input);
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
});
|
||||
|
||||
describe("transformSeatsApiToInternal", () => {
|
||||
it("should transform seat options", () => {
|
||||
const input: CreateEventTypeInput_2024_06_14["seats"] = {
|
||||
seatsPerTimeSlot: 20,
|
||||
showAttendeeInfo: true,
|
||||
showAvailabilityCount: false,
|
||||
};
|
||||
|
||||
const expectedOutput: SeatOptionsTransformedSchema = {
|
||||
seatsPerTimeSlot: 20,
|
||||
seatsShowAttendees: true,
|
||||
seatsShowAvailabilityCount: false,
|
||||
};
|
||||
|
||||
const result = transformSeatsApiToInternal(input);
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
|
||||
it("should transform seat options - disabled", () => {
|
||||
const input: CreateEventTypeInput_2024_06_14["seats"] = {
|
||||
disabled: true,
|
||||
};
|
||||
|
||||
const expectedOutput: SeatOptionsDisabledSchema = {
|
||||
seatsPerTimeSlot: null,
|
||||
};
|
||||
|
||||
const result = transformSeatsApiToInternal(input);
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
});
|
||||
|
||||
describe("transformRecurrenceApiToInternal", () => {
|
||||
it("should transform recurrence", () => {
|
||||
const input: Recurrence_2024_06_14 = {
|
||||
frequency: FrequencyInput.weekly,
|
||||
interval: 2,
|
||||
occurrences: 10,
|
||||
};
|
||||
const expectedOutput = {
|
||||
interval: 2,
|
||||
count: 10,
|
||||
freq: 2,
|
||||
};
|
||||
const result = transformRecurrenceApiToInternal(input);
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
});
|
||||
@@ -1,22 +0,0 @@
|
||||
import {
|
||||
BookerLayoutsInputEnum_2024_06_14,
|
||||
BookerLayoutsOutputEnum_2024_06_14,
|
||||
} from "@calcom/platform-enums/monorepo";
|
||||
import { type CreateEventTypeInput_2024_06_14 } from "@calcom/platform-types";
|
||||
|
||||
export function transformBookerLayoutsApiToInternal(
|
||||
inputBookerLayout: CreateEventTypeInput_2024_06_14["bookerLayouts"]
|
||||
) {
|
||||
if (!inputBookerLayout) return undefined;
|
||||
|
||||
const inputToOutputMap = {
|
||||
[BookerLayoutsInputEnum_2024_06_14.month]: BookerLayoutsOutputEnum_2024_06_14.month_view,
|
||||
[BookerLayoutsInputEnum_2024_06_14.week]: BookerLayoutsOutputEnum_2024_06_14.week_view,
|
||||
[BookerLayoutsInputEnum_2024_06_14.column]: BookerLayoutsOutputEnum_2024_06_14.column_view,
|
||||
};
|
||||
|
||||
return {
|
||||
defaultLayout: inputToOutputMap[inputBookerLayout.defaultLayout],
|
||||
enabledLayouts: inputBookerLayout.enabledLayouts.map((layout) => inputToOutputMap[layout]),
|
||||
};
|
||||
}
|
||||
@@ -1,317 +0,0 @@
|
||||
import type {
|
||||
InputBookingField_2024_06_14,
|
||||
PhoneDefaultFieldOutput_2024_06_14,
|
||||
MultiSelectFieldInput_2024_06_14,
|
||||
CheckboxGroupFieldInput_2024_06_14,
|
||||
RadioGroupFieldInput_2024_06_14,
|
||||
NameDefaultFieldInput_2024_06_14,
|
||||
EmailDefaultFieldInput_2024_06_14,
|
||||
TitleDefaultFieldInput_2024_06_14,
|
||||
LocationDefaultFieldInput_2024_06_14,
|
||||
NotesDefaultFieldInput_2024_06_14,
|
||||
GuestsDefaultFieldInput_2024_06_14,
|
||||
RescheduleReasonDefaultFieldInput_2024_06_14,
|
||||
SplitNameDefaultFieldInput_2024_06_14,
|
||||
} from "@calcom/platform-types";
|
||||
|
||||
import {
|
||||
systemBeforeFieldEmail,
|
||||
systemBeforeFieldName,
|
||||
systemBeforeFieldLocation,
|
||||
systemBeforeFieldPhone,
|
||||
systemAfterFieldTitle,
|
||||
systemAfterFieldNotes,
|
||||
systemAfterFieldGuests,
|
||||
systemAfterFieldRescheduleReason,
|
||||
type CustomField,
|
||||
type SystemField,
|
||||
systemBeforeFieldNameSplit,
|
||||
} from "../internal-to-api";
|
||||
|
||||
type InputBookingField = InputBookingField_2024_06_14 | PhoneDefaultFieldOutput_2024_06_14;
|
||||
|
||||
export function transformBookingFieldsApiToInternal(bookingFields: InputBookingField[]) {
|
||||
const customBookingFields = bookingFields.map((field) => {
|
||||
const baseProperties = getBaseProperties(field);
|
||||
|
||||
const options =
|
||||
"options" in field && field.options ? transformSelectOptionsApiToInternal(field.options) : undefined;
|
||||
|
||||
if (!options) {
|
||||
return baseProperties;
|
||||
}
|
||||
|
||||
return {
|
||||
...baseProperties,
|
||||
options,
|
||||
};
|
||||
});
|
||||
|
||||
return customBookingFields;
|
||||
}
|
||||
|
||||
function getBaseProperties(field: InputBookingField): CustomField | SystemField {
|
||||
if (fieldIsSelect(field)) {
|
||||
return {
|
||||
name: field.slug,
|
||||
type: field.type,
|
||||
label: field.label,
|
||||
sources: [
|
||||
{
|
||||
id: "user",
|
||||
type: "user",
|
||||
label: "User",
|
||||
fieldRequired: true,
|
||||
},
|
||||
],
|
||||
editable: "user",
|
||||
required: field.required,
|
||||
disableOnPrefill: !!field.disableOnPrefill,
|
||||
hidden: "hidden" in field ? field.hidden : false,
|
||||
};
|
||||
}
|
||||
|
||||
if (fieldIsDefaultSystemLocation(field)) {
|
||||
return {
|
||||
...systemBeforeFieldLocation,
|
||||
label: field.label,
|
||||
};
|
||||
}
|
||||
|
||||
if (fieldIsDefaultAttendeePhone(field)) {
|
||||
return {
|
||||
...systemBeforeFieldPhone,
|
||||
required: field.required,
|
||||
hidden: field.hidden,
|
||||
label: field.label,
|
||||
placeholder: field.placeholder,
|
||||
disableOnPrefill: !!field.disableOnPrefill,
|
||||
};
|
||||
}
|
||||
|
||||
if (fieldIsCustomSystemName(field)) {
|
||||
const systemName = { ...systemBeforeFieldName };
|
||||
if (systemName.variantsConfig?.variants?.fullName?.fields?.[0]) {
|
||||
systemName.variantsConfig.variants.fullName.fields[0].label = field.label;
|
||||
}
|
||||
|
||||
if (systemName.variantsConfig?.variants?.fullName?.fields?.[0]) {
|
||||
systemName.variantsConfig.variants.fullName.fields[0].placeholder = field.placeholder;
|
||||
}
|
||||
// note(Lauris): we attach top level label and placeholder for easier access when converting database event type
|
||||
// to v2 response event type even though form builder uses label and placeholder from variantsConfig.
|
||||
systemName.label = field.label;
|
||||
systemName.placeholder = field.placeholder;
|
||||
|
||||
return {
|
||||
...systemName,
|
||||
disableOnPrefill: !!field.disableOnPrefill,
|
||||
};
|
||||
}
|
||||
|
||||
if (fieldIsCustomSystemNameSplit(field)) {
|
||||
const systemNameSplit = { ...systemBeforeFieldNameSplit };
|
||||
|
||||
const firstNameField = systemNameSplit.variantsConfig?.variants?.firstAndLastName?.fields?.find(
|
||||
(field) => field.name === "firstName"
|
||||
);
|
||||
const lastNameField = systemNameSplit.variantsConfig?.variants?.firstAndLastName?.fields?.find(
|
||||
(field) => field.name === "lastName"
|
||||
);
|
||||
|
||||
if (firstNameField) {
|
||||
firstNameField.label = field.firstNameLabel || "";
|
||||
firstNameField.placeholder = field.firstNamePlaceholder || "";
|
||||
}
|
||||
|
||||
if (lastNameField) {
|
||||
lastNameField.label = field.lastNameLabel || "";
|
||||
lastNameField.placeholder = field.lastNamePlaceholder || "";
|
||||
lastNameField.required = !!field.lastNameRequired;
|
||||
}
|
||||
|
||||
return {
|
||||
...systemNameSplit,
|
||||
disableOnPrefill: !!field.disableOnPrefill,
|
||||
};
|
||||
}
|
||||
|
||||
if (fieldIsCustomSystemEmail(field)) {
|
||||
return {
|
||||
...systemBeforeFieldEmail,
|
||||
label: field.label,
|
||||
placeholder: field.placeholder,
|
||||
disableOnPrefill: !!field.disableOnPrefill,
|
||||
required: field.required,
|
||||
hidden: !!field.hidden,
|
||||
};
|
||||
}
|
||||
|
||||
if (fieldIsCustomSystemRescheduleReason(field)) {
|
||||
return {
|
||||
...systemAfterFieldRescheduleReason,
|
||||
required: !!field.required,
|
||||
hidden: !!field.hidden,
|
||||
label: field.label,
|
||||
placeholder: "placeholder" in field ? field.placeholder : undefined,
|
||||
disableOnPrefill: !!field.disableOnPrefill,
|
||||
};
|
||||
}
|
||||
|
||||
if (fieldIsCustomSystemTitle(field)) {
|
||||
return {
|
||||
...systemAfterFieldTitle,
|
||||
required: !!field.required,
|
||||
hidden: !!field.hidden,
|
||||
label: field.label,
|
||||
placeholder: "placeholder" in field ? field.placeholder : undefined,
|
||||
disableOnPrefill: !!field.disableOnPrefill,
|
||||
};
|
||||
}
|
||||
|
||||
if (fieldIsCustomSystemNotes(field)) {
|
||||
return {
|
||||
...systemAfterFieldNotes,
|
||||
required: !!field.required,
|
||||
hidden: !!field.hidden,
|
||||
label: field.label,
|
||||
placeholder: "placeholder" in field ? field.placeholder : undefined,
|
||||
disableOnPrefill: !!field.disableOnPrefill,
|
||||
};
|
||||
}
|
||||
|
||||
if (fieldIsCustomSystemGuests(field)) {
|
||||
return {
|
||||
...systemAfterFieldGuests,
|
||||
required: !!field.required,
|
||||
hidden: !!field.hidden,
|
||||
label: field.label,
|
||||
placeholder: "placeholder" in field ? field.placeholder : undefined,
|
||||
disableOnPrefill: !!field.disableOnPrefill,
|
||||
};
|
||||
}
|
||||
|
||||
if (field.type === "boolean") {
|
||||
return {
|
||||
name: field.slug,
|
||||
type: field.type,
|
||||
label: field.label,
|
||||
labelAsSafeHtml: `<p>${field.label}</p>\n`,
|
||||
sources: [
|
||||
{
|
||||
id: "user",
|
||||
type: "user",
|
||||
label: "User",
|
||||
fieldRequired: true,
|
||||
},
|
||||
],
|
||||
editable: "user",
|
||||
required: !!field.required,
|
||||
disableOnPrefill: !!field.disableOnPrefill,
|
||||
hidden: !!field.hidden,
|
||||
};
|
||||
}
|
||||
|
||||
if (field.type === "url") {
|
||||
return {
|
||||
name: field.slug,
|
||||
type: field.type,
|
||||
label: field.label,
|
||||
placeholder: "placeholder" in field ? field.placeholder : "",
|
||||
labelAsSafeHtml: `<p>${field.label}</p>\n`,
|
||||
sources: [
|
||||
{
|
||||
id: "user",
|
||||
type: "user",
|
||||
label: "User",
|
||||
fieldRequired: true,
|
||||
},
|
||||
],
|
||||
editable: "user",
|
||||
required: !!field.required,
|
||||
disableOnPrefill: !!field.disableOnPrefill,
|
||||
hidden: !!field.hidden,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
name: field.slug,
|
||||
type: field.type,
|
||||
label: "label" in field ? field.label : "",
|
||||
sources: [
|
||||
{
|
||||
id: "user",
|
||||
type: "user",
|
||||
label: "User",
|
||||
fieldRequired: true,
|
||||
},
|
||||
],
|
||||
editable: "user",
|
||||
required: !!field.required,
|
||||
placeholder: field.placeholder,
|
||||
disableOnPrefill: !!field.disableOnPrefill,
|
||||
hidden: !!field.hidden,
|
||||
};
|
||||
}
|
||||
|
||||
function fieldIsCustomSystemName(field: InputBookingField): field is NameDefaultFieldInput_2024_06_14 {
|
||||
return "type" in field && field.type === "name";
|
||||
}
|
||||
|
||||
function fieldIsCustomSystemNameSplit(
|
||||
field: InputBookingField
|
||||
): field is SplitNameDefaultFieldInput_2024_06_14 {
|
||||
return "type" in field && field.type === "splitName";
|
||||
}
|
||||
|
||||
function fieldIsCustomSystemEmail(field: InputBookingField): field is EmailDefaultFieldInput_2024_06_14 {
|
||||
return "type" in field && field.type === "email";
|
||||
}
|
||||
|
||||
function fieldIsCustomSystemTitle(field: InputBookingField): field is TitleDefaultFieldInput_2024_06_14 {
|
||||
return "slug" in field && field.slug === "title";
|
||||
}
|
||||
|
||||
function fieldIsCustomSystemNotes(field: InputBookingField): field is NotesDefaultFieldInput_2024_06_14 {
|
||||
return "slug" in field && field.slug === "notes";
|
||||
}
|
||||
|
||||
function fieldIsCustomSystemGuests(field: InputBookingField): field is GuestsDefaultFieldInput_2024_06_14 {
|
||||
return "slug" in field && field.slug === "guests";
|
||||
}
|
||||
|
||||
function fieldIsCustomSystemRescheduleReason(
|
||||
field: InputBookingField
|
||||
): field is RescheduleReasonDefaultFieldInput_2024_06_14 {
|
||||
return "slug" in field && field.slug === "rescheduleReason";
|
||||
}
|
||||
|
||||
function fieldIsDefaultAttendeePhone(field: InputBookingField): field is PhoneDefaultFieldOutput_2024_06_14 {
|
||||
const isPhone = "type" in field && field.type === "phone";
|
||||
const isAttendeePhoneNumber = "slug" in field && field.slug === "attendeePhoneNumber";
|
||||
return isPhone && isAttendeePhoneNumber;
|
||||
}
|
||||
|
||||
function fieldIsDefaultSystemLocation(
|
||||
field: InputBookingField
|
||||
): field is LocationDefaultFieldInput_2024_06_14 {
|
||||
return "slug" in field && field.slug === "location";
|
||||
}
|
||||
|
||||
function fieldIsSelect(
|
||||
field: InputBookingField
|
||||
): field is
|
||||
| CheckboxGroupFieldInput_2024_06_14
|
||||
| RadioGroupFieldInput_2024_06_14
|
||||
| MultiSelectFieldInput_2024_06_14 {
|
||||
return (
|
||||
"type" in field && (field.type === "checkbox" || field.type === "radio" || field.type === "multiselect")
|
||||
);
|
||||
}
|
||||
|
||||
export function transformSelectOptionsApiToInternal(options: string[]) {
|
||||
return options.map((option) => ({
|
||||
label: option,
|
||||
value: option,
|
||||
}));
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
import { ConfirmationPolicyEnum } from "@calcom/platform-enums/monorepo";
|
||||
import type {
|
||||
ConfirmationPolicyTransformedSchema,
|
||||
NoticeThresholdTransformedSchema,
|
||||
CreateEventTypeInput_2024_06_14,
|
||||
} from "@calcom/platform-types";
|
||||
|
||||
export function transformConfirmationPolicyApiToInternal(
|
||||
inputConfirmationPolicy: CreateEventTypeInput_2024_06_14["confirmationPolicy"]
|
||||
): ConfirmationPolicyTransformedSchema | undefined {
|
||||
if (!inputConfirmationPolicy) return undefined;
|
||||
if (inputConfirmationPolicy.disabled) {
|
||||
return {
|
||||
requiresConfirmation: false,
|
||||
requiresConfirmationWillBlockSlot: false,
|
||||
requiresConfirmationThreshold: undefined,
|
||||
};
|
||||
}
|
||||
switch (inputConfirmationPolicy.type) {
|
||||
case ConfirmationPolicyEnum.ALWAYS:
|
||||
return {
|
||||
requiresConfirmation: true,
|
||||
requiresConfirmationThreshold: undefined,
|
||||
requiresConfirmationWillBlockSlot: inputConfirmationPolicy.blockUnconfirmedBookingsInBooker,
|
||||
};
|
||||
case ConfirmationPolicyEnum.TIME:
|
||||
return {
|
||||
requiresConfirmation: true,
|
||||
requiresConfirmationThreshold: {
|
||||
unit: inputConfirmationPolicy.noticeThreshold?.unit,
|
||||
time: inputConfirmationPolicy.noticeThreshold?.count,
|
||||
} as NoticeThresholdTransformedSchema,
|
||||
requiresConfirmationWillBlockSlot: inputConfirmationPolicy.blockUnconfirmedBookingsInBooker,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
import type {
|
||||
CreateEventTypeInput_2024_06_14,
|
||||
EventTypeColorsTransformedSchema,
|
||||
} from "@calcom/platform-types";
|
||||
|
||||
export function transformEventColorsApiToInternal(
|
||||
inputEventTypeColors: CreateEventTypeInput_2024_06_14["color"]
|
||||
): EventTypeColorsTransformedSchema | undefined {
|
||||
if (!inputEventTypeColors) return undefined;
|
||||
|
||||
return {
|
||||
darkEventTypeColor: inputEventTypeColors.darkThemeHex,
|
||||
lightEventTypeColor: inputEventTypeColors.lightThemeHex,
|
||||
};
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
import {
|
||||
BookingWindowPeriodInputTypeEnum_2024_06_14,
|
||||
BookingWindowPeriodOutputTypeEnum_2024_06_14,
|
||||
} from "@calcom/platform-enums/monorepo";
|
||||
import {
|
||||
type CreateEventTypeInput_2024_06_14,
|
||||
type BusinessDaysWindow_2024_06_14,
|
||||
type RangeWindow_2024_06_14,
|
||||
type TransformFutureBookingsLimitSchema_2024_06_14,
|
||||
} from "@calcom/platform-types";
|
||||
|
||||
export function transformFutureBookingLimitsApiToInternal(
|
||||
inputBookingLimits: CreateEventTypeInput_2024_06_14["bookingWindow"]
|
||||
): TransformFutureBookingsLimitSchema_2024_06_14 | undefined {
|
||||
if (!inputBookingLimits) {
|
||||
return;
|
||||
}
|
||||
if (inputBookingLimits.disabled) {
|
||||
return {
|
||||
periodType: BookingWindowPeriodOutputTypeEnum_2024_06_14.UNLIMITED,
|
||||
};
|
||||
}
|
||||
switch (inputBookingLimits?.type) {
|
||||
case BookingWindowPeriodInputTypeEnum_2024_06_14.businessDays:
|
||||
return {
|
||||
periodDays: (inputBookingLimits as BusinessDaysWindow_2024_06_14).value,
|
||||
periodType: !!(inputBookingLimits as BusinessDaysWindow_2024_06_14).rolling
|
||||
? BookingWindowPeriodOutputTypeEnum_2024_06_14.ROLLING_WINDOW
|
||||
: BookingWindowPeriodOutputTypeEnum_2024_06_14.ROLLING,
|
||||
periodCountCalendarDays: false,
|
||||
};
|
||||
case BookingWindowPeriodInputTypeEnum_2024_06_14.calendarDays:
|
||||
return {
|
||||
periodDays: (inputBookingLimits as BusinessDaysWindow_2024_06_14).value,
|
||||
periodType: !!(inputBookingLimits as BusinessDaysWindow_2024_06_14).rolling
|
||||
? BookingWindowPeriodOutputTypeEnum_2024_06_14.ROLLING_WINDOW
|
||||
: BookingWindowPeriodOutputTypeEnum_2024_06_14.ROLLING,
|
||||
periodCountCalendarDays: true,
|
||||
};
|
||||
case BookingWindowPeriodInputTypeEnum_2024_06_14.range:
|
||||
return {
|
||||
periodType: BookingWindowPeriodOutputTypeEnum_2024_06_14.RANGE,
|
||||
periodStartDate: new Date((inputBookingLimits as RangeWindow_2024_06_14).value[0]),
|
||||
periodEndDate: new Date((inputBookingLimits as RangeWindow_2024_06_14).value[1]),
|
||||
};
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
export * from "./booking-fields";
|
||||
export * from "./locations";
|
||||
export * from "./recurrence";
|
||||
export * from "./interval-limits";
|
||||
export * from "./future-booking-limits";
|
||||
export * from "./booker-layouts";
|
||||
export * from "./confirmation-policy";
|
||||
export * from "./event-colors";
|
||||
export * from "./seats";
|
||||
@@ -1,23 +0,0 @@
|
||||
import { BookingLimitsEnum_2024_06_14 } from "@calcom/platform-enums/monorepo";
|
||||
import {
|
||||
type CreateEventTypeInput_2024_06_14,
|
||||
type BookingLimitsKeyOutputType_2024_06_14,
|
||||
type TransformBookingLimitsSchema_2024_06_14,
|
||||
} from "@calcom/platform-types";
|
||||
|
||||
export function transformIntervalLimitsApiToInternal(
|
||||
inputBookingLimits: CreateEventTypeInput_2024_06_14["bookingLimitsCount"]
|
||||
) {
|
||||
const res: TransformBookingLimitsSchema_2024_06_14 = {};
|
||||
if (inputBookingLimits?.disabled) {
|
||||
return res;
|
||||
}
|
||||
inputBookingLimits &&
|
||||
Object.entries(inputBookingLimits).map(([key, value]) => {
|
||||
const outputKey: BookingLimitsKeyOutputType_2024_06_14 = BookingLimitsEnum_2024_06_14[
|
||||
key as keyof typeof BookingLimitsEnum_2024_06_14
|
||||
] satisfies BookingLimitsKeyOutputType_2024_06_14;
|
||||
res[outputKey] = value;
|
||||
});
|
||||
return res;
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
import type { InputLocation_2024_06_14, InputTeamLocation_2024_06_14 } from "@calcom/platform-types";
|
||||
|
||||
import type {
|
||||
AttendeeAddressLocation,
|
||||
AttendeeDefinedLocation,
|
||||
AttendeePhoneLocation,
|
||||
OrganizerAddressLocation,
|
||||
OrganizerIntegrationLocation,
|
||||
OrganizerLinkLocation,
|
||||
OrganizerPhoneLocation,
|
||||
OrganizerConferencingSchema,
|
||||
} from "../internal/locations";
|
||||
|
||||
export const apiToInternalintegrationsMapping = {
|
||||
"cal-video": "integrations:daily",
|
||||
"google-meet": "integrations:google:meet",
|
||||
"office365-video": "integrations:office365_video",
|
||||
zoom: "integrations:zoom",
|
||||
"whereby-video": "integrations:whereby_video",
|
||||
"whatsapp-video": "integrations:whatsapp_video",
|
||||
"webex-video": "integrations:webex_video",
|
||||
"telegram-video": "integrations:telegram_video",
|
||||
tandem: "integrations:tandem",
|
||||
"sylaps-video": "integrations:sylaps_video",
|
||||
"skype-video": "integrations:skype_video",
|
||||
"sirius-video": "integrations:sirius_video_video",
|
||||
"signal-video": "integrations:signal_video",
|
||||
"shimmer-video": "integrations:shimmer_video",
|
||||
"salesroom-video": "integrations:salesroom_video",
|
||||
"roam-video": "integrations:roam_video",
|
||||
"riverside-video": "integrations:riverside_video",
|
||||
"ping-video": "integrations:ping_video",
|
||||
"mirotalk-video": "integrations:mirotalk_video",
|
||||
jitsi: "integrations:jitsi",
|
||||
"jelly-video": "integrations:jelly_video",
|
||||
"jelly-conferencing": "integrations:jelly_conferencing",
|
||||
huddle: "integrations:huddle01",
|
||||
"facetime-video": "integrations:facetime_video",
|
||||
"element-call-video": "integrations:element-call_video",
|
||||
"eightxeight-video": "integrations:eightxeight_video",
|
||||
"discord-video": "integrations:discord_video",
|
||||
"demodesk-video": "integrations:demodesk_video",
|
||||
"campfire-video": "integrations:campfire_video",
|
||||
} as const;
|
||||
|
||||
function transformLocation<T extends InputLocation_2024_06_14>(location: T) {
|
||||
const { type } = location;
|
||||
switch (type) {
|
||||
case "address":
|
||||
return {
|
||||
type: "inPerson",
|
||||
address: location.address,
|
||||
displayLocationPublicly: location.public,
|
||||
} satisfies OrganizerAddressLocation;
|
||||
case "attendeeAddress":
|
||||
return { type: "attendeeInPerson" } satisfies AttendeeAddressLocation;
|
||||
case "link":
|
||||
return {
|
||||
type: "link",
|
||||
link: location.link,
|
||||
displayLocationPublicly: location.public,
|
||||
} satisfies OrganizerLinkLocation;
|
||||
case "integration":
|
||||
const integrationLabel = apiToInternalintegrationsMapping[location.integration];
|
||||
return { type: integrationLabel } satisfies OrganizerIntegrationLocation;
|
||||
case "phone":
|
||||
return {
|
||||
type: "userPhone",
|
||||
hostPhoneNumber: location.phone,
|
||||
displayLocationPublicly: location.public,
|
||||
} satisfies OrganizerPhoneLocation;
|
||||
case "attendeePhone":
|
||||
return { type: "phone" } satisfies AttendeePhoneLocation;
|
||||
case "attendeeDefined":
|
||||
return { type: "somewhereElse" } satisfies AttendeeDefinedLocation;
|
||||
default:
|
||||
throw new Error(`Unsupported input location type '${type}'`);
|
||||
}
|
||||
}
|
||||
|
||||
export function transformLocationsApiToInternal(inputLocations: InputLocation_2024_06_14[] | undefined) {
|
||||
return inputLocations ? inputLocations.map(transformLocation) : [];
|
||||
}
|
||||
|
||||
export function transformTeamLocationsApiToInternal(
|
||||
inputLocations: InputTeamLocation_2024_06_14[] | undefined
|
||||
) {
|
||||
if (!inputLocations) return [];
|
||||
|
||||
return inputLocations.map((location) => {
|
||||
if (location.type === "organizersDefaultApp") {
|
||||
return { type: "conferencing" } satisfies OrganizerConferencingSchema;
|
||||
}
|
||||
return transformLocation(location);
|
||||
});
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
import { Frequency } from "@calcom/platform-enums/monorepo";
|
||||
import type { Recurrence_2024_06_14 } from "@calcom/platform-types";
|
||||
import { type TransformRecurringEventSchema_2024_06_14 } from "@calcom/platform-types";
|
||||
|
||||
export function transformRecurrenceApiToInternal(
|
||||
recurrence: Recurrence_2024_06_14
|
||||
): TransformRecurringEventSchema_2024_06_14 {
|
||||
return {
|
||||
interval: recurrence.interval,
|
||||
count: recurrence.occurrences,
|
||||
freq: Frequency[recurrence.frequency as keyof typeof Frequency],
|
||||
} satisfies TransformRecurringEventSchema_2024_06_14;
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
import type {
|
||||
CreateEventTypeInput_2024_06_14,
|
||||
SeatOptionsTransformedSchema,
|
||||
SeatOptionsDisabledSchema,
|
||||
} from "@calcom/platform-types";
|
||||
|
||||
export function transformSeatsApiToInternal(
|
||||
inputSeats: CreateEventTypeInput_2024_06_14["seats"]
|
||||
): SeatOptionsTransformedSchema | SeatOptionsDisabledSchema {
|
||||
if (!inputSeats || inputSeats.disabled)
|
||||
return {
|
||||
seatsPerTimeSlot: null,
|
||||
};
|
||||
|
||||
return {
|
||||
seatsPerTimeSlot: inputSeats.seatsPerTimeSlot,
|
||||
seatsShowAttendees: inputSeats.showAttendeeInfo,
|
||||
seatsShowAvailabilityCount: inputSeats.showAvailabilityCount,
|
||||
};
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
export * from "./api-to-internal";
|
||||
export * from "./internal-to-api";
|
||||
export * from "./internal/locations";
|
||||
@@ -1,20 +0,0 @@
|
||||
import {
|
||||
BookerLayoutsInputEnum_2024_06_14,
|
||||
BookerLayoutsOutputEnum_2024_06_14,
|
||||
} from "@calcom/platform-enums/monorepo";
|
||||
import type { BookerLayoutsTransformedSchema } from "@calcom/platform-types";
|
||||
|
||||
export function transformBookerLayoutsInternalToApi(
|
||||
transformedBookerLayouts: BookerLayoutsTransformedSchema
|
||||
) {
|
||||
const outputToInputMap = {
|
||||
[BookerLayoutsOutputEnum_2024_06_14.month_view]: BookerLayoutsInputEnum_2024_06_14.month,
|
||||
[BookerLayoutsOutputEnum_2024_06_14.week_view]: BookerLayoutsInputEnum_2024_06_14.week,
|
||||
[BookerLayoutsOutputEnum_2024_06_14.column_view]: BookerLayoutsInputEnum_2024_06_14.column,
|
||||
};
|
||||
|
||||
return {
|
||||
defaultLayout: outputToInputMap[transformedBookerLayouts.defaultLayout],
|
||||
enabledLayouts: transformedBookerLayouts.enabledLayouts.map((layout) => outputToInputMap[layout]),
|
||||
};
|
||||
}
|
||||
@@ -1,688 +0,0 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import type {
|
||||
OutputBookingField_2024_06_14,
|
||||
SplitNameDefaultFieldOutput_2024_06_14,
|
||||
NameDefaultFieldOutput_2024_06_14,
|
||||
EmailDefaultFieldOutput_2024_06_14,
|
||||
PhoneDefaultFieldOutput_2024_06_14,
|
||||
LocationDefaultFieldOutput_2024_06_14,
|
||||
RescheduleReasonDefaultFieldOutput_2024_06_14,
|
||||
TitleDefaultFieldOutput_2024_06_14,
|
||||
NotesDefaultFieldOutput_2024_06_14,
|
||||
GuestsDefaultFieldOutput_2024_06_14,
|
||||
OutputUnknownBookingField_2024_06_14,
|
||||
AddressFieldOutput_2024_06_14,
|
||||
BooleanFieldOutput_2024_06_14,
|
||||
CheckboxGroupFieldOutput_2024_06_14,
|
||||
MultiEmailFieldOutput_2024_06_14,
|
||||
MultiSelectFieldOutput_2024_06_14,
|
||||
NumberFieldOutput_2024_06_14,
|
||||
PhoneFieldOutput_2024_06_14,
|
||||
RadioGroupFieldOutput_2024_06_14,
|
||||
SelectFieldOutput_2024_06_14,
|
||||
TextAreaFieldOutput_2024_06_14,
|
||||
TextFieldOutput_2024_06_14,
|
||||
UrlFieldOutput_2024_06_14,
|
||||
} from "@calcom/platform-types";
|
||||
|
||||
export function transformBookingFieldsInternalToApi(
|
||||
databaseBookingFields: (SystemField | CustomField)[]
|
||||
): OutputBookingField_2024_06_14[] {
|
||||
return databaseBookingFields.map((field) => {
|
||||
if (field.editable === "system" || field.editable === "system-but-optional") {
|
||||
switch (field.name) {
|
||||
case "name": {
|
||||
if (field.variant === "firstAndLastName") {
|
||||
const firstNameField = field.variantsConfig?.variants?.firstAndLastName?.fields?.find(
|
||||
(f) => f.name === "firstName"
|
||||
);
|
||||
const lastNameField = field.variantsConfig?.variants?.firstAndLastName?.fields?.find(
|
||||
(f) => f.name === "lastName"
|
||||
);
|
||||
|
||||
return {
|
||||
isDefault: true,
|
||||
type: "splitName",
|
||||
slug: "splitName",
|
||||
firstNameLabel: firstNameField?.label,
|
||||
firstNamePlaceholder: firstNameField?.placeholder,
|
||||
lastNameLabel: lastNameField?.label,
|
||||
lastNamePlaceholder: lastNameField?.placeholder,
|
||||
lastNameRequired: !!lastNameField?.required,
|
||||
disableOnPrefill: !!field.disableOnPrefill,
|
||||
} satisfies SplitNameDefaultFieldOutput_2024_06_14;
|
||||
}
|
||||
|
||||
return {
|
||||
isDefault: true,
|
||||
type: field.type,
|
||||
slug: field.name,
|
||||
required: !!field.required,
|
||||
label: field.variantsConfig?.variants?.fullName?.fields[0]?.label,
|
||||
placeholder: field.variantsConfig?.variants?.fullName?.fields[0]?.placeholder,
|
||||
disableOnPrefill: !!field.disableOnPrefill,
|
||||
} satisfies NameDefaultFieldOutput_2024_06_14;
|
||||
}
|
||||
case "email":
|
||||
return {
|
||||
isDefault: true,
|
||||
type: field.type,
|
||||
slug: field.name,
|
||||
required: !!field.required,
|
||||
label: field.label,
|
||||
placeholder: field.placeholder,
|
||||
disableOnPrefill: !!field.disableOnPrefill,
|
||||
hidden: !!field.hidden,
|
||||
} satisfies EmailDefaultFieldOutput_2024_06_14;
|
||||
case "location":
|
||||
return {
|
||||
isDefault: true,
|
||||
type: "radioInput",
|
||||
slug: "location",
|
||||
required: !!field.required,
|
||||
hidden: !!field.hidden,
|
||||
label: field.label,
|
||||
} satisfies LocationDefaultFieldOutput_2024_06_14;
|
||||
case "rescheduleReason":
|
||||
return {
|
||||
isDefault: true,
|
||||
type: "textarea",
|
||||
slug: "rescheduleReason",
|
||||
required: !!field.required,
|
||||
label: field.label,
|
||||
placeholder: field.placeholder,
|
||||
disableOnPrefill: !!field.disableOnPrefill,
|
||||
hidden: !!field.hidden,
|
||||
} satisfies RescheduleReasonDefaultFieldOutput_2024_06_14;
|
||||
case "title":
|
||||
return {
|
||||
isDefault: true,
|
||||
type: "text",
|
||||
slug: "title",
|
||||
required: !!field.required,
|
||||
label: field.label,
|
||||
placeholder: field.placeholder,
|
||||
disableOnPrefill: !!field.disableOnPrefill,
|
||||
hidden: !!field.hidden,
|
||||
} satisfies TitleDefaultFieldOutput_2024_06_14;
|
||||
case "notes":
|
||||
return {
|
||||
isDefault: true,
|
||||
type: "textarea",
|
||||
slug: "notes",
|
||||
required: !!field.required,
|
||||
label: field.label,
|
||||
placeholder: field.placeholder,
|
||||
disableOnPrefill: !!field.disableOnPrefill,
|
||||
hidden: !!field.hidden,
|
||||
} satisfies NotesDefaultFieldOutput_2024_06_14;
|
||||
case "guests":
|
||||
return {
|
||||
isDefault: true,
|
||||
type: "multiemail",
|
||||
slug: "guests",
|
||||
required: !!field.required,
|
||||
label: field.label,
|
||||
placeholder: field.placeholder,
|
||||
disableOnPrefill: !!field.disableOnPrefill,
|
||||
hidden: !!field.hidden,
|
||||
} satisfies GuestsDefaultFieldOutput_2024_06_14;
|
||||
case "attendeePhoneNumber":
|
||||
return {
|
||||
isDefault: true,
|
||||
type: field.type,
|
||||
slug: field.name,
|
||||
required: !!field.required,
|
||||
label: field.label,
|
||||
placeholder: field.placeholder,
|
||||
disableOnPrefill: !!field.disableOnPrefill,
|
||||
hidden: !!field.hidden,
|
||||
} satisfies PhoneDefaultFieldOutput_2024_06_14;
|
||||
default:
|
||||
return {
|
||||
type: "unknown",
|
||||
slug: "unknown",
|
||||
bookingField: JSON.stringify(field),
|
||||
} satisfies OutputUnknownBookingField_2024_06_14;
|
||||
}
|
||||
} else {
|
||||
switch (field.type) {
|
||||
case "phone":
|
||||
return {
|
||||
isDefault: false,
|
||||
type: field.type,
|
||||
slug: field.name,
|
||||
label: field.label || "",
|
||||
required: !!field.required,
|
||||
placeholder: field.placeholder,
|
||||
disableOnPrefill: !!field.disableOnPrefill,
|
||||
hidden: !!field.hidden,
|
||||
} satisfies PhoneFieldOutput_2024_06_14;
|
||||
case "address":
|
||||
return {
|
||||
isDefault: false,
|
||||
type: field.type,
|
||||
slug: field.name,
|
||||
label: field.label,
|
||||
required: !!field.required,
|
||||
placeholder: field.placeholder,
|
||||
disableOnPrefill: !!field.disableOnPrefill,
|
||||
hidden: !!field.hidden,
|
||||
} satisfies AddressFieldOutput_2024_06_14;
|
||||
case "text":
|
||||
return {
|
||||
isDefault: false,
|
||||
type: field.type,
|
||||
slug: field.name,
|
||||
label: field.label || "",
|
||||
required: !!field.required,
|
||||
placeholder: field.placeholder,
|
||||
disableOnPrefill: !!field.disableOnPrefill,
|
||||
hidden: !!field.hidden,
|
||||
} satisfies TextFieldOutput_2024_06_14;
|
||||
case "number":
|
||||
return {
|
||||
isDefault: false,
|
||||
type: field.type,
|
||||
slug: field.name,
|
||||
label: field.label,
|
||||
required: !!field.required,
|
||||
placeholder: field.placeholder,
|
||||
disableOnPrefill: !!field.disableOnPrefill,
|
||||
hidden: !!field.hidden,
|
||||
} satisfies NumberFieldOutput_2024_06_14;
|
||||
case "textarea":
|
||||
return {
|
||||
isDefault: false,
|
||||
type: field.type,
|
||||
slug: field.name,
|
||||
label: field.label || "",
|
||||
required: !!field.required,
|
||||
placeholder: field.placeholder,
|
||||
disableOnPrefill: !!field.disableOnPrefill,
|
||||
hidden: !!field.hidden,
|
||||
} satisfies TextAreaFieldOutput_2024_06_14;
|
||||
case "multiemail":
|
||||
return {
|
||||
isDefault: false,
|
||||
type: field.type,
|
||||
slug: field.name,
|
||||
label: field.label || "",
|
||||
required: !!field.required,
|
||||
placeholder: field.placeholder,
|
||||
disableOnPrefill: !!field.disableOnPrefill,
|
||||
hidden: !!field.hidden,
|
||||
} satisfies MultiEmailFieldOutput_2024_06_14;
|
||||
case "boolean":
|
||||
return {
|
||||
isDefault: false,
|
||||
type: field.type,
|
||||
slug: field.name,
|
||||
label: field.label,
|
||||
required: !!field.required,
|
||||
disableOnPrefill: !!field.disableOnPrefill,
|
||||
hidden: !!field.hidden,
|
||||
} satisfies BooleanFieldOutput_2024_06_14;
|
||||
case "select":
|
||||
return {
|
||||
isDefault: false,
|
||||
type: field.type,
|
||||
slug: field.name,
|
||||
label: field.label,
|
||||
required: !!field.required,
|
||||
placeholder: field.placeholder,
|
||||
disableOnPrefill: !!field.disableOnPrefill,
|
||||
options: field.options ? field.options.map((option) => option.value) : [],
|
||||
hidden: !!field.hidden,
|
||||
} satisfies SelectFieldOutput_2024_06_14;
|
||||
case "multiselect":
|
||||
return {
|
||||
isDefault: false,
|
||||
type: field.type,
|
||||
slug: field.name,
|
||||
label: field.label,
|
||||
required: !!field.required,
|
||||
disableOnPrefill: !!field.disableOnPrefill,
|
||||
options: field.options ? field.options.map((option) => option.value) : [],
|
||||
hidden: !!field.hidden,
|
||||
} satisfies MultiSelectFieldOutput_2024_06_14;
|
||||
case "checkbox":
|
||||
return {
|
||||
isDefault: false,
|
||||
type: field.type,
|
||||
slug: field.name,
|
||||
label: field.label,
|
||||
required: !!field.required,
|
||||
disableOnPrefill: !!field.disableOnPrefill,
|
||||
options: field.options ? field.options.map((option) => option.value) : [],
|
||||
hidden: !!field.hidden,
|
||||
} satisfies CheckboxGroupFieldOutput_2024_06_14;
|
||||
case "radio":
|
||||
return {
|
||||
isDefault: false,
|
||||
type: field.type,
|
||||
slug: field.name,
|
||||
label: field.label,
|
||||
required: !!field.required,
|
||||
options: field.options ? field.options.map((option) => option.value) : [],
|
||||
disableOnPrefill: !!field.disableOnPrefill,
|
||||
hidden: !!field.hidden,
|
||||
} satisfies RadioGroupFieldOutput_2024_06_14;
|
||||
case "url":
|
||||
return {
|
||||
isDefault: false,
|
||||
type: field.type,
|
||||
slug: field.name,
|
||||
label: field.label || "",
|
||||
required: !!field.required,
|
||||
placeholder: field.placeholder,
|
||||
disableOnPrefill: !!field.disableOnPrefill,
|
||||
hidden: !!field.hidden,
|
||||
} satisfies UrlFieldOutput_2024_06_14;
|
||||
default:
|
||||
return {
|
||||
type: "unknown",
|
||||
slug: "unknown",
|
||||
bookingField: JSON.stringify(field),
|
||||
} satisfies OutputUnknownBookingField_2024_06_14;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const CustomFieldTypeEnum = z.enum([
|
||||
"number",
|
||||
"boolean",
|
||||
"address",
|
||||
"text",
|
||||
"textarea",
|
||||
"phone",
|
||||
"multiemail",
|
||||
"select",
|
||||
"multiselect",
|
||||
"checkbox",
|
||||
"radio",
|
||||
"radioInput",
|
||||
"url",
|
||||
]);
|
||||
|
||||
const CustomFieldsSchema = z.object({
|
||||
name: z.string(),
|
||||
type: CustomFieldTypeEnum,
|
||||
label: z.string(),
|
||||
labelAsSafeHtml: z.string().optional(),
|
||||
hidden: z.boolean().optional(),
|
||||
sources: z.array(
|
||||
z.object({
|
||||
id: z.literal("user"),
|
||||
type: z.literal("user"),
|
||||
label: z.literal("User"),
|
||||
fieldRequired: z.literal(true),
|
||||
})
|
||||
),
|
||||
editable: z.enum(["user", "user-readonly"]),
|
||||
required: z.boolean(),
|
||||
placeholder: z.string().optional(),
|
||||
options: z
|
||||
.array(
|
||||
z.object({
|
||||
label: z.string(),
|
||||
value: z.string(),
|
||||
})
|
||||
)
|
||||
.optional(),
|
||||
disableOnPrefill: z.boolean().optional(),
|
||||
});
|
||||
|
||||
const SystemFieldSchema = z.object({
|
||||
defaultLabel: z.string(),
|
||||
label: z.string().optional(),
|
||||
editable: z.enum(["system-but-optional", "system", "user-readonly"]),
|
||||
sources: z.array(
|
||||
z.object({
|
||||
id: z.literal("default"),
|
||||
type: z.literal("default"),
|
||||
label: z.literal("Default"),
|
||||
})
|
||||
),
|
||||
views: z
|
||||
.array(
|
||||
z.object({
|
||||
id: z.enum(["reschedule"]),
|
||||
label: z.string(),
|
||||
})
|
||||
)
|
||||
.optional(),
|
||||
defaultPlaceholder: z.enum(["", "share_additional_notes", "email", "reschedule_placeholder"]).optional(),
|
||||
placeholder: z.string().optional(),
|
||||
hidden: z.boolean().optional(),
|
||||
required: z.boolean(),
|
||||
hideWhenJustOneOption: z.boolean().optional(),
|
||||
getOptionsAt: z.enum(["locations"]).optional(),
|
||||
optionsInputs: z
|
||||
.object({
|
||||
attendeeInPerson: z.object({
|
||||
type: z.literal("address"),
|
||||
required: z.boolean(),
|
||||
placeholder: z.string(),
|
||||
}),
|
||||
phone: z.object({
|
||||
type: z.literal("phone"),
|
||||
required: z.boolean(),
|
||||
placeholder: z.string(),
|
||||
}),
|
||||
somewhereElse: z
|
||||
.object({
|
||||
type: z.literal("text"),
|
||||
required: z.boolean(),
|
||||
placeholder: z.string(),
|
||||
})
|
||||
.optional(),
|
||||
})
|
||||
.optional(),
|
||||
disableOnPrefill: z.boolean().optional(),
|
||||
});
|
||||
|
||||
const NameSystemFieldSchema = SystemFieldSchema.extend({
|
||||
name: z.literal("name"),
|
||||
type: z.literal("name"),
|
||||
required: z.boolean(),
|
||||
variant: z.enum(["fullName", "firstAndLastName"]).optional(),
|
||||
variantsConfig: z
|
||||
.object({
|
||||
variants: z.object({
|
||||
fullName: z.object({
|
||||
fields: z.array(
|
||||
z.object({
|
||||
name: z.literal("fullName"),
|
||||
type: z.literal("text"),
|
||||
label: z.string().optional(),
|
||||
required: z.boolean(),
|
||||
placeholder: z.string().optional(),
|
||||
})
|
||||
),
|
||||
}),
|
||||
firstAndLastName: z
|
||||
.object({
|
||||
fields: z.array(
|
||||
z.object({
|
||||
name: z.enum(["firstName", "lastName"]),
|
||||
type: z.literal("text"),
|
||||
label: z.string().optional(),
|
||||
required: z.boolean(),
|
||||
placeholder: z.string().optional(),
|
||||
})
|
||||
),
|
||||
})
|
||||
.optional(),
|
||||
}),
|
||||
})
|
||||
.optional(),
|
||||
});
|
||||
|
||||
const PhoneSystemFieldSchema = SystemFieldSchema.extend({
|
||||
name: z.literal("attendeePhoneNumber"),
|
||||
type: z.literal("phone"),
|
||||
required: z.boolean(),
|
||||
});
|
||||
|
||||
const EmailSystemFieldSchema = SystemFieldSchema.extend({
|
||||
name: z.literal("email"),
|
||||
type: z.literal("email"),
|
||||
required: z.boolean(),
|
||||
});
|
||||
|
||||
const RescheduleReasonSystemFieldSchema = SystemFieldSchema.extend({
|
||||
name: z.literal("rescheduleReason"),
|
||||
type: z.literal("textarea"),
|
||||
required: z.boolean(),
|
||||
});
|
||||
|
||||
const LocationReasonSystemFieldSchema = SystemFieldSchema.extend({
|
||||
name: z.literal("location"),
|
||||
type: z.literal("radioInput"),
|
||||
required: z.boolean(),
|
||||
});
|
||||
|
||||
const TitleSystemFieldSchema = SystemFieldSchema.extend({
|
||||
name: z.literal("title"),
|
||||
type: z.literal("text"),
|
||||
required: z.boolean(),
|
||||
});
|
||||
|
||||
const NotesSystemFieldSchema = SystemFieldSchema.extend({
|
||||
name: z.literal("notes"),
|
||||
type: z.literal("textarea"),
|
||||
required: z.boolean(),
|
||||
});
|
||||
|
||||
const GuestsSystemFieldSchema = SystemFieldSchema.extend({
|
||||
name: z.literal("guests"),
|
||||
type: z.literal("multiemail"),
|
||||
required: z.boolean(),
|
||||
});
|
||||
|
||||
export type NameSystemField = z.infer<typeof NameSystemFieldSchema>;
|
||||
export type EmailSystemField = z.infer<typeof EmailSystemFieldSchema>;
|
||||
type RescheduleReasonSystemField = z.infer<typeof RescheduleReasonSystemFieldSchema>;
|
||||
type LocationReasonSystemField = z.infer<typeof LocationReasonSystemFieldSchema>;
|
||||
type TitleSystemField = z.infer<typeof TitleSystemFieldSchema>;
|
||||
type NotesSystemField = z.infer<typeof NotesSystemFieldSchema>;
|
||||
type GuestsSystemField = z.infer<typeof GuestsSystemFieldSchema>;
|
||||
type PhoneSystemField = z.infer<typeof PhoneSystemFieldSchema>;
|
||||
|
||||
export type SystemField =
|
||||
| NameSystemField
|
||||
| EmailSystemField
|
||||
| PhoneSystemField
|
||||
| RescheduleReasonSystemField
|
||||
| LocationReasonSystemField
|
||||
| TitleSystemField
|
||||
| NotesSystemField
|
||||
| GuestsSystemField;
|
||||
|
||||
export type CustomField = z.infer<typeof CustomFieldsSchema>;
|
||||
|
||||
const SystemFieldsSchema = z.union([
|
||||
NameSystemFieldSchema,
|
||||
EmailSystemFieldSchema,
|
||||
PhoneSystemFieldSchema,
|
||||
LocationReasonSystemFieldSchema,
|
||||
RescheduleReasonSystemFieldSchema,
|
||||
TitleSystemFieldSchema,
|
||||
NotesSystemFieldSchema,
|
||||
GuestsSystemFieldSchema,
|
||||
]);
|
||||
|
||||
export const BookingFieldSchema = z.union([CustomFieldsSchema, SystemFieldsSchema]);
|
||||
export const BookingFieldsSchema = z.array(BookingFieldSchema);
|
||||
|
||||
export const systemBeforeFieldName: NameSystemField = {
|
||||
type: "name",
|
||||
name: "name",
|
||||
editable: "system",
|
||||
defaultLabel: "your_name",
|
||||
required: true,
|
||||
variant: "fullName",
|
||||
sources: [
|
||||
{
|
||||
label: "Default",
|
||||
id: "default",
|
||||
type: "default",
|
||||
},
|
||||
],
|
||||
variantsConfig: {
|
||||
variants: {
|
||||
fullName: {
|
||||
fields: [
|
||||
{
|
||||
name: "fullName",
|
||||
type: "text",
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
firstAndLastName: {
|
||||
fields: [
|
||||
{
|
||||
name: "firstName",
|
||||
type: "text",
|
||||
required: true,
|
||||
label: "",
|
||||
placeholder: "",
|
||||
},
|
||||
{
|
||||
name: "lastName",
|
||||
type: "text",
|
||||
required: false,
|
||||
label: "",
|
||||
placeholder: "",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const systemBeforeFieldNameSplit: NameSystemField = {
|
||||
...systemBeforeFieldName,
|
||||
variant: "firstAndLastName",
|
||||
};
|
||||
|
||||
export const systemBeforeFieldEmail: EmailSystemField = {
|
||||
defaultLabel: "email_address",
|
||||
type: "email",
|
||||
name: "email",
|
||||
required: true,
|
||||
editable: "system",
|
||||
sources: [
|
||||
{
|
||||
label: "Default",
|
||||
id: "default",
|
||||
type: "default",
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
export const systemBeforeFieldPhone: PhoneSystemField = {
|
||||
defaultLabel: "phone_number",
|
||||
type: "phone",
|
||||
name: "attendeePhoneNumber",
|
||||
required: false,
|
||||
hidden: true,
|
||||
editable: "system-but-optional",
|
||||
sources: [
|
||||
{
|
||||
label: "Default",
|
||||
id: "default",
|
||||
type: "default",
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
export const systemBeforeFieldLocation: LocationReasonSystemField = {
|
||||
defaultLabel: "location",
|
||||
type: "radioInput",
|
||||
name: "location",
|
||||
editable: "system",
|
||||
hideWhenJustOneOption: true,
|
||||
required: false,
|
||||
getOptionsAt: "locations",
|
||||
optionsInputs: {
|
||||
attendeeInPerson: {
|
||||
type: "address",
|
||||
required: true,
|
||||
placeholder: "",
|
||||
},
|
||||
phone: {
|
||||
type: "phone",
|
||||
required: true,
|
||||
placeholder: "",
|
||||
},
|
||||
somewhereElse: {
|
||||
type: "text",
|
||||
required: true,
|
||||
placeholder: "",
|
||||
},
|
||||
},
|
||||
sources: [
|
||||
{
|
||||
label: "Default",
|
||||
id: "default",
|
||||
type: "default",
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
export const systemAfterFieldTitle: TitleSystemField = {
|
||||
defaultLabel: "what_is_this_meeting_about",
|
||||
type: "text",
|
||||
name: "title",
|
||||
editable: "system-but-optional",
|
||||
required: true,
|
||||
hidden: true,
|
||||
defaultPlaceholder: "",
|
||||
sources: [
|
||||
{
|
||||
label: "Default",
|
||||
id: "default",
|
||||
type: "default",
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
export const systemAfterFieldNotes: NotesSystemField = {
|
||||
defaultLabel: "additional_notes",
|
||||
type: "textarea",
|
||||
name: "notes",
|
||||
editable: "system-but-optional",
|
||||
required: false,
|
||||
defaultPlaceholder: "share_additional_notes",
|
||||
sources: [
|
||||
{
|
||||
label: "Default",
|
||||
id: "default",
|
||||
type: "default",
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
export const systemAfterFieldGuests: GuestsSystemField = {
|
||||
defaultLabel: "additional_guests",
|
||||
type: "multiemail",
|
||||
editable: "system-but-optional",
|
||||
name: "guests",
|
||||
defaultPlaceholder: "email",
|
||||
required: false,
|
||||
hidden: false,
|
||||
sources: [
|
||||
{
|
||||
label: "Default",
|
||||
id: "default",
|
||||
type: "default",
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
export const systemAfterFieldRescheduleReason: RescheduleReasonSystemField = {
|
||||
defaultLabel: "reason_for_reschedule",
|
||||
type: "textarea",
|
||||
editable: "system-but-optional",
|
||||
name: "rescheduleReason",
|
||||
defaultPlaceholder: "reschedule_placeholder",
|
||||
required: false,
|
||||
views: [
|
||||
{
|
||||
id: "reschedule",
|
||||
label: "Reschedule View",
|
||||
},
|
||||
],
|
||||
sources: [
|
||||
{
|
||||
label: "Default",
|
||||
id: "default",
|
||||
type: "default",
|
||||
},
|
||||
],
|
||||
};
|
||||
@@ -1,10 +0,0 @@
|
||||
import type { EventTypeColorsTransformedSchema, EventTypeColor_2024_06_14 } from "@calcom/platform-types";
|
||||
|
||||
export function transformEventTypeColorsInternalToApi(
|
||||
transformedColors: EventTypeColorsTransformedSchema
|
||||
): EventTypeColor_2024_06_14 {
|
||||
return {
|
||||
darkThemeHex: transformedColors.darkEventTypeColor,
|
||||
lightThemeHex: transformedColors.lightEventTypeColor,
|
||||
};
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
import {
|
||||
BookingWindowPeriodInputTypeEnum_2024_06_14,
|
||||
BookingWindowPeriodOutputTypeEnum_2024_06_14,
|
||||
} from "@calcom/platform-enums/monorepo";
|
||||
import type {
|
||||
TransformFutureBookingsLimitSchema_2024_06_14,
|
||||
BookingWindow_2024_06_14,
|
||||
RangeWindow_2024_06_14,
|
||||
CalendarDaysWindow_2024_06_14,
|
||||
BusinessDaysWindow_2024_06_14,
|
||||
Disabled_2024_06_14,
|
||||
} from "@calcom/platform-types";
|
||||
|
||||
export function transformFutureBookingLimitsInternalToApi(
|
||||
transformedFutureBookingsLimitsFields: TransformFutureBookingsLimitSchema_2024_06_14
|
||||
): BookingWindow_2024_06_14 | undefined {
|
||||
switch (transformedFutureBookingsLimitsFields?.periodType) {
|
||||
case BookingWindowPeriodOutputTypeEnum_2024_06_14.RANGE:
|
||||
return {
|
||||
type: BookingWindowPeriodInputTypeEnum_2024_06_14.range,
|
||||
value: [
|
||||
transformedFutureBookingsLimitsFields?.periodStartDate?.toISOString().split("T")[0],
|
||||
transformedFutureBookingsLimitsFields?.periodEndDate?.toISOString().split("T")[0],
|
||||
],
|
||||
} as RangeWindow_2024_06_14;
|
||||
case BookingWindowPeriodOutputTypeEnum_2024_06_14.ROLLING_WINDOW:
|
||||
return {
|
||||
type: transformedFutureBookingsLimitsFields.periodCountCalendarDays
|
||||
? BookingWindowPeriodInputTypeEnum_2024_06_14.calendarDays
|
||||
: BookingWindowPeriodInputTypeEnum_2024_06_14.businessDays,
|
||||
value: transformedFutureBookingsLimitsFields.periodDays,
|
||||
rolling: true,
|
||||
} as CalendarDaysWindow_2024_06_14 | BusinessDaysWindow_2024_06_14;
|
||||
case BookingWindowPeriodOutputTypeEnum_2024_06_14.ROLLING:
|
||||
return {
|
||||
type: transformedFutureBookingsLimitsFields.periodCountCalendarDays
|
||||
? BookingWindowPeriodInputTypeEnum_2024_06_14.calendarDays
|
||||
: BookingWindowPeriodInputTypeEnum_2024_06_14.businessDays,
|
||||
value: transformedFutureBookingsLimitsFields.periodDays,
|
||||
rolling: false,
|
||||
} as CalendarDaysWindow_2024_06_14 | BusinessDaysWindow_2024_06_14;
|
||||
|
||||
case BookingWindowPeriodOutputTypeEnum_2024_06_14.UNLIMITED:
|
||||
return {
|
||||
disabled: true,
|
||||
} as Disabled_2024_06_14;
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
export * from "./booking-fields";
|
||||
export * from "./locations";
|
||||
export * from "./recurrence";
|
||||
export * from "./interval-limits";
|
||||
export * from "./future-booking-limits";
|
||||
export * from "./booker-layouts";
|
||||
export * from "./event-type-colors";
|
||||
export * from "./requires-confirmation";
|
||||
export * from "./seats";
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,27 +0,0 @@
|
||||
import { BookingLimitsEnum_2024_06_14 } from "@calcom/platform-enums/monorepo";
|
||||
import type {
|
||||
BookingLimitsKeysInputType,
|
||||
TransformBookingLimitsSchema_2024_06_14,
|
||||
} from "@calcom/platform-types";
|
||||
|
||||
export function transformIntervalLimitsInternalToApi(
|
||||
transformedBookingFields: TransformBookingLimitsSchema_2024_06_14 | null
|
||||
) {
|
||||
if (!transformedBookingFields) {
|
||||
return undefined;
|
||||
}
|
||||
const res: { [K in BookingLimitsKeysInputType]?: number } = {};
|
||||
transformedBookingFields &&
|
||||
Object.entries(transformedBookingFields).map(([key, value]) => {
|
||||
const outputKey: BookingLimitsKeysInputType | undefined = Object.keys(
|
||||
BookingLimitsEnum_2024_06_14
|
||||
).find(
|
||||
(item) => BookingLimitsEnum_2024_06_14[item as keyof typeof BookingLimitsEnum_2024_06_14] === key
|
||||
) as BookingLimitsKeysInputType;
|
||||
|
||||
if (outputKey) {
|
||||
res[outputKey] = value as number;
|
||||
}
|
||||
});
|
||||
return res;
|
||||
}
|
||||
@@ -1,145 +0,0 @@
|
||||
import type {
|
||||
OutputOrganizersDefaultAppLocation_2024_06_14,
|
||||
OutputIntegration_2024_06_14,
|
||||
OutputIntegrationLocation_2024_06_14,
|
||||
OutputAddressLocation_2024_06_14,
|
||||
OutputAttendeeAddressLocation_2024_06_14,
|
||||
OutputAttendeeDefinedLocation_2024_06_14,
|
||||
OutputAttendeePhoneLocation_2024_06_14,
|
||||
OutputLinkLocation_2024_06_14,
|
||||
OutputPhoneLocation_2024_06_14,
|
||||
OutputUnknownLocation_2024_06_14,
|
||||
OutputLocation_2024_06_14,
|
||||
} from "@calcom/platform-types";
|
||||
|
||||
import type { InternalLocation } from "../internal/locations";
|
||||
|
||||
const internalToApiIntegrationsMapping: Record<string, OutputIntegration_2024_06_14> = {
|
||||
"integrations:daily": "cal-video",
|
||||
"integrations:google:meet": "google-meet",
|
||||
"integrations:zoom": "zoom",
|
||||
"integrations:whereby_video": "whereby-video",
|
||||
"integrations:whatsapp_video": "whatsapp-video",
|
||||
"integrations:webex_video": "webex-video",
|
||||
"integrations:telegram_video": "telegram-video",
|
||||
"integrations:tandem": "tandem",
|
||||
"integrations:sylaps_video": "sylaps-video",
|
||||
"integrations:skype_video": "skype-video",
|
||||
"integrations:sirius_video_video": "sirius-video",
|
||||
"integrations:signal_video": "signal-video",
|
||||
"integrations:shimmer_video": "shimmer-video",
|
||||
"integrations:salesroom_video": "salesroom-video",
|
||||
"integrations:roam_video": "roam-video",
|
||||
"integrations:riverside_video": "riverside-video",
|
||||
"integrations:ping_video": "ping-video",
|
||||
"integrations:office365_video": "office365-video",
|
||||
"integrations:mirotalk_video": "mirotalk-video",
|
||||
"integrations:jitsi": "jitsi",
|
||||
"integrations:jelly_video": "jelly-video",
|
||||
"integrations:jelly_conferencing": "jelly-conferencing",
|
||||
"integrations:huddle01": "huddle",
|
||||
"integrations:facetime_video": "facetime-video",
|
||||
"integrations:element-call_video": "element-call-video",
|
||||
"integrations:eightxeight_video": "eightxeight-video",
|
||||
"integrations:discord_video": "discord-video",
|
||||
"integrations:demodesk_video": "demodesk-video",
|
||||
"integrations:campfire_video": "campfire-video",
|
||||
};
|
||||
|
||||
export function transformLocationsInternalToApi(internalLocations: InternalLocation[] | undefined) {
|
||||
if (!internalLocations) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const apiLocations: OutputLocation_2024_06_14[] = [];
|
||||
|
||||
for (const location of internalLocations) {
|
||||
switch (location.type) {
|
||||
case "inPerson": {
|
||||
if (!location.address) {
|
||||
continue;
|
||||
}
|
||||
const addressLocation: OutputAddressLocation_2024_06_14 = {
|
||||
type: "address",
|
||||
address: location.address,
|
||||
public: location.displayLocationPublicly,
|
||||
};
|
||||
apiLocations.push(addressLocation);
|
||||
break;
|
||||
}
|
||||
case "attendeeInPerson": {
|
||||
const attendeeAddressLocation: OutputAttendeeAddressLocation_2024_06_14 = {
|
||||
type: "attendeeAddress",
|
||||
};
|
||||
apiLocations.push(attendeeAddressLocation);
|
||||
break;
|
||||
}
|
||||
case "link": {
|
||||
if (!location.link) {
|
||||
continue;
|
||||
}
|
||||
const linkLocation: OutputLinkLocation_2024_06_14 = {
|
||||
type: "link",
|
||||
link: location.link,
|
||||
public: location.displayLocationPublicly,
|
||||
};
|
||||
apiLocations.push(linkLocation);
|
||||
break;
|
||||
}
|
||||
case "userPhone": {
|
||||
if (!location.hostPhoneNumber) {
|
||||
continue;
|
||||
}
|
||||
const phoneLocation: OutputPhoneLocation_2024_06_14 = {
|
||||
type: "phone",
|
||||
phone: location.hostPhoneNumber,
|
||||
public: location.displayLocationPublicly,
|
||||
};
|
||||
apiLocations.push(phoneLocation);
|
||||
break;
|
||||
}
|
||||
case "phone": {
|
||||
const attendeePhoneLocation: OutputAttendeePhoneLocation_2024_06_14 = {
|
||||
type: "attendeePhone",
|
||||
};
|
||||
apiLocations.push(attendeePhoneLocation);
|
||||
break;
|
||||
}
|
||||
case "somewhereElse": {
|
||||
const attendeeDefinedLocation: OutputAttendeeDefinedLocation_2024_06_14 = {
|
||||
type: "attendeeDefined",
|
||||
};
|
||||
apiLocations.push(attendeeDefinedLocation);
|
||||
break;
|
||||
}
|
||||
case "conferencing": {
|
||||
const conferencingLocation: OutputOrganizersDefaultAppLocation_2024_06_14 = {
|
||||
type: "organizersDefaultApp",
|
||||
};
|
||||
apiLocations.push(conferencingLocation);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
const integrationType = internalToApiIntegrationsMapping[location.type];
|
||||
if (!integrationType) {
|
||||
const unknown: OutputUnknownLocation_2024_06_14 = {
|
||||
type: "unknown",
|
||||
location: JSON.stringify(location),
|
||||
};
|
||||
apiLocations.push(unknown);
|
||||
break;
|
||||
}
|
||||
const integration: OutputIntegrationLocation_2024_06_14 = {
|
||||
type: "integration",
|
||||
integration: integrationType,
|
||||
link: location.link,
|
||||
credentialId: location.credentialId,
|
||||
};
|
||||
apiLocations.push(integration);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return apiLocations;
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
import { Frequency, FrequencyInput } from "@calcom/platform-enums/monorepo";
|
||||
import type { Recurrence_2024_06_14, TransformRecurringEventSchema_2024_06_14 } from "@calcom/platform-types";
|
||||
|
||||
export function transformRecurrenceInternalToApi(
|
||||
transformRecurringEvent: TransformRecurringEventSchema_2024_06_14
|
||||
): Recurrence_2024_06_14 {
|
||||
return {
|
||||
interval: transformRecurringEvent.interval,
|
||||
occurrences: transformRecurringEvent.count,
|
||||
frequency: FrequencyInput[Frequency[transformRecurringEvent.freq] as keyof typeof FrequencyInput],
|
||||
} satisfies Recurrence_2024_06_14;
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
import { ConfirmationPolicyEnum } from "@calcom/platform-enums/monorepo";
|
||||
import type { NoticeThresholdTransformedSchema, ConfirmationPolicy_2024_06_14 } from "@calcom/platform-types";
|
||||
|
||||
export function transformRequiresConfirmationInternalToApi(
|
||||
requiresConfirmation: boolean,
|
||||
requiresConfirmationWillBlockSlot: boolean,
|
||||
requiresConfirmationThreshold?: NoticeThresholdTransformedSchema
|
||||
): ConfirmationPolicy_2024_06_14 | undefined {
|
||||
if (requiresConfirmationThreshold?.unit) {
|
||||
return {
|
||||
type: ConfirmationPolicyEnum.TIME,
|
||||
noticeThreshold: {
|
||||
unit: requiresConfirmationThreshold.unit,
|
||||
count: requiresConfirmationThreshold.time,
|
||||
},
|
||||
blockUnconfirmedBookingsInBooker: requiresConfirmationWillBlockSlot,
|
||||
};
|
||||
} else if (requiresConfirmation) {
|
||||
return {
|
||||
type: ConfirmationPolicyEnum.ALWAYS,
|
||||
blockUnconfirmedBookingsInBooker: requiresConfirmationWillBlockSlot,
|
||||
};
|
||||
} else if (!requiresConfirmation) {
|
||||
return {
|
||||
disabled: true,
|
||||
};
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
import type {
|
||||
SeatOptionsTransformedSchema,
|
||||
SeatOptionsDisabledSchema,
|
||||
Seats_2024_06_14,
|
||||
Disabled_2024_06_14,
|
||||
} from "@calcom/platform-types";
|
||||
|
||||
export function transformSeatsInternalToApi(
|
||||
transformedSeats: SeatOptionsTransformedSchema | SeatOptionsDisabledSchema
|
||||
): Seats_2024_06_14 | Disabled_2024_06_14 {
|
||||
if (transformedSeats.seatsPerTimeSlot == null) {
|
||||
return {
|
||||
disabled: true,
|
||||
} satisfies Disabled_2024_06_14;
|
||||
}
|
||||
return {
|
||||
seatsPerTimeSlot: transformedSeats.seatsPerTimeSlot,
|
||||
showAttendeeInfo: transformedSeats.seatsShowAttendees,
|
||||
showAvailabilityCount: transformedSeats.seatsShowAvailabilityCount,
|
||||
} satisfies Seats_2024_06_14;
|
||||
}
|
||||
@@ -1,137 +0,0 @@
|
||||
import { z } from "zod";
|
||||
|
||||
const integrationsApiAvailable = {
|
||||
"cal-video": z.literal("integrations:daily"),
|
||||
"google-meet": z.literal("integrations:google:meet"),
|
||||
zoom: z.literal("integrations:zoom"),
|
||||
"office365-video": z.literal("integrations:office365_video"),
|
||||
};
|
||||
|
||||
// note(Lauris): these are read only aka they exist in database and are to be returned by a READ operation
|
||||
const integrationsApiUnavailable = {
|
||||
zoom: z.literal("integrations:zoom"),
|
||||
"whereby-video": z.literal("integrations:whereby_video"),
|
||||
"whatsapp-video": z.literal("integrations:whatsapp_video"),
|
||||
"webex-video": z.literal("integrations:webex_video"),
|
||||
"telegram-video": z.literal("integrations:telegram_video"),
|
||||
tandem: z.literal("integrations:tandem"),
|
||||
"sylaps-video": z.literal("integrations:sylaps_video"),
|
||||
"skype-video": z.literal("integrations:skype_video"),
|
||||
"sirius-video": z.literal("integrations:sirius_video_video"),
|
||||
"signal-video": z.literal("integrations:signal_video"),
|
||||
"shimmer-video": z.literal("integrations:shimmer_video"),
|
||||
"salesroom-video": z.literal("integrations:salesroom_video"),
|
||||
"roam-video": z.literal("integrations:roam_video"),
|
||||
"riverside-video": z.literal("integrations:riverside_video"),
|
||||
"ping-video": z.literal("integrations:ping_video"),
|
||||
"office365-video": z.literal("integrations:office365_video"),
|
||||
"mirotalk-video": z.literal("integrations:mirotalk_video"),
|
||||
jitsi: z.literal("integrations:jitsi"),
|
||||
"jelly-video": z.literal("integrations:jelly_video"),
|
||||
"jelly-conferencing": z.literal("integrations:jelly_conferencing"),
|
||||
huddle: z.literal("integrations:huddle01"),
|
||||
"facetime-video": z.literal("integrations:facetime_video"),
|
||||
"element-call-video": z.literal("integrations:element-call_video"),
|
||||
"eightxeight-video": z.literal("integrations:eightxeight_video"),
|
||||
"discord-video": z.literal("integrations:discord_video"),
|
||||
"demodesk-video": z.literal("integrations:demodesk_video"),
|
||||
"campfire-video": z.literal("integrations:campfire_video"),
|
||||
};
|
||||
|
||||
export const integrationsApiToInternalMappingSchema = {
|
||||
...integrationsApiAvailable,
|
||||
...integrationsApiUnavailable,
|
||||
};
|
||||
|
||||
const OrganizerIntegrationSchema = z.object({
|
||||
type: z.union([
|
||||
integrationsApiToInternalMappingSchema["cal-video"],
|
||||
integrationsApiToInternalMappingSchema["google-meet"],
|
||||
integrationsApiToInternalMappingSchema["zoom"],
|
||||
integrationsApiToInternalMappingSchema["whereby-video"],
|
||||
integrationsApiToInternalMappingSchema["whatsapp-video"],
|
||||
integrationsApiToInternalMappingSchema["webex-video"],
|
||||
integrationsApiToInternalMappingSchema["telegram-video"],
|
||||
integrationsApiToInternalMappingSchema["tandem"],
|
||||
integrationsApiToInternalMappingSchema["sylaps-video"],
|
||||
integrationsApiToInternalMappingSchema["skype-video"],
|
||||
integrationsApiToInternalMappingSchema["sirius-video"],
|
||||
integrationsApiToInternalMappingSchema["signal-video"],
|
||||
integrationsApiToInternalMappingSchema["shimmer-video"],
|
||||
integrationsApiToInternalMappingSchema["salesroom-video"],
|
||||
integrationsApiToInternalMappingSchema["roam-video"],
|
||||
integrationsApiToInternalMappingSchema["riverside-video"],
|
||||
integrationsApiToInternalMappingSchema["ping-video"],
|
||||
integrationsApiToInternalMappingSchema["office365-video"],
|
||||
integrationsApiToInternalMappingSchema["mirotalk-video"],
|
||||
integrationsApiToInternalMappingSchema["jitsi"],
|
||||
integrationsApiToInternalMappingSchema["jelly-video"],
|
||||
integrationsApiToInternalMappingSchema["jelly-conferencing"],
|
||||
integrationsApiToInternalMappingSchema["huddle"],
|
||||
integrationsApiToInternalMappingSchema["facetime-video"],
|
||||
integrationsApiToInternalMappingSchema["element-call-video"],
|
||||
integrationsApiToInternalMappingSchema["eightxeight-video"],
|
||||
integrationsApiToInternalMappingSchema["discord-video"],
|
||||
integrationsApiToInternalMappingSchema["demodesk-video"],
|
||||
integrationsApiToInternalMappingSchema["campfire-video"],
|
||||
]),
|
||||
link: z.string().url().optional(),
|
||||
credentialId: z.number().optional(),
|
||||
});
|
||||
|
||||
const OrganizerAddressSchema = z.object({
|
||||
type: z.literal("inPerson"),
|
||||
address: z.string(),
|
||||
displayLocationPublicly: z.boolean().default(false),
|
||||
});
|
||||
|
||||
const OrganizerLinkSchema = z.object({
|
||||
type: z.literal("link"),
|
||||
link: z.string().url(),
|
||||
displayLocationPublicly: z.boolean().default(false),
|
||||
});
|
||||
|
||||
const OrganizerPhoneSchema = z.object({
|
||||
type: z.literal("userPhone"),
|
||||
hostPhoneNumber: z.string(),
|
||||
displayLocationPublicly: z.boolean().default(false),
|
||||
});
|
||||
|
||||
const OrganizerConferencingSchema = z.object({
|
||||
type: z.literal("conferencing"),
|
||||
});
|
||||
|
||||
const AttendeeAddressSchema = z.object({
|
||||
type: z.literal("attendeeInPerson"),
|
||||
});
|
||||
|
||||
const AttendeePhoneSchema = z.object({
|
||||
type: z.literal("phone"),
|
||||
});
|
||||
|
||||
const AttendeeDefinedSchema = z.object({
|
||||
type: z.literal("somewhereElse"),
|
||||
});
|
||||
|
||||
export type OrganizerAddressLocation = z.infer<typeof OrganizerAddressSchema>;
|
||||
export type OrganizerLinkLocation = z.infer<typeof OrganizerLinkSchema>;
|
||||
export type OrganizerIntegrationLocation = z.infer<typeof OrganizerIntegrationSchema>;
|
||||
export type OrganizerPhoneLocation = z.infer<typeof OrganizerPhoneSchema>;
|
||||
export type OrganizerConferencingSchema = z.infer<typeof OrganizerConferencingSchema>;
|
||||
export type AttendeeAddressLocation = z.infer<typeof AttendeeAddressSchema>;
|
||||
export type AttendeePhoneLocation = z.infer<typeof AttendeePhoneSchema>;
|
||||
export type AttendeeDefinedLocation = z.infer<typeof AttendeeDefinedSchema>;
|
||||
|
||||
export const InternalLocationSchema = z.union([
|
||||
OrganizerAddressSchema,
|
||||
OrganizerLinkSchema,
|
||||
OrganizerIntegrationSchema,
|
||||
OrganizerPhoneSchema,
|
||||
OrganizerConferencingSchema,
|
||||
AttendeeAddressSchema,
|
||||
AttendeePhoneSchema,
|
||||
AttendeeDefinedSchema,
|
||||
]);
|
||||
export type InternalLocation = z.infer<typeof InternalLocationSchema>;
|
||||
|
||||
export const InternalLocationsSchema = z.array(InternalLocationSchema);
|
||||
@@ -1,54 +0,0 @@
|
||||
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];
|
||||
}
|
||||
@@ -1,2 +1 @@
|
||||
export * from "./for-atom";
|
||||
export * from "./from-api";
|
||||
@@ -0,0 +1,133 @@
|
||||
import { getAvailabilityFromSchedule } from "@calcom/lib/availability";
|
||||
import { hasEditPermissionForUserID } from "@calcom/lib/hasEditPermissionForUser";
|
||||
import { transformScheduleToAvailabilityForAtom } from "@calcom/lib/schedules/transformers/for-atom";
|
||||
import type { PrismaClient } from "@calcom/prisma";
|
||||
import type { TUpdateInputSchema } from "@calcom/trpc/server/routers/viewer/availability/schedule/update.schema";
|
||||
import { setupDefaultSchedule } from "@calcom/trpc/server/routers/viewer/availability/util";
|
||||
import type { TrpcSessionUser } from "@calcom/trpc/server/types";
|
||||
|
||||
import { TRPCError } from "@trpc/server";
|
||||
|
||||
interface IUpdateScheduleOptions {
|
||||
input: TUpdateInputSchema;
|
||||
user: Pick<NonNullable<TrpcSessionUser>, "id" | "defaultScheduleId" | "timeZone">;
|
||||
prisma: PrismaClient;
|
||||
}
|
||||
|
||||
export type UpdateScheduleResponse = Awaited<ReturnType<typeof updateSchedule>>;
|
||||
|
||||
export const updateSchedule = async ({ input, user, prisma }: IUpdateScheduleOptions) => {
|
||||
const availability = input.schedule
|
||||
? getAvailabilityFromSchedule(input.schedule)
|
||||
: (input.dateOverrides || []).map((dateOverride) => ({
|
||||
startTime: dateOverride.start,
|
||||
endTime: dateOverride.end,
|
||||
date: dateOverride.start,
|
||||
days: [],
|
||||
}));
|
||||
|
||||
// Not able to update the schedule with userId where clause, so fetch schedule separately and then validate
|
||||
// Bug: https://github.com/prisma/prisma/issues/7290
|
||||
const userSchedule = await prisma.schedule.findUnique({
|
||||
where: {
|
||||
id: input.scheduleId,
|
||||
},
|
||||
select: {
|
||||
userId: true,
|
||||
name: true,
|
||||
id: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!userSchedule) {
|
||||
throw new TRPCError({
|
||||
code: "UNAUTHORIZED",
|
||||
});
|
||||
}
|
||||
|
||||
if (userSchedule?.userId !== user.id) {
|
||||
const hasEditPermission = await hasEditPermissionForUserID({
|
||||
ctx: {
|
||||
user,
|
||||
},
|
||||
input: { memberId: userSchedule.userId },
|
||||
});
|
||||
if (!hasEditPermission) {
|
||||
throw new TRPCError({
|
||||
code: "UNAUTHORIZED",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
let updatedUser;
|
||||
if (input.isDefault) {
|
||||
const setupDefault = await setupDefaultSchedule(user.id, input.scheduleId, prisma);
|
||||
updatedUser = setupDefault;
|
||||
}
|
||||
|
||||
if (!input.name) {
|
||||
// TODO: Improve
|
||||
// We don't want to pass the full schedule for just a set as default update
|
||||
// but in the current logic, this wipes the existing availability.
|
||||
// Return early to prevent this from happening.
|
||||
return {
|
||||
schedule: userSchedule,
|
||||
isDefault: updatedUser
|
||||
? updatedUser.defaultScheduleId === input.scheduleId
|
||||
: user.defaultScheduleId === input.scheduleId,
|
||||
};
|
||||
}
|
||||
|
||||
const schedule = await prisma.schedule.update({
|
||||
where: {
|
||||
id: input.scheduleId,
|
||||
},
|
||||
data: {
|
||||
timeZone: input.timeZone,
|
||||
name: input.name,
|
||||
availability: {
|
||||
deleteMany: {
|
||||
scheduleId: {
|
||||
equals: input.scheduleId,
|
||||
},
|
||||
},
|
||||
createMany: {
|
||||
data: [
|
||||
...availability,
|
||||
...(input.dateOverrides || []).map((override) => ({
|
||||
date: override.start,
|
||||
startTime: override.start,
|
||||
endTime: override.end,
|
||||
})),
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
userId: true,
|
||||
name: true,
|
||||
availability: true,
|
||||
timeZone: true,
|
||||
eventType: {
|
||||
select: {
|
||||
id: true,
|
||||
eventName: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const userAvailability = transformScheduleToAvailabilityForAtom(schedule);
|
||||
|
||||
return {
|
||||
schedule,
|
||||
availability: userAvailability,
|
||||
timeZone: schedule.timeZone || user.timeZone,
|
||||
isDefault: updatedUser
|
||||
? updatedUser.defaultScheduleId === schedule.id
|
||||
: user.defaultScheduleId === schedule.id,
|
||||
prevDefaultId: user.defaultScheduleId,
|
||||
currentDefaultId: updatedUser ? updatedUser.defaultScheduleId : user.defaultScheduleId,
|
||||
};
|
||||
};
|
||||
@@ -8,6 +8,10 @@ import {
|
||||
transformWorkingHoursForAtom,
|
||||
} from "../../schedules/transformers";
|
||||
|
||||
export type FindDetailedScheduleByIdReturnType = Awaited<
|
||||
ReturnType<typeof ScheduleRepository.findDetailedScheduleById>
|
||||
>;
|
||||
|
||||
export class ScheduleRepository {
|
||||
static async findScheduleById({ id }: { id: number }) {
|
||||
const schedule = await prisma.schedule.findUnique({
|
||||
|
||||
-152
@@ -1,152 +0,0 @@
|
||||
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);
|
||||
});
|
||||
});
|
||||
-60
@@ -1,60 +0,0 @@
|
||||
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,
|
||||
id: schedule.id,
|
||||
};
|
||||
});
|
||||
|
||||
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
@@ -1,72 +0,0 @@
|
||||
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);
|
||||
});
|
||||
});
|
||||
-88
@@ -1,88 +0,0 @@
|
||||
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) => transfromAtomOverrideForApi(range)) ?? []
|
||||
) ?? [];
|
||||
|
||||
const availability = formatScheduleTime(schedule);
|
||||
|
||||
return { name, timeZone, isDefault, availability, overrides };
|
||||
}
|
||||
|
||||
type AtomDateOverride = {
|
||||
start: Date;
|
||||
end: Date;
|
||||
};
|
||||
|
||||
function transfromAtomOverrideForApi(override: AtomDateOverride) {
|
||||
const date = `${override.start.getUTCFullYear()}-${(override.start.getUTCMonth() + 1)
|
||||
.toString()
|
||||
.padStart(2, "0")}-${override.start.getUTCDate().toString().padStart(2, "0")}`;
|
||||
|
||||
return {
|
||||
date,
|
||||
startTime: padHoursMinutesWithZeros(`${override.start.getUTCHours()}:${override.start.getUTCMinutes()}`),
|
||||
endTime: padHoursMinutesWithZeros(`${override.end.getUTCHours()}:${override.end.getUTCMinutes()}`),
|
||||
};
|
||||
}
|
||||
|
||||
function padHoursMinutesWithZeros(hhMM: string) {
|
||||
const [hours, minutes] = hhMM.split(":");
|
||||
|
||||
const formattedHours = hours.padStart(2, "0");
|
||||
const formattedMinutes = minutes.padStart(2, "0");
|
||||
|
||||
return `${formattedHours}:${formattedMinutes}`;
|
||||
}
|
||||
|
||||
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}`;
|
||||
}
|
||||
+15
-20
@@ -1,25 +1,18 @@
|
||||
import type { ReactNode } from "react";
|
||||
|
||||
import type { ScheduleLabelsType } from "@calcom/features/schedules/components/Schedule";
|
||||
import type {
|
||||
ApiErrorResponse,
|
||||
ApiResponse,
|
||||
ScheduleOutput_2024_06_11,
|
||||
UpdateScheduleInput_2024_06_11,
|
||||
} from "@calcom/platform-types";
|
||||
import type { UpdateScheduleResponse } from "@calcom/lib/schedules/updateSchedule";
|
||||
import type { ApiErrorResponse, ApiResponse, UpdateScheduleInput_2024_06_11 } from "@calcom/platform-types";
|
||||
|
||||
import { useAtomSchedule } from "../../hooks/schedules/useAtomSchedule";
|
||||
import { useAtomUpdateSchedule } from "../../hooks/schedules/useAtomUpdateSchedule";
|
||||
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 { AtomsWrapper } from "../../src/components/atoms-wrapper";
|
||||
import { useToast } from "../../src/components/ui/use-toast";
|
||||
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 = {
|
||||
@@ -28,7 +21,7 @@ type AvailabilitySettingsPlatformWrapperProps = {
|
||||
tooltips: Partial<ScheduleLabelsType>;
|
||||
};
|
||||
customClassNames?: Partial<CustomClassNames>;
|
||||
onUpdateSuccess?: (res: ApiResponse<ScheduleOutput_2024_06_11>) => void;
|
||||
onUpdateSuccess?: (res: ApiResponse<UpdateScheduleResponse>) => void;
|
||||
onUpdateError?: (err: ApiErrorResponse) => void;
|
||||
onDeleteSuccess?: (res: ApiResponse) => void;
|
||||
onDeleteError?: (err: ApiErrorResponse) => void;
|
||||
@@ -62,10 +55,8 @@ export const AvailabilitySettingsPlatformWrapper = ({
|
||||
noScheduleChildren,
|
||||
loadingStateChildren,
|
||||
}: AvailabilitySettingsPlatformWrapperProps) => {
|
||||
const { isLoading, data: schedule } = useSchedule(id);
|
||||
const { data: schedules } = useSchedules();
|
||||
const { isLoading, data: atomSchedule } = useAtomSchedule(id);
|
||||
const { data: me } = useMe();
|
||||
const atomSchedule = transformApiScheduleForAtom(me?.data, schedule, schedules?.length || 0);
|
||||
const { timeFormat } = me?.data || { timeFormat: null };
|
||||
const { toast } = useToast();
|
||||
|
||||
@@ -88,7 +79,7 @@ export const AvailabilitySettingsPlatformWrapper = ({
|
||||
},
|
||||
});
|
||||
|
||||
const { mutate: updateSchedule, isPending: isSavingInProgress } = useUpdateSchedule({
|
||||
const { mutate: updateSchedule, isPending: isSavingInProgress } = useAtomUpdateSchedule({
|
||||
onSuccess: (res) => {
|
||||
onUpdateSuccess?.(res);
|
||||
if (!disableToasts) {
|
||||
@@ -112,16 +103,20 @@ export const AvailabilitySettingsPlatformWrapper = ({
|
||||
};
|
||||
|
||||
const handleUpdate = async (id: number, body: AvailabilityFormValues) => {
|
||||
const updateBody = transformAtomScheduleForApi(body);
|
||||
|
||||
let canUpdate = true;
|
||||
|
||||
if (onBeforeUpdate) {
|
||||
canUpdate = await onBeforeUpdate(updateBody);
|
||||
canUpdate = await onBeforeUpdate(body);
|
||||
}
|
||||
|
||||
if (canUpdate) {
|
||||
updateSchedule({ id, ...updateBody });
|
||||
updateSchedule({
|
||||
scheduleId: id,
|
||||
body: {
|
||||
...body,
|
||||
dateOverrides: body.dateOverrides.flatMap((override) => override.ranges),
|
||||
},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -14,14 +14,10 @@ import { useTimePreferences } from "@calcom/features/bookings/lib";
|
||||
import { useTimesForSchedule } from "@calcom/features/schedules/lib/use-schedule/useTimesForSchedule";
|
||||
import { getRoutedTeamMemberIdsFromSearchParams } from "@calcom/lib/bookings/getRoutedTeamMemberIdsFromSearchParams";
|
||||
import { getUsernameList } from "@calcom/lib/defaultEvents";
|
||||
import type { ConnectedDestinationCalendars } from "@calcom/lib/getConnectedDestinationCalendars";
|
||||
import { localStorage } from "@calcom/lib/webstorage";
|
||||
import type { ConnectedDestinationCalendars } from "@calcom/platform-libraries";
|
||||
import { BookerLayouts } from "@calcom/prisma/zod-utils";
|
||||
|
||||
import {
|
||||
transformApiEventTypeForAtom,
|
||||
transformApiTeamEventTypeForAtom,
|
||||
} from "../event-types/atom-api-transformers/transformApiEventTypeForAtom";
|
||||
import { useCreateBooking } from "../hooks/bookings/useCreateBooking";
|
||||
import { useCreateInstantBooking } from "../hooks/bookings/useCreateInstantBooking";
|
||||
import { useCreateRecurringBooking } from "../hooks/bookings/useCreateRecurringBooking";
|
||||
@@ -30,8 +26,7 @@ import {
|
||||
QUERY_KEY as BOOKING_RESCHEDULE_KEY,
|
||||
} from "../hooks/bookings/useGetBookingForReschedule";
|
||||
import { useHandleBookEvent } from "../hooks/bookings/useHandleBookEvent";
|
||||
import { useEventType } from "../hooks/event-types/public/useEventType";
|
||||
import { useTeamEventType } from "../hooks/event-types/public/useTeamEventType";
|
||||
import { useAtomGetPublicEvent } from "../hooks/event-types/public/useAtomGetPublicEvent";
|
||||
import { useAtomsContext } from "../hooks/useAtomsContext";
|
||||
import { useAvailableSlots } from "../hooks/useAvailableSlots";
|
||||
import { useCalendarsBusyTimes } from "../hooks/useCalendarsBusyTimes";
|
||||
@@ -74,6 +69,7 @@ export const BookerPlatformWrapper = (
|
||||
const bookingData = useBookerStore((state) => state.bookingData);
|
||||
const setSelectedTimeslot = useBookerStore((state) => state.setSelectedTimeslot);
|
||||
const setSelectedMonth = useBookerStore((state) => state.setMonth);
|
||||
const selectedDuration = useBookerStore((state) => state.selectedDuration);
|
||||
|
||||
const [isOverlayCalendarEnabled, setIsOverlayCalendarEnabled] = useState(
|
||||
Boolean(localStorage?.getItem?.("overlayCalendarSwitchDefault"))
|
||||
@@ -147,61 +143,13 @@ export const BookerPlatformWrapper = (
|
||||
return getUsernameList(username ?? "").length > 1;
|
||||
}, [username]);
|
||||
|
||||
const { isSuccess, isError, isPending, data } = useEventType(username, props.eventSlug, props.isTeamEvent);
|
||||
const {
|
||||
isSuccess: isTeamSuccess,
|
||||
isError: isTeamError,
|
||||
isPending: isTeamPending,
|
||||
data: teamEventTypeData,
|
||||
} = useTeamEventType(teamId, props.eventSlug, props.isTeamEvent, props.hostsLimit);
|
||||
|
||||
const event = useMemo(() => {
|
||||
if (props.isTeamEvent && !isTeamPending && teamId && teamEventTypeData && teamEventTypeData.length > 0) {
|
||||
return {
|
||||
isSuccess: isTeamSuccess,
|
||||
isError: isTeamError,
|
||||
isPending: isTeamPending,
|
||||
data:
|
||||
teamEventTypeData && teamEventTypeData.length > 0
|
||||
? transformApiTeamEventTypeForAtom(
|
||||
teamEventTypeData[0],
|
||||
props.entity,
|
||||
props.defaultFormValues,
|
||||
!!props.hostsLimit
|
||||
)
|
||||
: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
isSuccess,
|
||||
isError,
|
||||
isPending,
|
||||
data:
|
||||
data && data.length > 0
|
||||
? transformApiEventTypeForAtom(data[0], props.entity, props.defaultFormValues, !!props.hostsLimit)
|
||||
: undefined,
|
||||
};
|
||||
}, [
|
||||
props.isTeamEvent,
|
||||
const event = useAtomGetPublicEvent({
|
||||
username,
|
||||
eventSlug: props.eventSlug,
|
||||
isTeamEvent: props.isTeamEvent,
|
||||
teamId,
|
||||
props.entity,
|
||||
teamEventTypeData,
|
||||
isSuccess,
|
||||
isError,
|
||||
isPending,
|
||||
data,
|
||||
isTeamPending,
|
||||
isTeamSuccess,
|
||||
isTeamError,
|
||||
props.hostsLimit,
|
||||
]);
|
||||
|
||||
if (isDynamic && props.duration && event.data) {
|
||||
// note(Lauris): Mandatory - In case of "dynamic" event type default event duration returned by the API is 30,
|
||||
// but we are re-using the dynamic event type as a team event, so we must set the event length to whatever the event length is.
|
||||
event.data.length = props.duration;
|
||||
}
|
||||
selectedDuration,
|
||||
});
|
||||
|
||||
const bookerLayout = useBookerLayout(event.data?.profile?.bookerLayouts);
|
||||
useInitializeBookerStore({
|
||||
@@ -209,7 +157,7 @@ export const BookerPlatformWrapper = (
|
||||
teamMemberEmail,
|
||||
crmAppSlug,
|
||||
crmOwnerRecordType,
|
||||
eventId: event.data?.id,
|
||||
eventId: event?.data?.id,
|
||||
rescheduleUid: props.rescheduleUid ?? null,
|
||||
bookingUid: props.bookingUid ?? null,
|
||||
layout: layout,
|
||||
@@ -225,8 +173,6 @@ export const BookerPlatformWrapper = (
|
||||
const month = useBookerStore((state) => state.month);
|
||||
const eventSlug = useBookerStore((state) => state.eventSlug);
|
||||
|
||||
const selectedDuration = useBookerStore((state) => state.selectedDuration);
|
||||
|
||||
const { data: session } = useMe();
|
||||
const hasSession = !!session;
|
||||
const { name: defaultName, guests: defaultGuests, ...restFormValues } = props.defaultFormValues ?? {};
|
||||
@@ -323,7 +269,7 @@ export const BookerPlatformWrapper = (
|
||||
Boolean(teamId || username) &&
|
||||
Boolean(month) &&
|
||||
Boolean(timezone) &&
|
||||
(props.isTeamEvent ? !isTeamPending : !isPending) &&
|
||||
!event?.isPending &&
|
||||
Boolean(event?.data?.id),
|
||||
orgSlug: props.entity?.orgSlug ?? undefined,
|
||||
eventTypeSlug: isDynamic ? "dynamic" : eventSlug || "",
|
||||
@@ -331,7 +277,7 @@ export const BookerPlatformWrapper = (
|
||||
});
|
||||
|
||||
const bookerForm = useBookingForm({
|
||||
event: event.data,
|
||||
event: event?.data,
|
||||
sessionEmail:
|
||||
session?.data?.email && clientId
|
||||
? session.data.email.replace(`+${clientId}`, "")
|
||||
@@ -356,8 +302,8 @@ export const BookerPlatformWrapper = (
|
||||
schedule.refetch();
|
||||
props.onCreateBookingSuccess?.(data);
|
||||
|
||||
if (!preventEventTypeRedirect && !!event.data?.successRedirectUrl) {
|
||||
window.location.href = event.data.successRedirectUrl;
|
||||
if (!preventEventTypeRedirect && !!event?.data?.successRedirectUrl) {
|
||||
window.location.href = event?.data?.successRedirectUrl;
|
||||
}
|
||||
},
|
||||
onError: props.onCreateBookingError,
|
||||
@@ -376,8 +322,8 @@ export const BookerPlatformWrapper = (
|
||||
schedule.refetch();
|
||||
props.onCreateRecurringBookingSuccess?.(data);
|
||||
|
||||
if (!!event.data?.successRedirectUrl) {
|
||||
window.location.href = event.data.successRedirectUrl;
|
||||
if (!!event?.data?.successRedirectUrl) {
|
||||
window.location.href = event?.data?.successRedirectUrl;
|
||||
}
|
||||
},
|
||||
onError: props.onCreateRecurringBookingError,
|
||||
|
||||
@@ -3,7 +3,7 @@ import type React from "react";
|
||||
import type { BookerProps } from "@calcom/features/bookings/Booker";
|
||||
import type { BookerStore } from "@calcom/features/bookings/Booker/store";
|
||||
import type { Timezone } from "@calcom/features/bookings/Booker/types";
|
||||
import type { BookingResponse } from "@calcom/platform-libraries";
|
||||
import type { BookingResponse } from "@calcom/features/bookings/types";
|
||||
import type {
|
||||
ApiSuccessResponse,
|
||||
ApiErrorResponse,
|
||||
|
||||
@@ -4,11 +4,11 @@ import { useState, useEffect, useMemo } from "react";
|
||||
|
||||
import { SingleValueComponent } from "@calcom/features/calendars/DestinationCalendarSelector";
|
||||
import { OptionComponent } from "@calcom/features/calendars/DestinationCalendarSelector";
|
||||
import type { ConnectedDestinationCalendars } from "@calcom/lib/getConnectedDestinationCalendars";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import type { ConnectedDestinationCalendars } from "@calcom/platform-libraries";
|
||||
import classNames from "@calcom/ui/classNames";
|
||||
import { Badge } from "@calcom/ui/components/badge";
|
||||
import { Select } from "@calcom/ui/components/form";
|
||||
import classNames from "@calcom/ui/classNames";
|
||||
|
||||
import { getPlaceholderContent } from "../lib/getPlaceholderContent";
|
||||
|
||||
|
||||
-407
@@ -1,407 +0,0 @@
|
||||
import { defaultEvents } from "@calcom/lib/defaultEvents";
|
||||
import type { SystemField } from "@calcom/lib/event-types/transformers";
|
||||
import {
|
||||
transformTeamLocationsApiToInternal,
|
||||
transformBookingFieldsApiToInternal,
|
||||
systemBeforeFieldName,
|
||||
systemBeforeFieldEmail,
|
||||
systemBeforeFieldLocation,
|
||||
systemAfterFieldRescheduleReason,
|
||||
transformRecurrenceApiToInternal,
|
||||
transformIntervalLimitsApiToInternal,
|
||||
transformSeatsApiToInternal,
|
||||
transformEventColorsApiToInternal,
|
||||
transformConfirmationPolicyApiToInternal,
|
||||
transformFutureBookingLimitsApiToInternal,
|
||||
} from "@calcom/lib/event-types/transformers";
|
||||
import { getBookerBaseUrlSync } from "@calcom/lib/getBookerUrl/client";
|
||||
import type {
|
||||
EmailDefaultFieldOutput_2024_06_14,
|
||||
EventTypeOutput_2024_06_14,
|
||||
InputLocation_2024_06_14,
|
||||
KnownBookingField_2024_06_14,
|
||||
NameDefaultFieldOutput_2024_06_14,
|
||||
TeamEventTypeOutput_2024_06_14,
|
||||
} from "@calcom/platform-types";
|
||||
import {
|
||||
bookerLayoutOptions,
|
||||
BookerLayouts,
|
||||
bookerLayouts as bookerLayoutsSchema,
|
||||
userMetadata as userMetadataSchema,
|
||||
eventTypeBookingFields,
|
||||
EventTypeMetaDataSchema,
|
||||
} from "@calcom/prisma/zod-utils";
|
||||
|
||||
import type { BookerPlatformWrapperAtomProps } from "../../booker/types";
|
||||
|
||||
export function transformApiEventTypeForAtom(
|
||||
eventType: Omit<EventTypeOutput_2024_06_14, "ownerId"> & { bannerUrl?: string },
|
||||
entity: BookerPlatformWrapperAtomProps["entity"] | undefined,
|
||||
defaultFormValues: BookerPlatformWrapperAtomProps["defaultFormValues"] | undefined,
|
||||
limitHosts = false
|
||||
) {
|
||||
const {
|
||||
lengthInMinutes,
|
||||
lengthInMinutesOptions,
|
||||
locations,
|
||||
bookingFields,
|
||||
users,
|
||||
recurrence,
|
||||
bookingLimitsCount,
|
||||
bookingLimitsDuration,
|
||||
seats,
|
||||
color,
|
||||
confirmationPolicy,
|
||||
customName,
|
||||
useDestinationCalendarEmail,
|
||||
bookingWindow,
|
||||
...rest
|
||||
} = eventType;
|
||||
|
||||
const isDefault = isDefaultEvent(rest.title);
|
||||
const user = users[0];
|
||||
|
||||
const confirmationPolicyTransformed = transformConfirmationPolicyApiToInternal(confirmationPolicy);
|
||||
const defaultEventBookerLayouts = {
|
||||
enabledLayouts: [...bookerLayoutOptions],
|
||||
defaultLayout: BookerLayouts.MONTH_VIEW,
|
||||
};
|
||||
const firstUsersMetadata = userMetadataSchema.parse(user.metadata || {});
|
||||
const bookerLayouts = bookerLayoutsSchema.parse(
|
||||
firstUsersMetadata?.defaultBookerLayouts || defaultEventBookerLayouts
|
||||
);
|
||||
const metadata = EventTypeMetaDataSchema.parse(eventType.metadata);
|
||||
const usersTransformed = users.map((user) => ({
|
||||
...user,
|
||||
metadata: undefined,
|
||||
bookerUrl: getBookerBaseUrlSync(null),
|
||||
profile: {
|
||||
username: user.username || "",
|
||||
name: user.name,
|
||||
weekStart: user.weekStart,
|
||||
image: "",
|
||||
brandColor: user.brandColor,
|
||||
darkBrandColor: user.darkBrandColor,
|
||||
theme: null,
|
||||
organization: null,
|
||||
id: user.id,
|
||||
organizationId: null,
|
||||
userId: user.id,
|
||||
upId: `usr-${user.id}`,
|
||||
},
|
||||
}));
|
||||
|
||||
return {
|
||||
...rest,
|
||||
length: lengthInMinutes,
|
||||
locations: getLocations(locations),
|
||||
bookingFields: getBookingFields(bookingFields, defaultFormValues),
|
||||
isDefault,
|
||||
isDynamic: false,
|
||||
profile: {
|
||||
username: user.username,
|
||||
name: user.name,
|
||||
weekStart: user.weekStart,
|
||||
image: "",
|
||||
brandColor: user.brandColor,
|
||||
darkBrandColor: user.darkBrandColor,
|
||||
theme: null,
|
||||
bookerLayouts,
|
||||
},
|
||||
entity: entity
|
||||
? {
|
||||
...entity,
|
||||
orgSlug: entity.orgSlug || null,
|
||||
teamSlug: entity.teamSlug || null,
|
||||
fromRedirectOfNonOrgLink: true,
|
||||
name: entity.name || null,
|
||||
logoUrl: entity.logoUrl || undefined,
|
||||
}
|
||||
: {
|
||||
fromRedirectOfNonOrgLink: true,
|
||||
considerUnpublished: false,
|
||||
orgSlug: null,
|
||||
teamSlug: null,
|
||||
name: null,
|
||||
logoUrl: undefined,
|
||||
},
|
||||
hosts: [],
|
||||
subsetOfHosts: [],
|
||||
users: !limitHosts ? usersTransformed : undefined,
|
||||
subsetOfUsers: usersTransformed,
|
||||
bookingLimits: bookingLimitsCount ? transformIntervalLimitsApiToInternal(bookingLimitsCount) : undefined,
|
||||
durationLimits: bookingLimitsDuration
|
||||
? transformIntervalLimitsApiToInternal(bookingLimitsDuration)
|
||||
: undefined,
|
||||
|
||||
metadata: {
|
||||
...metadata,
|
||||
requiresConfirmationThreshold:
|
||||
confirmationPolicyTransformed?.requiresConfirmationThreshold ?? undefined,
|
||||
multipleDuration: lengthInMinutesOptions,
|
||||
},
|
||||
|
||||
requiresConfirmation: confirmationPolicyTransformed?.requiresConfirmation ?? undefined,
|
||||
requiresConfirmationWillBlockSlot:
|
||||
confirmationPolicyTransformed?.requiresConfirmationWillBlockSlot ?? undefined,
|
||||
|
||||
eventTypeColor: transformEventColorsApiToInternal(color),
|
||||
recurringEvent: recurrence ? transformRecurrenceApiToInternal(recurrence) : null,
|
||||
...transformSeatsApiToInternal(seats),
|
||||
eventName: customName,
|
||||
useEventTypeDestinationCalendarEmail: useDestinationCalendarEmail,
|
||||
...getBookingWindow(bookingWindow),
|
||||
};
|
||||
}
|
||||
|
||||
export function transformApiTeamEventTypeForAtom(
|
||||
eventType: TeamEventTypeOutput_2024_06_14,
|
||||
entity: BookerPlatformWrapperAtomProps["entity"] | undefined,
|
||||
defaultFormValues: BookerPlatformWrapperAtomProps["defaultFormValues"] | undefined,
|
||||
limitHosts = false
|
||||
) {
|
||||
const {
|
||||
lengthInMinutes,
|
||||
lengthInMinutesOptions,
|
||||
locations,
|
||||
hosts,
|
||||
bookingFields,
|
||||
recurrence,
|
||||
team,
|
||||
bookingLimitsCount,
|
||||
bookingLimitsDuration,
|
||||
seats,
|
||||
color,
|
||||
confirmationPolicy,
|
||||
customName,
|
||||
useDestinationCalendarEmail,
|
||||
bookingWindow,
|
||||
...rest
|
||||
} = eventType;
|
||||
|
||||
const metadata = EventTypeMetaDataSchema.parse(eventType.metadata);
|
||||
|
||||
const isDefault = isDefaultEvent(rest.title);
|
||||
|
||||
const confirmationPolicyTransformed = transformConfirmationPolicyApiToInternal(confirmationPolicy);
|
||||
const defaultEventBookerLayouts = {
|
||||
enabledLayouts: [...bookerLayoutOptions],
|
||||
defaultLayout: BookerLayouts.MONTH_VIEW,
|
||||
};
|
||||
const firstUsersMetadata = userMetadataSchema.parse({});
|
||||
const bookerLayouts = bookerLayoutsSchema.parse(
|
||||
firstUsersMetadata?.defaultBookerLayouts || defaultEventBookerLayouts
|
||||
);
|
||||
|
||||
const hostTransformed = hosts.map((host) => ({
|
||||
user: {
|
||||
id: host.userId,
|
||||
avatarUrl: null,
|
||||
name: host.name,
|
||||
username: "",
|
||||
metadata: {},
|
||||
darkBrandColor: null,
|
||||
brandColor: null,
|
||||
theme: null,
|
||||
weekStart: "Sunday",
|
||||
},
|
||||
}));
|
||||
|
||||
const usersTransformed = hosts.map((host) => ({
|
||||
...host,
|
||||
metadata: undefined,
|
||||
bookerUrl: getBookerBaseUrlSync(null),
|
||||
profile: {
|
||||
username: "",
|
||||
name: host.name,
|
||||
weekStart: "Sunday",
|
||||
image: "",
|
||||
brandColor: null,
|
||||
darkBrandColor: null,
|
||||
theme: null,
|
||||
organization: null,
|
||||
id: host.userId,
|
||||
organizationId: null,
|
||||
userId: host.userId,
|
||||
upId: `usr-${host.userId}`,
|
||||
},
|
||||
}));
|
||||
|
||||
return {
|
||||
...rest,
|
||||
length: lengthInMinutes,
|
||||
locations: getLocations(locations),
|
||||
bookingFields: getBookingFields(bookingFields, defaultFormValues),
|
||||
isDefault,
|
||||
isDynamic: false,
|
||||
profile: {
|
||||
username: team?.slug ?? "team",
|
||||
name: team?.name,
|
||||
weekStart: team?.weekStart ?? "Sunday",
|
||||
image: team?.logoUrl,
|
||||
brandColor: team?.brandColor ?? null,
|
||||
darkBrandColor: team?.darkBrandColor ?? null,
|
||||
theme: team?.theme ?? null,
|
||||
bookerLayouts,
|
||||
},
|
||||
bannerUrl: team?.bannerUrl,
|
||||
entity: entity
|
||||
? {
|
||||
...entity,
|
||||
orgSlug: entity.orgSlug || null,
|
||||
teamSlug: entity.teamSlug || null,
|
||||
fromRedirectOfNonOrgLink: true,
|
||||
name: entity.name || null,
|
||||
logoUrl: entity.logoUrl || undefined,
|
||||
}
|
||||
: {
|
||||
fromRedirectOfNonOrgLink: true,
|
||||
considerUnpublished: false,
|
||||
orgSlug: null,
|
||||
teamSlug: team?.slug,
|
||||
name: team?.name,
|
||||
logoUrl: team?.logoUrl,
|
||||
},
|
||||
hosts: !limitHosts ? hostTransformed : undefined,
|
||||
subsetOfHosts: hostTransformed,
|
||||
users: !limitHosts ? usersTransformed : undefined,
|
||||
subsetOfUsers: usersTransformed,
|
||||
recurringEvent: recurrence ? transformRecurrenceApiToInternal(recurrence) : null,
|
||||
bookingLimits: bookingLimitsCount ? transformIntervalLimitsApiToInternal(bookingLimitsCount) : undefined,
|
||||
durationLimits: bookingLimitsDuration
|
||||
? transformIntervalLimitsApiToInternal(bookingLimitsDuration)
|
||||
: undefined,
|
||||
|
||||
metadata: {
|
||||
...metadata,
|
||||
requiresConfirmationThreshold:
|
||||
confirmationPolicyTransformed?.requiresConfirmationThreshold ?? undefined,
|
||||
multipleDuration: lengthInMinutesOptions,
|
||||
},
|
||||
|
||||
requiresConfirmation: confirmationPolicyTransformed?.requiresConfirmation ?? undefined,
|
||||
requiresConfirmationWillBlockSlot:
|
||||
confirmationPolicyTransformed?.requiresConfirmationWillBlockSlot ?? undefined,
|
||||
|
||||
eventTypeColor: transformEventColorsApiToInternal(color),
|
||||
...transformSeatsApiToInternal(seats),
|
||||
eventName: customName,
|
||||
useEventTypeDestinationCalendarEmail: useDestinationCalendarEmail,
|
||||
...getBookingWindow(bookingWindow),
|
||||
};
|
||||
}
|
||||
|
||||
function isDefaultEvent(eventSlug: string) {
|
||||
const foundInDefaults = defaultEvents.find((obj) => {
|
||||
return obj.slug === eventSlug;
|
||||
});
|
||||
return !!foundInDefaults;
|
||||
}
|
||||
|
||||
function getLocations(locations: EventTypeOutput_2024_06_14["locations"]) {
|
||||
const transformed = transformTeamLocationsApiToInternal(
|
||||
locations.filter((location) => isAtomSupportedLocation(location))
|
||||
);
|
||||
|
||||
const withPrivateHidden = transformed.map((location) => {
|
||||
const { type } = location;
|
||||
|
||||
switch (type) {
|
||||
case "inPerson":
|
||||
return location?.displayLocationPublicly ? location : { ...location, address: "" };
|
||||
case "link":
|
||||
return location?.displayLocationPublicly ? location : { ...location, link: "" };
|
||||
case "userPhone":
|
||||
return location?.displayLocationPublicly
|
||||
? location
|
||||
: {
|
||||
...location,
|
||||
hostPhoneNumber: "",
|
||||
};
|
||||
default:
|
||||
return location;
|
||||
}
|
||||
});
|
||||
|
||||
return withPrivateHidden;
|
||||
}
|
||||
|
||||
function isAtomSupportedLocation(
|
||||
location: EventTypeOutput_2024_06_14["locations"][number]
|
||||
): location is InputLocation_2024_06_14 {
|
||||
const supportedIntegrations = ["cal-video", "google-meet", "office365-video", "zoom"];
|
||||
|
||||
return (
|
||||
location.type === "address" ||
|
||||
location.type === "attendeeAddress" ||
|
||||
location.type === "link" ||
|
||||
location.type === "phone" ||
|
||||
location.type === "attendeePhone" ||
|
||||
location.type === "attendeeDefined" ||
|
||||
location.type === "organizersDefaultApp" ||
|
||||
(location.type === "integration" && supportedIntegrations.includes(location.integration))
|
||||
);
|
||||
}
|
||||
|
||||
function getBookingFields(
|
||||
bookingFields: EventTypeOutput_2024_06_14["bookingFields"],
|
||||
defaultFormValues: BookerPlatformWrapperAtomProps["defaultFormValues"] | undefined
|
||||
) {
|
||||
const transformedBookingFields = transformBookingFieldsApiToInternal(
|
||||
bookingFields.filter((field) => isKnownField(field))
|
||||
);
|
||||
|
||||
const hasNameField = transformedBookingFields.some((field) => field.name === "name");
|
||||
const hasEmailField = transformedBookingFields.some((field) => field.name === "email");
|
||||
const hasLocationField = transformedBookingFields.some((field) => field.name === "location");
|
||||
const hasRescheduleReasonField = transformedBookingFields.some(
|
||||
(field) => field.name === "rescheduleReason"
|
||||
);
|
||||
|
||||
const systemBeforeFields: SystemField[] = [];
|
||||
if (!hasNameField) {
|
||||
systemBeforeFields.push(systemBeforeFieldName);
|
||||
}
|
||||
if (!hasEmailField) {
|
||||
systemBeforeFields.push(systemBeforeFieldEmail);
|
||||
}
|
||||
if (!hasLocationField) {
|
||||
systemBeforeFields.push(systemBeforeFieldLocation);
|
||||
}
|
||||
const systemAfterFields: SystemField[] = [];
|
||||
if (!hasRescheduleReasonField) {
|
||||
systemAfterFields.push(systemAfterFieldRescheduleReason);
|
||||
}
|
||||
|
||||
const fieldsWithSystem = [...systemBeforeFields, ...transformedBookingFields, ...systemAfterFields];
|
||||
|
||||
// note(Lauris): in web app booking form values can be passed as url query params, but booker atom does not accept booking field values via url,
|
||||
// so defaultFormValues act as a way to prefill booking form fields, and if the field in database has disableOnPrefill=true and value passed then its read only.
|
||||
const defaultFormValuesKeys = defaultFormValues ? Object.keys(defaultFormValues) : [];
|
||||
if (defaultFormValuesKeys.length) {
|
||||
for (const field of fieldsWithSystem) {
|
||||
if (defaultFormValuesKeys.includes(field.name) && field.disableOnPrefill) {
|
||||
field.editable = "user-readonly";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return eventTypeBookingFields.brand<"HAS_SYSTEM_FIELDS">().parse(fieldsWithSystem);
|
||||
}
|
||||
|
||||
function isKnownField(
|
||||
field: EventTypeOutput_2024_06_14["bookingFields"][number]
|
||||
): field is KnownBookingField_2024_06_14 {
|
||||
return field.type !== "unknown";
|
||||
}
|
||||
|
||||
function getBookingWindow(inputBookingWindow: EventTypeOutput_2024_06_14["bookingWindow"]) {
|
||||
const res = transformFutureBookingLimitsApiToInternal(inputBookingWindow);
|
||||
return !!res ? res : {};
|
||||
}
|
||||
|
||||
function isDefaultEditableField(
|
||||
field: EventTypeOutput_2024_06_14["bookingFields"][number]
|
||||
): field is NameDefaultFieldOutput_2024_06_14 | EmailDefaultFieldOutput_2024_06_14 {
|
||||
return field.type === "name" || field.type === "email";
|
||||
}
|
||||
+2
-6
@@ -6,8 +6,7 @@ import type { EventTypeSetup, FormValues } from "@calcom/features/eventtypes/lib
|
||||
import type { User } from "@calcom/prisma/client";
|
||||
|
||||
import type { Availability } from "../../availability/AvailabilitySettings";
|
||||
import { transformApiScheduleForAtom } from "../../availability/atom-api-transformers/transformApiScheduleForAtom";
|
||||
import { useSchedule } from "../../hooks/schedules/useSchedule";
|
||||
import { useAtomSchedule } from "../../hooks/schedules/useAtomSchedule";
|
||||
import { useSchedules } from "../../hooks/schedules/useSchedules";
|
||||
import { useTeamMembers } from "../../hooks/teams/useTeamMembers";
|
||||
import { useAtomHostSchedules } from "../hooks/useAtomHostSchedules";
|
||||
@@ -28,13 +27,10 @@ const EventAvailabilityTabPlatformWrapper = ({
|
||||
const formMethods = useFormContext<FormValues>();
|
||||
const scheduleId = formMethods.watch("schedule");
|
||||
|
||||
const { isLoading: isSchedulePending, data: scheduleQueryData } = useSchedule(
|
||||
scheduleId || user?.defaultScheduleId || undefined
|
||||
);
|
||||
const { isLoading: isSchedulePending, data: atomSchedule } = useAtomSchedule(scheduleId?.toString());
|
||||
|
||||
const { data: schedulesQueryData, isLoading: isSchedulesPending } = useSchedules();
|
||||
|
||||
const atomSchedule = transformApiScheduleForAtom(user, scheduleQueryData, schedulesQueryData?.length || 0);
|
||||
const hostSchedulesQuery = useAtomHostSchedules;
|
||||
const { data: teamMembers } = useTeamMembers({ teamId });
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useMutation } from "@tanstack/react-query";
|
||||
|
||||
import type { BookingResponse } from "@calcom/features/bookings/types";
|
||||
import { SUCCESS_STATUS } from "@calcom/platform-constants";
|
||||
import type { BookingResponse } from "@calcom/platform-libraries";
|
||||
import type { ApiResponse, ApiErrorResponse, ApiSuccessResponse } from "@calcom/platform-types";
|
||||
import type { BookingCreateBody } from "@calcom/prisma/zod/custom/booking";
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useMutation } from "@tanstack/react-query";
|
||||
|
||||
import type { BookingResponse } from "@calcom/features/bookings/types";
|
||||
import { SUCCESS_STATUS } from "@calcom/platform-constants";
|
||||
import type { BookingResponse } from "@calcom/platform-libraries";
|
||||
import type { ApiResponse, ApiErrorResponse, ApiSuccessResponse } from "@calcom/platform-types";
|
||||
import type { BookingCreateBody } from "@calcom/prisma/zod/custom/booking";
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useMutation } from "@tanstack/react-query";
|
||||
|
||||
import type { BookingResponse, RecurringBookingCreateBody } from "@calcom/features/bookings/types";
|
||||
import { SUCCESS_STATUS } from "@calcom/platform-constants";
|
||||
import type { BookingResponse, RecurringBookingCreateBody } from "@calcom/platform-libraries";
|
||||
import type { ApiResponse, ApiErrorResponse, ApiSuccessResponse } from "@calcom/platform-types";
|
||||
|
||||
import http from "../../lib/http";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
|
||||
import type { getBookingForReschedule } from "@calcom/features/bookings/lib/get-booking";
|
||||
import { V2_ENDPOINTS, SUCCESS_STATUS } from "@calcom/platform-constants";
|
||||
import type { getBookingForReschedule } from "@calcom/platform-libraries";
|
||||
import type { ApiResponse, ApiSuccessResponse } from "@calcom/platform-types";
|
||||
|
||||
import http from "../../lib/http";
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { useMemo } from "react";
|
||||
|
||||
import { getUsernameList } from "@calcom/lib/defaultEvents";
|
||||
import { SUCCESS_STATUS, V2_ENDPOINTS } from "@calcom/platform-constants";
|
||||
import type { PublicEventType } from "@calcom/features/eventtypes/lib/getPublicEvent";
|
||||
import type { ApiResponse } from "@calcom/platform-types";
|
||||
|
||||
import http from "../../../lib/http";
|
||||
import { useAtomsContext } from "../../../hooks/useAtomsContext";
|
||||
|
||||
export const QUERY_KEY = "get-public-event";
|
||||
export type UsePublicEventReturnType = ReturnType<typeof useAtomGetPublicEvent>;
|
||||
|
||||
type Props = {
|
||||
username: string;
|
||||
eventSlug: string;
|
||||
isTeamEvent?: boolean;
|
||||
teamId?: number;
|
||||
selectedDuration: number | null;
|
||||
};
|
||||
|
||||
export const useAtomGetPublicEvent = ({ username, eventSlug, isTeamEvent, teamId, selectedDuration }: Props) => {
|
||||
|
||||
const { organizationId } = useAtomsContext();
|
||||
|
||||
const isDynamic = useMemo(() => {
|
||||
return getUsernameList(username ?? "").length > 1;
|
||||
}, [username]);
|
||||
|
||||
const pathname = `/atoms/${V2_ENDPOINTS.eventTypes}/${eventSlug}/public`;
|
||||
|
||||
const event = useQuery({
|
||||
queryKey: [QUERY_KEY, username, eventSlug, isTeamEvent, teamId, organizationId],
|
||||
queryFn: () => {
|
||||
return http?.get<ApiResponse<PublicEventType>>(pathname, {
|
||||
params: {
|
||||
isTeamEvent,
|
||||
teamId,
|
||||
orgId: organizationId,
|
||||
username: getUsernameList(username?? "").join(",")
|
||||
},
|
||||
})
|
||||
.then((res) => {
|
||||
if (res.data.status === SUCCESS_STATUS) {
|
||||
if (isDynamic && selectedDuration && res.data.data) {
|
||||
// note(Lauris): Mandatory - In case of "dynamic" event type default event duration returned by the API is 30,
|
||||
// but we are re-using the dynamic event type as a team event, so we must set the event length to whatever the event length is.
|
||||
res.data.data.length = selectedDuration;
|
||||
}
|
||||
return res.data.data;
|
||||
}
|
||||
throw new Error(res.data.error.message);
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
return event;
|
||||
};
|
||||
@@ -0,0 +1,31 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
|
||||
import type { FindDetailedScheduleByIdReturnType } from "@calcom/lib/server/repository/schedule";
|
||||
import { SUCCESS_STATUS } from "@calcom/platform-constants";
|
||||
import type { ApiResponse } from "@calcom/platform-types";
|
||||
|
||||
import http from "../../lib/http";
|
||||
|
||||
export const QUERY_KEY = "use-atom-schedule";
|
||||
|
||||
export const useAtomSchedule = (scheduleId?: string, isManagedEventType?: boolean) => {
|
||||
const pathname = "atoms/schedules";
|
||||
|
||||
const { isLoading, error, data } = useQuery({
|
||||
queryKey: [QUERY_KEY, scheduleId, isManagedEventType],
|
||||
queryFn: () => {
|
||||
return http
|
||||
.get<ApiResponse<FindDetailedScheduleByIdReturnType | null>>(pathname, {
|
||||
params: { scheduleId, isManagedEventType },
|
||||
})
|
||||
.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,49 @@
|
||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
|
||||
import type { UpdateScheduleResponse } from "@calcom/lib/schedules/updateSchedule";
|
||||
import { SUCCESS_STATUS } from "@calcom/platform-constants";
|
||||
import type { ApiResponse, ApiErrorResponse, UpdateAtomScheduleDto } from "@calcom/platform-types";
|
||||
|
||||
import http from "../../lib/http";
|
||||
import { QUERY_KEY as ScheduleQueryKey } from "./useAtomSchedule";
|
||||
|
||||
interface IUseAtomUpdateScheduleOptions {
|
||||
onSuccess?: (res: ApiResponse<UpdateScheduleResponse>) => void;
|
||||
onError?: (err: ApiErrorResponse) => void;
|
||||
}
|
||||
|
||||
export const useAtomUpdateSchedule = (
|
||||
{ onSuccess, onError }: IUseAtomUpdateScheduleOptions = {
|
||||
onSuccess: () => {
|
||||
return;
|
||||
},
|
||||
onError: () => {
|
||||
return;
|
||||
},
|
||||
}
|
||||
) => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation<
|
||||
ApiResponse<UpdateScheduleResponse>,
|
||||
unknown,
|
||||
{ scheduleId: number; body: UpdateAtomScheduleDto }
|
||||
>({
|
||||
mutationFn: async ({ scheduleId, body }: { scheduleId: number; body: UpdateAtomScheduleDto }) => {
|
||||
const url = `atoms/schedules/${scheduleId}`;
|
||||
const response = await http.patch<ApiResponse<UpdateScheduleResponse>>(url, body);
|
||||
return response.data;
|
||||
},
|
||||
onSuccess: (data) => {
|
||||
if (data.status === SUCCESS_STATUS) {
|
||||
onSuccess?.(data);
|
||||
queryClient.invalidateQueries({ queryKey: [ScheduleQueryKey] });
|
||||
} else {
|
||||
onError?.(data);
|
||||
}
|
||||
},
|
||||
onError: (err) => {
|
||||
onError?.(err as ApiErrorResponse);
|
||||
},
|
||||
});
|
||||
};
|
||||
@@ -5,7 +5,7 @@ import { V2_ENDPOINTS } from "@calcom/platform-constants";
|
||||
import type { ApiResponse, ApiErrorResponse } from "@calcom/platform-types";
|
||||
|
||||
import http from "../../lib/http";
|
||||
import { QUERY_KEY } from "./useSchedule";
|
||||
import { QUERY_KEY } from "./useAtomSchedule";
|
||||
|
||||
interface IUseDeleteScheduleProps {
|
||||
onSuccess?: (res: ApiResponse) => void;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
|
||||
import { SUCCESS_STATUS } from "@calcom/platform-constants";
|
||||
import type { AvailableSlotsType } from "@calcom/platform-libraries";
|
||||
import type {
|
||||
GetAvailableSlotsInput_2024_04_15,
|
||||
ApiResponse,
|
||||
ApiSuccessResponse,
|
||||
} from "@calcom/platform-types";
|
||||
import type { GetAvailableSlotsResponse } from "@calcom/trpc/server/routers/viewer/slots/util";
|
||||
|
||||
import http from "../lib/http";
|
||||
|
||||
@@ -33,12 +33,12 @@ export const useAvailableSlots = ({
|
||||
],
|
||||
queryFn: () => {
|
||||
return http
|
||||
.get<ApiResponse<AvailableSlotsType>>("/slots/available", {
|
||||
.get<ApiResponse<GetAvailableSlotsResponse>>("/slots/available", {
|
||||
params: rest,
|
||||
})
|
||||
.then((res) => {
|
||||
if (res.data.status === SUCCESS_STATUS) {
|
||||
return (res.data as ApiSuccessResponse<AvailableSlotsType>).data;
|
||||
return (res.data as ApiSuccessResponse<GetAvailableSlotsResponse>).data;
|
||||
}
|
||||
throw new Error(res.data.error.message);
|
||||
});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
|
||||
import type { ConnectedDestinationCalendars } from "@calcom/lib/getConnectedDestinationCalendars";
|
||||
import { SUCCESS_STATUS } from "@calcom/platform-constants";
|
||||
import type { ConnectedDestinationCalendars } from "@calcom/platform-libraries";
|
||||
import type { ApiResponse, ApiSuccessResponse } from "@calcom/platform-types";
|
||||
|
||||
import http from "../lib/http";
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { shallow } from "zustand/shallow";
|
||||
|
||||
import { useBookerStore } from "@calcom/features/bookings/Booker/store";
|
||||
import { SUCCESS_STATUS, V2_ENDPOINTS } from "@calcom/platform-constants";
|
||||
import type { PublicEventType } from "@calcom/platform-libraries";
|
||||
import type { ApiResponse } from "@calcom/platform-types";
|
||||
|
||||
import http from "../lib/http";
|
||||
|
||||
export const QUERY_KEY = "get-public-event";
|
||||
export type UsePublicEventReturnType = ReturnType<typeof usePublicEvent>;
|
||||
|
||||
type Props = {
|
||||
username: string;
|
||||
eventSlug: string;
|
||||
isDynamic?: boolean;
|
||||
};
|
||||
|
||||
export const usePublicEvent = (props: Props) => {
|
||||
const [username, eventSlug] = useBookerStore((state) => [state.username, state.eventSlug], shallow);
|
||||
const isTeamEvent = useBookerStore((state) => state.isTeamEvent);
|
||||
const org = useBookerStore((state) => state.org);
|
||||
const selectedDuration = useBookerStore((state) => state.selectedDuration);
|
||||
|
||||
const requestUsername = username ?? props.username;
|
||||
const requestEventSlug = eventSlug ?? props.eventSlug;
|
||||
|
||||
const event = useQuery({
|
||||
queryKey: [QUERY_KEY, username ?? props.username, eventSlug ?? props.eventSlug, props.isDynamic],
|
||||
queryFn: () => {
|
||||
return http
|
||||
.get<ApiResponse<PublicEventType>>(
|
||||
`/${V2_ENDPOINTS.eventTypes}/${requestUsername}/${requestEventSlug}/public`,
|
||||
{
|
||||
params: {
|
||||
isTeamEvent,
|
||||
org: org ?? null,
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((res) => {
|
||||
if (res.data.status === SUCCESS_STATUS) {
|
||||
if (props.isDynamic && selectedDuration && res.data.data) {
|
||||
// note(Lauris): Mandatory - In case of "dynamic" event type default event duration returned by the API is 30,
|
||||
// but we are re-using the dynamic event type as a team event, so we must set the event length to whatever the event length is.
|
||||
res.data.data.length = selectedDuration;
|
||||
}
|
||||
|
||||
return res.data.data;
|
||||
}
|
||||
throw new Error(res.data.error.message);
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
return event;
|
||||
};
|
||||
@@ -12,7 +12,6 @@
|
||||
"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",
|
||||
|
||||
@@ -128,7 +128,10 @@ export default function Bookings(props: { calUsername: string; calEmail: string
|
||||
},
|
||||
}}
|
||||
{...(isTeamEvent
|
||||
? { isTeamEvent: true, teamId: teams?.[0]?.id || 0 }
|
||||
? {
|
||||
isTeamEvent: true,
|
||||
teamId: teams?.[0]?.id || 0,
|
||||
}
|
||||
: { username: props.calUsername })}
|
||||
hostsLimit={3}
|
||||
allowUpdatingUrlParams={true}
|
||||
|
||||
@@ -15,7 +15,7 @@ export default function ConferencingApps(props: { calUsername: string; calEmail:
|
||||
className={`flex min-h-screen flex-col ${inter.className} main text-default flex min-h-full w-full flex-col items-center overflow-visible`}>
|
||||
<Navbar username={props.calUsername} />
|
||||
<div className="my-8">
|
||||
<ConferencingAppsSettings returnTo={callbackUri} onErrorReturnTo={callbackUri} teamId={20} />
|
||||
<ConferencingAppsSettings returnTo={callbackUri} onErrorReturnTo={callbackUri} />
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
|
||||
@@ -22,6 +22,8 @@ export { getEnabledAppsFromCredentials };
|
||||
|
||||
export { getConnectedApps } from "@calcom/lib/getConnectedApps";
|
||||
|
||||
export type { TServiceAccountKeySchema } from "@calcom/prisma/zod-utils";
|
||||
|
||||
export type { ConnectedApps } from "@calcom/lib/getConnectedApps";
|
||||
|
||||
export type { AppsStatus } from "@calcom/types/Calendar";
|
||||
@@ -40,3 +42,5 @@ export {
|
||||
CalendarAppDelegationCredentialClientIdNotAuthorizedError,
|
||||
CalendarAppDelegationCredentialNotSetupError,
|
||||
} from "@calcom/lib/CalendarAppError";
|
||||
|
||||
export { getUsersCredentialsIncludeServiceAccountKey } from "@calcom/lib/server/getUsersCredentials";
|
||||
@@ -1,4 +1,4 @@
|
||||
import { getPublicEvent } from "@calcom/features/eventtypes/lib/getPublicEvent";
|
||||
export { getPublicEvent, type PublicEventType } from "@calcom/features/eventtypes/lib/getPublicEvent";
|
||||
|
||||
export { getBulkUserEventTypes, getBulkTeamEventTypes } from "@calcom/lib/event-types/getBulkEventTypes";
|
||||
|
||||
@@ -9,51 +9,6 @@ export type { TUpdateInputSchema as TUpdateEventTypeInputSchema } from "@calcom/
|
||||
export type { EventTypesPublic } from "@calcom/lib/event-types/getEventTypesPublic";
|
||||
export { getEventTypesPublic } from "@calcom/lib/event-types/getEventTypesPublic";
|
||||
export { parseEventTypeColor } from "@calcom/lib/isEventTypeColor";
|
||||
export {
|
||||
// note(Lauris): Api to internal
|
||||
transformBookingFieldsApiToInternal,
|
||||
transformLocationsApiToInternal,
|
||||
transformTeamLocationsApiToInternal,
|
||||
transformIntervalLimitsApiToInternal,
|
||||
transformFutureBookingLimitsApiToInternal,
|
||||
transformRecurrenceApiToInternal,
|
||||
transformBookerLayoutsApiToInternal,
|
||||
transformConfirmationPolicyApiToInternal,
|
||||
transformEventColorsApiToInternal,
|
||||
transformSeatsApiToInternal,
|
||||
// note(Lauris): Internal to api
|
||||
transformBookingFieldsInternalToApi,
|
||||
transformLocationsInternalToApi,
|
||||
transformIntervalLimitsInternalToApi,
|
||||
transformFutureBookingLimitsInternalToApi,
|
||||
transformRecurrenceInternalToApi,
|
||||
transformBookerLayoutsInternalToApi,
|
||||
transformRequiresConfirmationInternalToApi,
|
||||
transformEventTypeColorsInternalToApi,
|
||||
transformSeatsInternalToApi,
|
||||
// note(Lauris): schemas
|
||||
InternalLocationsSchema,
|
||||
InternalLocationSchema,
|
||||
BookingFieldsSchema,
|
||||
BookingFieldSchema,
|
||||
// note(Lauris): constants
|
||||
systemBeforeFieldName,
|
||||
systemBeforeFieldEmail,
|
||||
systemBeforeFieldLocation,
|
||||
systemAfterFieldRescheduleReason,
|
||||
systemAfterFieldTitle,
|
||||
systemAfterFieldNotes,
|
||||
systemAfterFieldGuests,
|
||||
apiToInternalintegrationsMapping,
|
||||
} from "@calcom/lib/event-types/transformers";
|
||||
|
||||
export type {
|
||||
SystemField,
|
||||
CustomField,
|
||||
NameSystemField,
|
||||
EmailSystemField,
|
||||
InternalLocation,
|
||||
} from "@calcom/lib/event-types/transformers";
|
||||
|
||||
export {
|
||||
EventTypeMetaDataSchema,
|
||||
@@ -70,7 +25,5 @@ export type { EventTypesByViewer } from "@calcom/lib/event-types/getEventTypesBy
|
||||
export type { UpdateEventTypeReturn } from "@calcom/trpc/server/routers/viewer/eventTypes/update.handler";
|
||||
export { updateNewTeamMemberEventTypes } from "@calcom/lib/server/queries/teams";
|
||||
|
||||
export type PublicEventType = Awaited<ReturnType<typeof getPublicEvent>>;
|
||||
export { bulkUpdateEventsToDefaultLocation } from "@calcom/lib/bulkUpdateEventsToDefaultLocation";
|
||||
export { bulkUpdateTeamEventsToDefaultLocation } from "@calcom/lib/bulkUpdateTeamEventsToDefaultLocation";
|
||||
export { getPublicEvent };
|
||||
@@ -22,11 +22,11 @@ import { credentialForCalendarServiceSelect } from "@calcom/prisma/selects/crede
|
||||
import { paymentDataSelect } from "@calcom/prisma/selects/payment";
|
||||
import { createNewUsersConnectToOrgIfExists } from "@calcom/trpc/server/routers/viewer/teams/inviteMember/utils";
|
||||
|
||||
export { getUsersCredentials } from "@calcom/lib/server/getUsersCredentials";
|
||||
|
||||
export { slugify } from "@calcom/lib/slugify";
|
||||
export { getBookingForReschedule };
|
||||
|
||||
export type { EventBusyDate } from "@calcom/types/Calendar";
|
||||
|
||||
export { SchedulingType, PeriodType } from "@calcom/prisma/enums";
|
||||
|
||||
export { getUsernameList } from "@calcom/lib/defaultEvents";
|
||||
@@ -42,15 +42,10 @@ export { handleCreatePhoneCall };
|
||||
export { handleNewRecurringBooking } from "@calcom/features/bookings/lib/handleNewRecurringBooking";
|
||||
|
||||
export { getConnectedDestinationCalendarsAndEnsureDefaultsInDb } from "@calcom/lib/getConnectedDestinationCalendars";
|
||||
export type { ConnectedDestinationCalendars } from "@calcom/lib/getConnectedDestinationCalendars";
|
||||
|
||||
export { getBusyCalendarTimes } from "@calcom/lib/CalendarManager";
|
||||
|
||||
export type {
|
||||
BookingCreateBody,
|
||||
BookingResponse,
|
||||
RecurringBookingCreateBody,
|
||||
} from "@calcom/features/bookings/types";
|
||||
export type { BookingCreateBody, BookingResponse } from "@calcom/features/bookings/types";
|
||||
export { HttpError } from "@calcom/lib/http-error";
|
||||
|
||||
export { MINUTES_TO_BOOK } from "@calcom/lib/constants";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {
|
||||
transformApiScheduleOverrides,
|
||||
transformApiScheduleAvailability,
|
||||
} from "@calcom/lib/schedules/transformers/from-api";
|
||||
export {
|
||||
ScheduleRepository,
|
||||
type FindDetailedScheduleByIdReturnType,
|
||||
} from "@calcom/lib/server/repository/schedule";
|
||||
|
||||
export { transformApiScheduleOverrides, transformApiScheduleAvailability };
|
||||
export { updateSchedule, type UpdateScheduleResponse } from "@calcom/lib/schedules/updateSchedule";
|
||||
@@ -1,4 +1,3 @@
|
||||
import { getAvailableSlots } from "@calcom/trpc/server/routers/viewer/slots/util";
|
||||
|
||||
export { getAvailableSlots };
|
||||
export type AvailableSlotsType = Awaited<ReturnType<typeof getAvailableSlots>>;
|
||||
@@ -1,3 +1,2 @@
|
||||
export * from "./inputs";
|
||||
export * from "./outputs";
|
||||
export * from "./transformed";
|
||||
-59
@@ -1,59 +0,0 @@
|
||||
import type { z } from "zod";
|
||||
|
||||
import type {
|
||||
transformEventColorsApiToInternal,
|
||||
transformFutureBookingLimitsApiToInternal,
|
||||
transformIntervalLimitsApiToInternal,
|
||||
transformRecurrenceApiToInternal,
|
||||
transformSeatsApiToInternal,
|
||||
transformBookingFieldsApiToInternal,
|
||||
InternalLocationsSchema,
|
||||
} from "@calcom/lib/event-types/transformers";
|
||||
|
||||
import type { CreateEventTypeInput_2024_06_14, ConfirmationPolicyTransformedSchema } from "../inputs";
|
||||
|
||||
export type InputEventTransformed_2024_06_14 = Omit<
|
||||
CreateEventTypeInput_2024_06_14,
|
||||
| "lengthInMinutes"
|
||||
| "locations"
|
||||
| "bookingFields"
|
||||
| "bookingLimitsCount"
|
||||
| "bookingLimitsDuration"
|
||||
| "bookingWindow"
|
||||
| "bookerLayouts"
|
||||
| "confirmationPolicy"
|
||||
| "recurrence"
|
||||
| "color"
|
||||
| "seats"
|
||||
| "customName"
|
||||
| "useDestinationCalendarEmail"
|
||||
> & {
|
||||
length: number;
|
||||
slug: string;
|
||||
eventName?: string;
|
||||
bookingLimits?: ReturnType<typeof transformIntervalLimitsApiToInternal>;
|
||||
locations?: z.infer<typeof InternalLocationsSchema>;
|
||||
bookingFields?: ReturnType<typeof transformBookingFieldsApiToInternal>;
|
||||
durationLimits?: ReturnType<typeof transformIntervalLimitsApiToInternal>;
|
||||
recurringEvent?: ReturnType<typeof transformRecurrenceApiToInternal>;
|
||||
eventTypeColor?: ReturnType<typeof transformEventColorsApiToInternal>;
|
||||
useEventTypeDestinationCalendarEmail?: boolean;
|
||||
} & Partial<
|
||||
Pick<ConfirmationPolicyTransformedSchema, "requiresConfirmation" | "requiresConfirmationWillBlockSlot">
|
||||
> &
|
||||
Partial<ReturnType<typeof transformSeatsApiToInternal>> &
|
||||
Partial<ReturnType<typeof transformFutureBookingLimitsApiToInternal>>;
|
||||
|
||||
export type InputTeamEventTransformed_2024_06_14 = InputEventTransformed_2024_06_14 & {
|
||||
hosts: {
|
||||
userId: number;
|
||||
isFixed: boolean;
|
||||
priority: number;
|
||||
}[];
|
||||
children: {
|
||||
id: number;
|
||||
name: string;
|
||||
email: string;
|
||||
eventTypeSlugs: string[];
|
||||
}[];
|
||||
};
|
||||
@@ -1 +0,0 @@
|
||||
export * from "./event-type.tranformed";
|
||||
@@ -1,2 +1,3 @@
|
||||
export * from "./schedules-2024-06-11";
|
||||
export * from "./schedules-2024-04-15";
|
||||
export * from "./update-atom-schedule-body.input";
|
||||
@@ -0,0 +1,45 @@
|
||||
import { Type } from "class-transformer";
|
||||
import { IsString, IsOptional, IsBoolean, ValidateNested, IsArray, IsDate } from "class-validator";
|
||||
|
||||
export class ScheduleTimeRangeDto {
|
||||
@Type(() => Date)
|
||||
@IsDate()
|
||||
start!: Date;
|
||||
|
||||
@Type(() => Date)
|
||||
@IsDate()
|
||||
end!: Date;
|
||||
}
|
||||
|
||||
export class ScheduleDto {
|
||||
@IsArray()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => ScheduleTimeRangeDto)
|
||||
times!: ScheduleTimeRangeDto[];
|
||||
}
|
||||
|
||||
export class UpdateAtomScheduleDto {
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
timeZone?: string;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
name?: string;
|
||||
|
||||
@IsBoolean()
|
||||
@IsOptional()
|
||||
isDefault?: boolean;
|
||||
|
||||
@IsArray()
|
||||
@IsOptional()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => ScheduleTimeRangeDto)
|
||||
schedule?: ScheduleTimeRangeDto[][];
|
||||
|
||||
@IsArray()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => ScheduleTimeRangeDto)
|
||||
@IsOptional()
|
||||
dateOverrides?: ScheduleTimeRangeDto[];
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import type { TCreateInputSchema } from "./create.schema";
|
||||
|
||||
type CreateHandlerOptions = {
|
||||
ctx: {
|
||||
user: NonNullable<TrpcSessionUser>;
|
||||
user: Pick<NonNullable<TrpcSessionUser>, "id">;
|
||||
};
|
||||
input: TCreateInputSchema;
|
||||
};
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
import { getAvailabilityFromSchedule } from "@calcom/lib/availability";
|
||||
import { hasEditPermissionForUserID } from "@calcom/lib/hasEditPermissionForUser";
|
||||
import { transformScheduleToAvailabilityForAtom } from "@calcom/lib/schedules/transformers/for-atom";
|
||||
import { updateSchedule } from "@calcom/lib/schedules/updateSchedule";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import type { TrpcSessionUser } from "@calcom/trpc/server/types";
|
||||
|
||||
import { TRPCError } from "@trpc/server";
|
||||
|
||||
import type { TrpcSessionUser } from "../../../../types";
|
||||
import { setupDefaultSchedule, updateHostsWithNewDefaultSchedule } from "../util";
|
||||
import type { TUpdateInputSchema } from "./update.schema";
|
||||
|
||||
type User = NonNullable<TrpcSessionUser>;
|
||||
@@ -19,119 +14,9 @@ type UpdateOptions = {
|
||||
|
||||
export const updateHandler = async ({ input, ctx }: UpdateOptions) => {
|
||||
const { user } = ctx;
|
||||
const availability = input.schedule
|
||||
? getAvailabilityFromSchedule(input.schedule)
|
||||
: (input.dateOverrides || []).map((dateOverride) => ({
|
||||
startTime: dateOverride.start,
|
||||
endTime: dateOverride.end,
|
||||
date: dateOverride.start,
|
||||
days: [],
|
||||
}));
|
||||
|
||||
// Not able to update the schedule with userId where clause, so fetch schedule separately and then validate
|
||||
// Bug: https://github.com/prisma/prisma/issues/7290
|
||||
const userSchedule = await prisma.schedule.findUnique({
|
||||
where: {
|
||||
id: input.scheduleId,
|
||||
},
|
||||
select: {
|
||||
userId: true,
|
||||
name: true,
|
||||
id: true,
|
||||
},
|
||||
return updateSchedule({
|
||||
input,
|
||||
user,
|
||||
prisma,
|
||||
});
|
||||
|
||||
if (!userSchedule) {
|
||||
throw new TRPCError({
|
||||
code: "UNAUTHORIZED",
|
||||
});
|
||||
}
|
||||
|
||||
if (userSchedule?.userId !== user.id) {
|
||||
const hasEditPermission = await hasEditPermissionForUserID({
|
||||
ctx,
|
||||
input: { memberId: userSchedule.userId },
|
||||
});
|
||||
if (!hasEditPermission) {
|
||||
throw new TRPCError({
|
||||
code: "UNAUTHORIZED",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
let updatedUser;
|
||||
if (input.isDefault) {
|
||||
if (user?.defaultScheduleId) {
|
||||
await updateHostsWithNewDefaultSchedule(user.id, user.defaultScheduleId, input.scheduleId);
|
||||
}
|
||||
|
||||
const setupDefault = await setupDefaultSchedule(user.id, input.scheduleId, prisma);
|
||||
updatedUser = setupDefault;
|
||||
}
|
||||
|
||||
if (!input.name) {
|
||||
// TODO: Improve
|
||||
// We don't want to pass the full schedule for just a set as default update
|
||||
// but in the current logic, this wipes the existing availability.
|
||||
// Return early to prevent this from happening.
|
||||
return {
|
||||
schedule: userSchedule,
|
||||
isDefault: updatedUser
|
||||
? updatedUser.defaultScheduleId === input.scheduleId
|
||||
: user.defaultScheduleId === input.scheduleId,
|
||||
};
|
||||
}
|
||||
|
||||
const schedule = await prisma.schedule.update({
|
||||
where: {
|
||||
id: input.scheduleId,
|
||||
},
|
||||
data: {
|
||||
timeZone: input.timeZone,
|
||||
name: input.name,
|
||||
availability: {
|
||||
deleteMany: {
|
||||
scheduleId: {
|
||||
equals: input.scheduleId,
|
||||
},
|
||||
},
|
||||
createMany: {
|
||||
data: [
|
||||
...availability,
|
||||
...(input.dateOverrides || []).map((override) => ({
|
||||
date: override.start,
|
||||
startTime: override.start,
|
||||
endTime: override.end,
|
||||
})),
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
userId: true,
|
||||
name: true,
|
||||
availability: true,
|
||||
timeZone: true,
|
||||
eventType: {
|
||||
select: {
|
||||
id: true,
|
||||
eventName: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const userAvailability = transformScheduleToAvailabilityForAtom(schedule);
|
||||
|
||||
return {
|
||||
schedule,
|
||||
availability: userAvailability,
|
||||
timeZone: schedule.timeZone || user.timeZone,
|
||||
isDefault: updatedUser
|
||||
? updatedUser.defaultScheduleId === schedule.id
|
||||
: user.defaultScheduleId === schedule.id,
|
||||
prevDefaultId: user.defaultScheduleId,
|
||||
currentDefaultId: updatedUser ? updatedUser.defaultScheduleId : user.defaultScheduleId,
|
||||
};
|
||||
};
|
||||
@@ -36,7 +36,7 @@ import type { TConfirmInputSchema } from "./confirm.schema";
|
||||
|
||||
type ConfirmOptions = {
|
||||
ctx: {
|
||||
user: NonNullable<TrpcSessionUser>;
|
||||
user: Pick<NonNullable<TrpcSessionUser>, "id" | "email" | "username" | "role" | "destinationCalendar">;
|
||||
};
|
||||
input: TConfirmInputSchema;
|
||||
};
|
||||
|
||||
@@ -302,6 +302,7 @@ const getStartTime = (startTimeInput: string, timeZone?: string, minimumBookingN
|
||||
return startTimeMin.isAfter(startTime) ? startTimeMin.tz(timeZone) : startTime;
|
||||
};
|
||||
|
||||
export type GetAvailableSlotsResponse = Awaited<ReturnType<typeof _getAvailableSlots>>;
|
||||
const _getAvailableSlots = async ({ input, ctx }: GetScheduleOptions): Promise<IGetAvailableSlots> => {
|
||||
const {
|
||||
_enableTroubleshooter: enableTroubleshooter = false,
|
||||
|
||||
Reference in new issue
Block a user