refactor: v2 event-types (#15457)
* refactor: UserAvatarGroupWithOrg.tsx remove unecessary profile prop * chore: define event-type types in platform/types * feat: event-type transformes in lib and re-exported through platform-libraries * chore: define user types in platform/types * chore: add users endpoint to platform-constants * refactor: app-store use narrowed down booker event type * chore: version old event-types module * fix: old event-types e2e test * fix: libraries add missing export * fix: reset libraries version to 0 * feat: new event-types module and users endpoints * feat: make booker atom work with v2 event-types * updating event type * refactor: remove guard for get event-types * refactor: move private hook to public * Revert "refactor: remove guard for get event-types" This reverts commit d41204069f1d5bb1305b388ce53399f9175f4249. * Revert "refactor: move private hook to public" This reverts commit 09322e8fba102e57104959f79ed6bfa9a677dc9d. * refactor: get by username and slug in /event-types * remove console log * feat: locations handle displayEventPublicly * test e2e event-types * revert: user output from types * refactor: event-types hooks have private and public folders * refactor: require event-type.slug in input * refactor: demand that all labels of booking fields are unique * refactor: remove unused import * refactor: only have email and name by default in booker * refactor: add booking field slug * fix: display event-type location publicly / hide it in booker * fix: display event-type location publicly / hide it in booker * fix: packages/lib tests * fix: typescript in e2e test * fix: dynamic event types input * refactor: use IsIn instead of IsEnum * refactor: simplify getEventTypes * fix: use ApiAuthGuard instead of AccessTokenGuard * chore: export more stuff from libraries * refactor: SchedulingTypeEnum and Type --------- Co-authored-by: Morgan <[email protected]>
This commit is contained in:
1 parent
c7a96e1b43
commit
0072aba55d
122 files changed
+4738
-523
No files matched your search
@@ -22,6 +22,8 @@ import type {
|
||||
} from "@calcom/platform-types";
|
||||
import { BookerLayouts } from "@calcom/prisma/zod-utils";
|
||||
|
||||
import { transformApiEventTypeForAtom } from "../event-types/atom-api-transformers/transformApiEventTypeForAtom";
|
||||
import { useEventType } from "../hooks/event-types/public/useEventType";
|
||||
import { useAtomsContext } from "../hooks/useAtomsContext";
|
||||
import { useAvailableSlots } from "../hooks/useAvailableSlots";
|
||||
import { useCalendarsBusyTimes } from "../hooks/useCalendarsBusyTimes";
|
||||
@@ -36,7 +38,6 @@ import {
|
||||
} from "../hooks/useGetBookingForReschedule";
|
||||
import { useHandleBookEvent } from "../hooks/useHandleBookEvent";
|
||||
import { useMe } from "../hooks/useMe";
|
||||
import { usePublicEvent } from "../hooks/usePublicEvent";
|
||||
import { useSlots } from "../hooks/useSlots";
|
||||
import { AtomsWrapper } from "../src/components/atoms-wrapper";
|
||||
|
||||
@@ -109,6 +110,7 @@ export const BookerPlatformWrapper = (props: BookerPlatformWrapperAtomProps) =>
|
||||
setBookingData(null);
|
||||
}
|
||||
};
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
setSelectedDuration(props.duration ?? null);
|
||||
@@ -118,11 +120,22 @@ export const BookerPlatformWrapper = (props: BookerPlatformWrapperAtomProps) =>
|
||||
return getUsernameList(username ?? "").length > 1;
|
||||
}, [username]);
|
||||
|
||||
const event = usePublicEvent({
|
||||
username,
|
||||
eventSlug: props.eventSlug,
|
||||
isDynamic,
|
||||
});
|
||||
const { isSuccess, isError, isPending, data } = useEventType(username, props.eventSlug);
|
||||
|
||||
const event = useMemo(() => {
|
||||
return {
|
||||
isSuccess,
|
||||
isError,
|
||||
isPending,
|
||||
data: data && data.length > 0 ? transformApiEventTypeForAtom(data[0], props.entity) : undefined,
|
||||
};
|
||||
}, [isSuccess, isError, isPending, data, props.entity]);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
const bookerLayout = useBookerLayout(event.data);
|
||||
useInitializeBookerStore({
|
||||
@@ -322,7 +335,7 @@ export const BookerPlatformWrapper = (props: BookerPlatformWrapperAtomProps) =>
|
||||
onClickOverlayContinue={function (): void {
|
||||
throw new Error("Function not implemented.");
|
||||
}}
|
||||
onOverlaySwitchStateChange={function (state: boolean): void {
|
||||
onOverlaySwitchStateChange={function (): void {
|
||||
throw new Error("Function not implemented.");
|
||||
}}
|
||||
extraOptions={extraOptions ?? {}}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||
import { useEffect, type ReactNode } from "react";
|
||||
|
||||
import type { API_VERSIONS_ENUM } from "@calcom/platform-constants";
|
||||
import { VERSION_2024_06_11 } from "@calcom/platform-constants";
|
||||
import { VERSION_2024_06_14 } from "@calcom/platform-constants";
|
||||
|
||||
import http from "../lib/http";
|
||||
import { BaseCalProvider } from "./BaseCalProvider";
|
||||
@@ -40,7 +40,7 @@ export function CalProvider({
|
||||
children,
|
||||
autoUpdateTimezone = true,
|
||||
onTimezoneChange,
|
||||
version = VERSION_2024_06_11,
|
||||
version = VERSION_2024_06_14,
|
||||
}: CalProviderProps) {
|
||||
useEffect(() => {
|
||||
http.setVersionHeader(version);
|
||||
|
||||
+257
@@ -0,0 +1,257 @@
|
||||
import type { BookerProps } from "@calcom/features/bookings/Booker";
|
||||
import { getFieldIdentifier } from "@calcom/features/form-builder/utils/getFieldIdentifier";
|
||||
import { defaultEvents } from "@calcom/lib/defaultEvents";
|
||||
import type { CommonField, OptionsField, SystemField } from "@calcom/lib/event-types/transformers";
|
||||
import {
|
||||
transformApiEventTypeLocations,
|
||||
transformApiEventTypeBookingFields,
|
||||
} from "@calcom/lib/event-types/transformers";
|
||||
import { getBookerBaseUrlSync } from "@calcom/lib/getBookerUrl/client";
|
||||
import type { EventTypeOutput_2024_06_14 } from "@calcom/platform-types";
|
||||
import {
|
||||
bookerLayoutOptions,
|
||||
BookerLayouts,
|
||||
bookerLayouts as bookerLayoutsSchema,
|
||||
userMetadata as userMetadataSchema,
|
||||
eventTypeBookingFields,
|
||||
} from "@calcom/prisma/zod-utils";
|
||||
|
||||
export function transformApiEventTypeForAtom(
|
||||
eventType: Omit<EventTypeOutput_2024_06_14, "ownerId">,
|
||||
entity: BookerProps["entity"] | undefined
|
||||
) {
|
||||
const { lengthInMinutes, locations, bookingFields, users, ...rest } = eventType;
|
||||
|
||||
const isDefault = isDefaultEvent(rest.title);
|
||||
const user = users[0];
|
||||
|
||||
const defaultEventBookerLayouts = {
|
||||
enabledLayouts: [...bookerLayoutOptions],
|
||||
defaultLayout: BookerLayouts.MONTH_VIEW,
|
||||
};
|
||||
const firstUsersMetadata = userMetadataSchema.parse(user.metadata || {});
|
||||
const bookerLayouts = bookerLayoutsSchema.parse(
|
||||
firstUsersMetadata?.defaultBookerLayouts || defaultEventBookerLayouts
|
||||
);
|
||||
|
||||
return {
|
||||
...rest,
|
||||
length: lengthInMinutes,
|
||||
locations: getLocations(locations),
|
||||
bookingFields: getBookingFields(bookingFields),
|
||||
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: [],
|
||||
users: 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}`,
|
||||
},
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
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 = transformApiEventTypeLocations(locations);
|
||||
|
||||
const withPrivateHidden = transformed.map((location) => {
|
||||
const { displayLocationPublicly, type } = location;
|
||||
|
||||
switch (type) {
|
||||
case "address":
|
||||
return displayLocationPublicly ? location : { ...location, address: "" };
|
||||
case "link":
|
||||
return displayLocationPublicly ? location : { ...location, link: "" };
|
||||
case "phone":
|
||||
return displayLocationPublicly
|
||||
? location
|
||||
: {
|
||||
...location,
|
||||
hostPhoneNumber: "",
|
||||
};
|
||||
default:
|
||||
return location;
|
||||
}
|
||||
});
|
||||
|
||||
return withPrivateHidden;
|
||||
}
|
||||
|
||||
function getBookingFields(bookingFields: EventTypeOutput_2024_06_14["bookingFields"]) {
|
||||
const transformedBookingFields: (CommonField | SystemField | OptionsField)[] =
|
||||
transformApiEventTypeBookingFields(bookingFields);
|
||||
|
||||
// These fields should be added before other user fields
|
||||
const systemBeforeFields: SystemField[] = [
|
||||
{
|
||||
type: "name",
|
||||
// This is the `name` of the main field
|
||||
name: "name",
|
||||
editable: "system",
|
||||
// This Label is used in Email only as of now.
|
||||
defaultLabel: "your_name",
|
||||
required: true,
|
||||
sources: [
|
||||
{
|
||||
label: "Default",
|
||||
id: "default",
|
||||
type: "default",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
defaultLabel: "email_address",
|
||||
type: "email",
|
||||
name: "email",
|
||||
required: true,
|
||||
editable: "system",
|
||||
sources: [
|
||||
{
|
||||
label: "Default",
|
||||
id: "default",
|
||||
type: "default",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
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: "",
|
||||
},
|
||||
},
|
||||
sources: [
|
||||
{
|
||||
label: "Default",
|
||||
id: "default",
|
||||
type: "default",
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
// These fields should be added after other user fields
|
||||
const systemAfterFields: SystemField[] = [
|
||||
{
|
||||
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",
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const missingSystemBeforeFields: SystemField[] = [];
|
||||
|
||||
for (const field of systemBeforeFields) {
|
||||
const existingBookingFieldIndex = transformedBookingFields.findIndex(
|
||||
(f) => getFieldIdentifier(f.name) === getFieldIdentifier(field.name)
|
||||
);
|
||||
// Only do a push, we must not update existing system fields as user could have modified any property in it,
|
||||
if (existingBookingFieldIndex === -1) {
|
||||
missingSystemBeforeFields.push(field);
|
||||
} else {
|
||||
// Adding the fields from Code first and then fields from DB. Allows, the code to push new properties to the field
|
||||
transformedBookingFields[existingBookingFieldIndex] = {
|
||||
...field,
|
||||
...transformedBookingFields[existingBookingFieldIndex],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
transformedBookingFields.push(...missingSystemBeforeFields);
|
||||
|
||||
const missingSystemAfterFields: SystemField[] = [];
|
||||
for (const field of systemAfterFields) {
|
||||
const existingBookingFieldIndex = transformedBookingFields.findIndex(
|
||||
(f) => getFieldIdentifier(f.name) === getFieldIdentifier(field.name)
|
||||
);
|
||||
// Only do a push, we must not update existing system fields as user could have modified any property in it,
|
||||
if (existingBookingFieldIndex === -1) {
|
||||
missingSystemAfterFields.push(field);
|
||||
} else {
|
||||
transformedBookingFields[existingBookingFieldIndex] = {
|
||||
// Adding the fields from Code first and then fields from DB. Allows, the code to push new properties to the field
|
||||
...field,
|
||||
...transformedBookingFields[existingBookingFieldIndex],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
transformedBookingFields.push(...missingSystemAfterFields);
|
||||
return eventTypeBookingFields.brand<"HAS_SYSTEM_FIELDS">().parse(transformedBookingFields);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
|
||||
import { V2_ENDPOINTS, SUCCESS_STATUS } from "@calcom/platform-constants";
|
||||
import type { EventTypeOutput_2024_06_14 } from "@calcom/platform-types";
|
||||
import type { ApiResponse, ApiSuccessResponse } from "@calcom/platform-types";
|
||||
|
||||
import http from "../../../lib/http";
|
||||
|
||||
export const QUERY_KEY = "use-event-by-id";
|
||||
export const useEventTypeById = (id: number | null) => {
|
||||
const pathname = `/${V2_ENDPOINTS.eventTypes}/${id}`;
|
||||
|
||||
return useQuery({
|
||||
queryKey: [QUERY_KEY, id],
|
||||
queryFn: () => {
|
||||
return http?.get<ApiResponse<EventTypeOutput_2024_06_14>>(pathname).then((res) => {
|
||||
if (res.data.status === SUCCESS_STATUS) {
|
||||
return (res.data as ApiSuccessResponse<EventTypeOutput_2024_06_14>).data;
|
||||
}
|
||||
throw new Error(res.data.error.message);
|
||||
});
|
||||
},
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,59 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { useMemo } from "react";
|
||||
import { shallow } from "zustand/shallow";
|
||||
|
||||
import { useBookerStore } from "@calcom/features/bookings/Booker/store";
|
||||
import { getUsernameList } from "@calcom/lib/defaultEvents";
|
||||
import { SUCCESS_STATUS, V2_ENDPOINTS } from "@calcom/platform-constants";
|
||||
import type { EventTypeOutput_2024_06_14 } from "@calcom/platform-types";
|
||||
import type { ApiResponse } from "@calcom/platform-types";
|
||||
|
||||
import http from "../../../lib/http";
|
||||
|
||||
export const QUERY_KEY = "use-event-type";
|
||||
export type UsePublicEventReturnType = ReturnType<typeof useEventType>;
|
||||
|
||||
export const useEventType = (username: string, eventSlug: string) => {
|
||||
const [stateUsername, stateEventSlug] = useBookerStore(
|
||||
(state) => [state.username, state.eventSlug],
|
||||
shallow
|
||||
);
|
||||
|
||||
const requestUsername = stateUsername ?? username;
|
||||
const requestEventSlug = stateEventSlug ?? eventSlug;
|
||||
|
||||
const isDynamic = useMemo(() => {
|
||||
return getUsernameList(requestUsername ?? "").length > 1;
|
||||
}, [requestUsername]);
|
||||
|
||||
const event = useQuery({
|
||||
queryKey: [QUERY_KEY, stateUsername ?? username, stateEventSlug ?? eventSlug],
|
||||
queryFn: async () => {
|
||||
if (isDynamic) {
|
||||
return http
|
||||
.get<ApiResponse<EventTypeOutput_2024_06_14[]>>(
|
||||
`/${V2_ENDPOINTS.eventTypes}?usernames=${encodeURIComponent(getUsernameList(username).join(","))}`
|
||||
)
|
||||
.then((res) => {
|
||||
if (res.data.status === SUCCESS_STATUS) {
|
||||
return res.data.data;
|
||||
}
|
||||
throw new Error(res.data.error.message);
|
||||
});
|
||||
}
|
||||
|
||||
return http
|
||||
.get<ApiResponse<EventTypeOutput_2024_06_14[]>>(
|
||||
`/${V2_ENDPOINTS.eventTypes}?username=${requestUsername}&eventSlug=${requestEventSlug}`
|
||||
)
|
||||
.then((res) => {
|
||||
if (res.data.status === SUCCESS_STATUS) {
|
||||
return res.data.data;
|
||||
}
|
||||
throw new Error(res.data.error.message);
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
return event;
|
||||
};
|
||||
@@ -0,0 +1,24 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
|
||||
import { V2_ENDPOINTS, SUCCESS_STATUS } from "@calcom/platform-constants";
|
||||
import type { EventTypeOutput_2024_06_14 } from "@calcom/platform-types";
|
||||
import type { ApiResponse, ApiSuccessResponse } from "@calcom/platform-types";
|
||||
|
||||
import http from "../../../lib/http";
|
||||
|
||||
export const QUERY_KEY = "use-event-types";
|
||||
export const useEventTypes = (username: string) => {
|
||||
const pathname = `/${V2_ENDPOINTS.eventTypes}?username=${username}`;
|
||||
|
||||
return useQuery({
|
||||
queryKey: [QUERY_KEY, username],
|
||||
queryFn: () => {
|
||||
return http?.get<ApiResponse<EventTypeOutput_2024_06_14[]>>(pathname).then((res) => {
|
||||
if (res.data.status === SUCCESS_STATUS) {
|
||||
return (res.data as ApiSuccessResponse<EventTypeOutput_2024_06_14[]>).data;
|
||||
}
|
||||
throw new Error(res.data.error.message);
|
||||
});
|
||||
},
|
||||
});
|
||||
};
|
||||
@@ -1,24 +0,0 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
|
||||
import { V2_ENDPOINTS, SUCCESS_STATUS } from "@calcom/platform-constants";
|
||||
import type { EventTypesByViewer } from "@calcom/platform-libraries";
|
||||
import type { ApiResponse, ApiSuccessResponse } from "@calcom/platform-types";
|
||||
|
||||
import http from "../../lib/http";
|
||||
|
||||
export const QUERY_KEY = "get-private-events";
|
||||
export const useEventTypesPrivate = () => {
|
||||
const pathname = `/${V2_ENDPOINTS.eventTypes}`;
|
||||
|
||||
return useQuery({
|
||||
queryKey: [QUERY_KEY],
|
||||
queryFn: () => {
|
||||
return http?.get<ApiResponse<EventTypesByViewer>>(pathname).then((res) => {
|
||||
if (res.data.status === SUCCESS_STATUS) {
|
||||
return (res.data as ApiSuccessResponse<EventTypesByViewer>).data;
|
||||
}
|
||||
throw new Error(res.data.error.message);
|
||||
});
|
||||
},
|
||||
});
|
||||
};
|
||||
@@ -1,24 +0,0 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
|
||||
import { V2_ENDPOINTS, SUCCESS_STATUS } from "@calcom/platform-constants";
|
||||
import type { EventTypesPublic } from "@calcom/platform-libraries";
|
||||
import type { ApiResponse, ApiSuccessResponse } from "@calcom/platform-types";
|
||||
|
||||
import http from "../../lib/http";
|
||||
|
||||
export const QUERY_KEY = "get-public-events";
|
||||
export const useEventTypesPublic = (username: string) => {
|
||||
const pathname = `/${V2_ENDPOINTS.eventTypes}/${username}/public`;
|
||||
|
||||
return useQuery({
|
||||
queryKey: [QUERY_KEY, username],
|
||||
queryFn: () => {
|
||||
return http?.get<ApiResponse<EventTypesPublic>>(pathname).then((res) => {
|
||||
if (res.data.status === SUCCESS_STATUS) {
|
||||
return (res.data as ApiSuccessResponse<EventTypesPublic>).data;
|
||||
}
|
||||
throw new Error(res.data.error.message);
|
||||
});
|
||||
},
|
||||
});
|
||||
};
|
||||
@@ -1,24 +0,0 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
|
||||
import { V2_ENDPOINTS, SUCCESS_STATUS } from "@calcom/platform-constants";
|
||||
import type { EventType as AtomEventType } from "@calcom/platform-libraries";
|
||||
import type { ApiResponse, ApiSuccessResponse } from "@calcom/platform-types";
|
||||
|
||||
import http from "../../lib/http";
|
||||
|
||||
export const QUERY_KEY = "get-event-by-id";
|
||||
export const useGetEventTypeById = (id: number | null) => {
|
||||
const pathname = `/${V2_ENDPOINTS.eventTypes}/${id}?for=atom`;
|
||||
|
||||
return useQuery({
|
||||
queryKey: [QUERY_KEY, id],
|
||||
queryFn: () => {
|
||||
return http?.get<ApiResponse<AtomEventType>>(pathname).then((res) => {
|
||||
if (res.data.status === SUCCESS_STATUS) {
|
||||
return (res.data as ApiSuccessResponse<AtomEventType>).data;
|
||||
}
|
||||
throw new Error(res.data.error.message);
|
||||
});
|
||||
},
|
||||
});
|
||||
};
|
||||
@@ -1,11 +1,11 @@
|
||||
import type { UseBookingFormReturnType } from "@calcom/features/bookings/Booker/components/hooks/useBookingForm";
|
||||
import { useBookerStore } from "@calcom/features/bookings/Booker/store";
|
||||
import type { useEventReturnType } from "@calcom/features/bookings/Booker/utils/event";
|
||||
import {
|
||||
useTimePreferences,
|
||||
mapBookingToMutationInput,
|
||||
mapRecurringBookingToMutationInput,
|
||||
} from "@calcom/features/bookings/lib";
|
||||
import type { BookerEvent } from "@calcom/features/bookings/types";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import type { BookingCreateBody } from "@calcom/prisma/zod-utils";
|
||||
|
||||
@@ -13,7 +13,12 @@ import type { UseCreateBookingInput } from "./useCreateBooking";
|
||||
|
||||
type UseHandleBookingProps = {
|
||||
bookingForm: UseBookingFormReturnType["bookingForm"];
|
||||
event: useEventReturnType;
|
||||
event?: {
|
||||
data?: Pick<
|
||||
BookerEvent,
|
||||
"id" | "isDynamic" | "metadata" | "recurringEvent" | "length" | "slug" | "schedulingType"
|
||||
> | null;
|
||||
};
|
||||
metadata: Record<string, string>;
|
||||
hashedLink?: string | null;
|
||||
teamMemberEmail?: string;
|
||||
|
||||
@@ -4,7 +4,7 @@ import { shallow } from "zustand/shallow";
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import { useBookerStore } from "@calcom/features/bookings/Booker/store";
|
||||
import { useSlotReservationId } from "@calcom/features/bookings/Booker/useSlotReservationId";
|
||||
import type { useEventReturnType } from "@calcom/features/bookings/Booker/utils/event";
|
||||
import type { BookerEvent } from "@calcom/features/bookings/types";
|
||||
import { MINUTES_TO_BOOK } from "@calcom/lib/constants";
|
||||
|
||||
import { useDeleteSelectedSlot } from "./useDeleteSelectedSlot";
|
||||
@@ -12,7 +12,7 @@ import { useReserveSlot } from "./useReserveSlot";
|
||||
|
||||
export type UseSlotsReturnType = ReturnType<typeof useSlots>;
|
||||
|
||||
export const useSlots = (event: useEventReturnType) => {
|
||||
export const useSlots = (event: { data?: Pick<BookerEvent, "id" | "length"> | null }) => {
|
||||
const selectedDuration = useBookerStore((state) => state.selectedDuration);
|
||||
const [selectedTimeslot, setSelectedTimeslot] = useBookerStore(
|
||||
(state) => [state.selectedTimeslot, state.setSelectedTimeslot],
|
||||
|
||||
@@ -5,9 +5,9 @@ export { BookerPlatformWrapper as Booker } from "./booker";
|
||||
export { useIsPlatform } from "./hooks/useIsPlatform";
|
||||
export { useAtomsContext } from "./hooks/useAtomsContext";
|
||||
export { useConnectedCalendars } from "./hooks/useConnectedCalendars";
|
||||
export { useEventTypesPublic } from "./hooks/event-types/useEventTypesPublic";
|
||||
export { usePublicEvent } from "./hooks/usePublicEvent";
|
||||
export { useGetEventTypeById } from "./hooks/event-types/useGetEventTypeById";
|
||||
export { useEventTypes } from "./hooks/event-types/public/useEventTypes";
|
||||
export { useEventType as useEvent } from "./hooks/event-types/public/useEventType";
|
||||
export { useEventTypeById } from "./hooks/event-types/private/useEventTypeById";
|
||||
export { useCancelBooking } from "./hooks/useCancelBooking";
|
||||
export { useGetBooking } from "./hooks/useGetBooking";
|
||||
export { useGetBookings } from "./hooks/useGetBookings";
|
||||
|
||||
@@ -3,7 +3,7 @@ export { AvailabilitySettingsWebWrapper as AvailabilitySettings } from "./availa
|
||||
export { CalProvider } from "./cal-provider/CalProvider";
|
||||
export { useIsPlatform } from "./hooks/useIsPlatform";
|
||||
export { useAtomsContext } from "./hooks/useAtomsContext";
|
||||
export { useGetEventTypeById } from "./hooks/event-types/useGetEventTypeById";
|
||||
export { useEventTypeById } from "./hooks/event-types/private/useEventTypeById";
|
||||
export { useHandleBookEvent } from "./hooks/useHandleBookEvent";
|
||||
export * as Dialog from "./src/components/ui/dialog";
|
||||
export { Timezone } from "./timezone";
|
||||
@@ -51,9 +51,12 @@ export const X_CAL_CLIENT_ID = "x-cal-client-id";
|
||||
// HTTP status codes
|
||||
export const HTTP_CODE_TOKEN_EXPIRED = 498;
|
||||
|
||||
export const VERSION_2024_06_14 = "2024-06-14";
|
||||
export const VERSION_2024_06_11 = "2024-06-11";
|
||||
export const VERSION_2024_04_15 = "2024-04-15";
|
||||
export const API_VERSIONS = [VERSION_2024_06_11, VERSION_2024_04_15] as const;
|
||||
|
||||
export const API_VERSIONS = [VERSION_2024_06_14, VERSION_2024_06_11, VERSION_2024_04_15] as const;
|
||||
|
||||
export type API_VERSIONS_ENUM = (typeof API_VERSIONS)[number];
|
||||
export type API_VERSIONS_TYPE = typeof API_VERSIONS;
|
||||
export const CAL_API_VERSION_HEADER = "cal-api-version";
|
||||
@@ -4,7 +4,7 @@ import { Inter } from "next/font/google";
|
||||
import { useRouter } from "next/router";
|
||||
import { useState } from "react";
|
||||
|
||||
import { Booker, useEventTypesPublic } from "@calcom/atoms";
|
||||
import { Booker, useEventTypes } from "@calcom/atoms";
|
||||
|
||||
const inter = Inter({ subsets: ["latin"] });
|
||||
|
||||
@@ -13,7 +13,7 @@ export default function Bookings(props: { calUsername: string; calEmail: string
|
||||
const [eventTypeSlug, setEventTypeSlug] = useState<string | null>(null);
|
||||
const [eventTypeDuration, setEventTypeDuration] = useState<number | null>(null);
|
||||
const router = useRouter();
|
||||
const { isLoading: isLoadingEvents, data: eventTypes } = useEventTypesPublic(props.calUsername);
|
||||
const { isLoading: isLoadingEvents, data: eventTypes } = useEventTypes(props.calUsername);
|
||||
const rescheduleUid = (router.query.rescheduleUid as string) ?? "";
|
||||
const eventTypeSlugQueryParam = (router.query.eventTypeSlug as string) ?? "";
|
||||
|
||||
@@ -28,26 +28,28 @@ export default function Bookings(props: { calUsername: string; calEmail: string
|
||||
|
||||
{!isLoadingEvents && !eventTypeSlug && Boolean(eventTypes?.length) && !rescheduleUid && (
|
||||
<div className="flex flex-col gap-4">
|
||||
{eventTypes?.map((event: { id: number; slug: string; title: string; length: number }) => {
|
||||
const formatEventSlug = event.slug
|
||||
.split("-")
|
||||
.map((item) => `${item[0].toLocaleUpperCase()}${item.slice(1)}`)
|
||||
.join(" ");
|
||||
{eventTypes?.map(
|
||||
(event: { id: number; slug: string; title: string; lengthInMinutes: number }) => {
|
||||
const formatEventSlug = event.slug
|
||||
.split("-")
|
||||
.map((item) => `${item[0].toLocaleUpperCase()}${item.slice(1)}`)
|
||||
.join(" ");
|
||||
|
||||
return (
|
||||
<div
|
||||
onClick={() => {
|
||||
setEventTypeSlug(event.slug);
|
||||
setEventTypeDuration(event.length);
|
||||
}}
|
||||
className="mx-10 w-[80vw] cursor-pointer rounded-md border-[0.8px] border-black px-10 py-4"
|
||||
key={event.id}>
|
||||
<h1 className="text-lg font-semibold">{formatEventSlug}</h1>
|
||||
<p>{`/${event.slug}`}</p>
|
||||
<span className="border-none bg-gray-800 px-2 text-white">{event?.length}</span>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
return (
|
||||
<div
|
||||
onClick={() => {
|
||||
setEventTypeSlug(event.slug);
|
||||
setEventTypeDuration(event.lengthInMinutes);
|
||||
}}
|
||||
className="mx-10 w-[80vw] cursor-pointer rounded-md border-[0.8px] border-black px-10 py-4"
|
||||
key={event.id}>
|
||||
<h1 className="text-lg font-semibold">{formatEventSlug}</h1>
|
||||
<p>{`/${event.slug}`}</p>
|
||||
<span className="border-none bg-gray-800 px-2 text-white">{event?.lengthInMinutes}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { CalendarService } from "@calcom/app-store/applecalendar/lib";
|
||||
import { getBookingForReschedule } from "@calcom/features/bookings/lib/get-booking";
|
||||
import getBookingInfo from "@calcom/features/bookings/lib/getBookingInfo";
|
||||
import handleCancelBooking from "@calcom/features/bookings/lib/handleCancelBooking";
|
||||
@@ -5,6 +6,7 @@ import * as newBookingMethods from "@calcom/features/bookings/lib/handleNewBooki
|
||||
import { getPublicEvent } from "@calcom/features/eventtypes/lib/getPublicEvent";
|
||||
import * as instantMeetingMethods from "@calcom/features/instant-meeting/handleInstantMeeting";
|
||||
import getAllUserBookings from "@calcom/lib/bookings/getAllUserBookings";
|
||||
import { symmetricEncrypt } from "@calcom/lib/crypto";
|
||||
import { updateHandler as updateScheduleHandler } from "@calcom/trpc/server/routers/viewer/availability/schedule/update.handler";
|
||||
import { getAvailableSlots } from "@calcom/trpc/server/routers/viewer/slots/util";
|
||||
import { createNewUsersConnectToOrgIfExists } from "@calcom/trpc/server/routers/viewer/teams/inviteMember/utils";
|
||||
@@ -78,3 +80,20 @@ export { getBookingInfo };
|
||||
export { handleCancelBooking };
|
||||
|
||||
export { eventTypeBookingFields, eventTypeLocations } from "@calcom/prisma/zod-utils";
|
||||
|
||||
export { EventTypeMetaDataSchema, userMetadata } from "@calcom/prisma/zod-utils";
|
||||
|
||||
export {
|
||||
transformApiEventTypeBookingFields,
|
||||
transformApiEventTypeLocations,
|
||||
getResponseEventTypeLocations,
|
||||
getResponseEventTypeBookingFields,
|
||||
TransformedLocationsSchema,
|
||||
BookingFieldsSchema,
|
||||
} from "@calcom/lib/event-types/transformers";
|
||||
|
||||
export { parseRecurringEvent } from "@calcom/lib/isRecurringEvent";
|
||||
export { dynamicEvent } from "@calcom/lib/defaultEvents";
|
||||
|
||||
export { symmetricEncrypt };
|
||||
export { CalendarService };
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from "./inputs";
|
||||
export * from "./outputs";
|
||||
+416
@@ -0,0 +1,416 @@
|
||||
import { BadRequestException } from "@nestjs/common";
|
||||
import { ApiProperty as DocsProperty } from "@nestjs/swagger";
|
||||
import { plainToInstance } from "class-transformer";
|
||||
import { IsString, IsBoolean, IsArray, IsIn, IsOptional } from "class-validator";
|
||||
import type { ValidationOptions, ValidatorConstraintInterface } from "class-validator";
|
||||
import { registerDecorator, validate, ValidatorConstraint } from "class-validator";
|
||||
|
||||
const bookingFields = [
|
||||
"name",
|
||||
"email",
|
||||
"phone",
|
||||
"address",
|
||||
"text",
|
||||
"number",
|
||||
"textarea",
|
||||
"select",
|
||||
"multiselect",
|
||||
"multiemail",
|
||||
"checkbox",
|
||||
"radio",
|
||||
"boolean",
|
||||
] as const;
|
||||
|
||||
export class NameField_2024_06_14 {
|
||||
@IsIn(bookingFields)
|
||||
@DocsProperty()
|
||||
type!: "name";
|
||||
|
||||
@IsString()
|
||||
@DocsProperty()
|
||||
slug!: string;
|
||||
|
||||
@IsString()
|
||||
@DocsProperty()
|
||||
label!: string;
|
||||
|
||||
@IsBoolean()
|
||||
@DocsProperty()
|
||||
required!: boolean;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@DocsProperty()
|
||||
placeholder?: string;
|
||||
}
|
||||
export class EmailField_2024_06_14 {
|
||||
@IsIn(bookingFields)
|
||||
@DocsProperty()
|
||||
type!: "email";
|
||||
|
||||
@IsString()
|
||||
@DocsProperty()
|
||||
slug!: string;
|
||||
|
||||
@IsString()
|
||||
@DocsProperty()
|
||||
label!: string;
|
||||
|
||||
@IsBoolean()
|
||||
@DocsProperty()
|
||||
required!: boolean;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@DocsProperty()
|
||||
placeholder?: string;
|
||||
}
|
||||
|
||||
export class PhoneField_2024_06_14 {
|
||||
@IsIn(bookingFields)
|
||||
@DocsProperty()
|
||||
type!: "phone";
|
||||
|
||||
@IsString()
|
||||
@DocsProperty()
|
||||
slug!: string;
|
||||
|
||||
@IsString()
|
||||
@DocsProperty()
|
||||
label!: string;
|
||||
|
||||
@IsBoolean()
|
||||
@DocsProperty()
|
||||
required!: boolean;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@DocsProperty()
|
||||
placeholder?: string;
|
||||
}
|
||||
|
||||
export class AddressField_2024_06_14 {
|
||||
@IsIn(bookingFields)
|
||||
@DocsProperty()
|
||||
type!: "address";
|
||||
|
||||
@IsString()
|
||||
@DocsProperty()
|
||||
slug!: string;
|
||||
|
||||
@IsString()
|
||||
@DocsProperty({ example: "Please enter your address" })
|
||||
label!: string;
|
||||
|
||||
@IsBoolean()
|
||||
@DocsProperty()
|
||||
required!: boolean;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@DocsProperty()
|
||||
@DocsProperty({ example: "e.g., 1234 Main St" })
|
||||
placeholder?: string;
|
||||
}
|
||||
|
||||
export class TextField_2024_06_14 {
|
||||
@IsIn(bookingFields)
|
||||
@DocsProperty()
|
||||
type!: "text";
|
||||
|
||||
@IsString()
|
||||
@DocsProperty()
|
||||
slug!: string;
|
||||
|
||||
@IsString()
|
||||
@DocsProperty({ example: "Please enter your text" })
|
||||
label!: string;
|
||||
|
||||
@IsBoolean()
|
||||
@DocsProperty()
|
||||
required!: boolean;
|
||||
|
||||
@IsString()
|
||||
@DocsProperty({ example: "e.g., Enter text here" })
|
||||
@IsOptional()
|
||||
@DocsProperty()
|
||||
placeholder?: string;
|
||||
}
|
||||
|
||||
export class NumberField_2024_06_14 {
|
||||
@IsIn(bookingFields)
|
||||
@DocsProperty()
|
||||
type!: "number";
|
||||
|
||||
@IsString()
|
||||
@DocsProperty()
|
||||
slug!: string;
|
||||
|
||||
@IsString()
|
||||
@DocsProperty({ example: "Please enter a number" })
|
||||
label!: string;
|
||||
|
||||
@IsBoolean()
|
||||
@DocsProperty()
|
||||
required!: boolean;
|
||||
|
||||
@IsString()
|
||||
@DocsProperty({ example: "e.g., 100" })
|
||||
@IsOptional()
|
||||
@DocsProperty()
|
||||
placeholder?: string;
|
||||
}
|
||||
|
||||
export class TextAreaField_2024_06_14 {
|
||||
@IsIn(bookingFields)
|
||||
@DocsProperty()
|
||||
type!: "textarea";
|
||||
|
||||
@IsString()
|
||||
@DocsProperty()
|
||||
slug!: string;
|
||||
|
||||
@IsString()
|
||||
@DocsProperty({ example: "Please enter detailed information" })
|
||||
label!: string;
|
||||
|
||||
@IsBoolean()
|
||||
@DocsProperty()
|
||||
required!: boolean;
|
||||
|
||||
@IsString()
|
||||
@DocsProperty({ example: "e.g., Detailed description here..." })
|
||||
@IsOptional()
|
||||
@DocsProperty()
|
||||
placeholder?: string;
|
||||
}
|
||||
|
||||
export class SelectField_2024_06_14 {
|
||||
@IsIn(bookingFields)
|
||||
@DocsProperty()
|
||||
type!: "select";
|
||||
|
||||
@IsString()
|
||||
@DocsProperty()
|
||||
slug!: string;
|
||||
|
||||
@IsString()
|
||||
@DocsProperty({ example: "Please select an option" })
|
||||
label!: string;
|
||||
|
||||
@IsBoolean()
|
||||
@DocsProperty()
|
||||
required!: boolean;
|
||||
|
||||
@IsString()
|
||||
@DocsProperty({ example: "Select..." })
|
||||
@IsOptional()
|
||||
@DocsProperty()
|
||||
placeholder?: string;
|
||||
|
||||
@IsArray()
|
||||
@DocsProperty({ type: [String], example: ["Option 1", "Option 2"] })
|
||||
options!: string[];
|
||||
}
|
||||
|
||||
export class MultiSelectField_2024_06_14 {
|
||||
@IsIn(bookingFields)
|
||||
@DocsProperty()
|
||||
type!: "multiselect";
|
||||
|
||||
@IsString()
|
||||
@DocsProperty()
|
||||
slug!: string;
|
||||
|
||||
@IsString()
|
||||
@DocsProperty({ example: "Please select multiple options" })
|
||||
label!: string;
|
||||
|
||||
@IsBoolean()
|
||||
@DocsProperty()
|
||||
required!: boolean;
|
||||
|
||||
@IsArray()
|
||||
@DocsProperty({ type: [String], example: ["Option 1", "Option 2"] })
|
||||
options!: string[];
|
||||
}
|
||||
|
||||
export class MultiEmailField_2024_06_14 {
|
||||
@IsIn(bookingFields)
|
||||
@DocsProperty()
|
||||
type!: "multiemail";
|
||||
|
||||
@IsString()
|
||||
@DocsProperty()
|
||||
slug!: string;
|
||||
|
||||
@IsString()
|
||||
@DocsProperty({ example: "Please enter multiple emails" })
|
||||
label!: string;
|
||||
|
||||
@IsBoolean()
|
||||
@DocsProperty()
|
||||
required!: boolean;
|
||||
|
||||
@IsString()
|
||||
@DocsProperty({ example: "e.g., [email protected]" })
|
||||
@IsOptional()
|
||||
@DocsProperty()
|
||||
placeholder?: string;
|
||||
}
|
||||
|
||||
export class CheckboxGroupField_2024_06_14 {
|
||||
@IsIn(bookingFields)
|
||||
@DocsProperty()
|
||||
type!: "checkbox";
|
||||
|
||||
@IsString()
|
||||
@DocsProperty()
|
||||
slug!: string;
|
||||
|
||||
@IsString()
|
||||
@DocsProperty({ example: "Select all that apply" })
|
||||
label!: string;
|
||||
|
||||
@IsBoolean()
|
||||
@DocsProperty()
|
||||
required!: boolean;
|
||||
|
||||
@IsArray()
|
||||
@DocsProperty({ type: [String], example: ["Checkbox 1", "Checkbox 2"] })
|
||||
options!: string[];
|
||||
}
|
||||
|
||||
export class RadioGroupField_2024_06_14 {
|
||||
@IsIn(bookingFields)
|
||||
@DocsProperty()
|
||||
type!: "radio";
|
||||
|
||||
@IsString()
|
||||
@DocsProperty()
|
||||
slug!: string;
|
||||
|
||||
@IsString()
|
||||
@DocsProperty({ example: "Select one option" })
|
||||
label!: string;
|
||||
|
||||
@IsBoolean()
|
||||
@DocsProperty()
|
||||
required!: boolean;
|
||||
|
||||
@IsArray()
|
||||
@DocsProperty({ type: [String], example: ["Radio 1", "Radio 2"] })
|
||||
options!: string[];
|
||||
}
|
||||
|
||||
export class BooleanField_2024_06_14 {
|
||||
@IsIn(bookingFields)
|
||||
@DocsProperty()
|
||||
type!: "boolean";
|
||||
|
||||
@IsString()
|
||||
@DocsProperty()
|
||||
slug!: string;
|
||||
|
||||
@IsString()
|
||||
@DocsProperty({ example: "Agree to terms?" })
|
||||
label!: string;
|
||||
|
||||
@IsBoolean()
|
||||
@DocsProperty()
|
||||
required!: boolean;
|
||||
}
|
||||
|
||||
export type BookingField_2024_06_14 =
|
||||
| NameField_2024_06_14
|
||||
| EmailField_2024_06_14
|
||||
| PhoneField_2024_06_14
|
||||
| AddressField_2024_06_14
|
||||
| TextField_2024_06_14
|
||||
| NumberField_2024_06_14
|
||||
| TextAreaField_2024_06_14
|
||||
| SelectField_2024_06_14
|
||||
| MultiSelectField_2024_06_14
|
||||
| MultiEmailField_2024_06_14
|
||||
| CheckboxGroupField_2024_06_14
|
||||
| RadioGroupField_2024_06_14
|
||||
| BooleanField_2024_06_14;
|
||||
|
||||
@ValidatorConstraint({ async: true })
|
||||
class BookingFieldValidator_2024_06_14 implements ValidatorConstraintInterface {
|
||||
private classTypeMap: { [key: string]: new () => BookingField_2024_06_14 } = {
|
||||
name: NameField_2024_06_14,
|
||||
email: EmailField_2024_06_14,
|
||||
phone: PhoneField_2024_06_14,
|
||||
address: AddressField_2024_06_14,
|
||||
text: TextField_2024_06_14,
|
||||
number: NumberField_2024_06_14,
|
||||
textarea: TextAreaField_2024_06_14,
|
||||
select: SelectField_2024_06_14,
|
||||
multiselect: MultiSelectField_2024_06_14,
|
||||
multiemail: MultiEmailField_2024_06_14,
|
||||
checkbox: CheckboxGroupField_2024_06_14,
|
||||
radio: RadioGroupField_2024_06_14,
|
||||
boolean: BooleanField_2024_06_14,
|
||||
};
|
||||
|
||||
async validate(bookingFields: { type: string; slug: string }[]) {
|
||||
if (!Array.isArray(bookingFields)) {
|
||||
throw new BadRequestException(`'bookingFields' must be an array.`);
|
||||
}
|
||||
|
||||
if (!bookingFields.length) {
|
||||
throw new BadRequestException(`'bookingFields' must contain at least 1 booking field.`);
|
||||
}
|
||||
|
||||
const slugs: string[] = [];
|
||||
for (const field of bookingFields) {
|
||||
const { type, slug } = field;
|
||||
if (!type) {
|
||||
throw new BadRequestException(`Each booking field must have a 'type' property.`);
|
||||
}
|
||||
|
||||
if (!slug) {
|
||||
throw new BadRequestException(`Each booking field must have a 'slug' property.`);
|
||||
}
|
||||
|
||||
if (slugs.includes(slug)) {
|
||||
throw new BadRequestException(
|
||||
`Duplicate bookingFields slug '${slug}' found. All bookingFields slugs must be unique.`
|
||||
);
|
||||
}
|
||||
slugs.push(slug);
|
||||
|
||||
const ClassType = this.classTypeMap[type];
|
||||
if (!ClassType) {
|
||||
throw new BadRequestException(`Unsupported booking field type '${type}'.`);
|
||||
}
|
||||
|
||||
const instance = plainToInstance(ClassType, field);
|
||||
const errors = await validate(instance);
|
||||
if (errors.length > 0) {
|
||||
const message = errors.flatMap((error) => Object.values(error.constraints || {})).join(", ");
|
||||
throw new BadRequestException(`Validation failed for ${type} booking field: ${message}`);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
defaultMessage() {
|
||||
return `Validation failed for one or more booking fields.`;
|
||||
}
|
||||
}
|
||||
|
||||
export function ValidateBookingFields_2024_06_14(validationOptions?: ValidationOptions) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
return function (object: any, propertyName: string) {
|
||||
registerDecorator({
|
||||
name: "ValidateBookingFields",
|
||||
target: object.constructor,
|
||||
propertyName: propertyName,
|
||||
options: validationOptions,
|
||||
validator: new BookingFieldValidator_2024_06_14(),
|
||||
});
|
||||
};
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
import { ApiProperty as DocsProperty } from "@nestjs/swagger";
|
||||
import { IsString, IsInt, IsBoolean, IsOptional, Min } from "class-validator";
|
||||
|
||||
import type { BookingField_2024_06_14 } from "./booking-fields.input";
|
||||
import { ValidateBookingFields_2024_06_14 } from "./booking-fields.input";
|
||||
import { ValidateLocations_2024_06_14 } from "./locations.input";
|
||||
import type { Location_2024_06_14 } from "./locations.input";
|
||||
|
||||
export const CREATE_EVENT_LENGTH_EXAMPLE = 60;
|
||||
export const CREATE_EVENT_TITLE_EXAMPLE = "Learn the secrets of masterchief!";
|
||||
export const CREATE_EVENT_DESCRIPTION_EXAMPLE =
|
||||
"Discover the culinary wonders of the Argentina by making the best flan ever!";
|
||||
export class CreateEventTypeInput_2024_06_14 {
|
||||
@IsInt()
|
||||
@Min(1)
|
||||
@DocsProperty({ example: CREATE_EVENT_LENGTH_EXAMPLE })
|
||||
lengthInMinutes!: number;
|
||||
|
||||
@IsString()
|
||||
@DocsProperty({ example: CREATE_EVENT_TITLE_EXAMPLE })
|
||||
title!: string;
|
||||
|
||||
@IsString()
|
||||
slug!: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@DocsProperty({ example: CREATE_EVENT_DESCRIPTION_EXAMPLE })
|
||||
description?: string;
|
||||
|
||||
@IsOptional()
|
||||
@ValidateLocations_2024_06_14()
|
||||
locations?: Location_2024_06_14[];
|
||||
|
||||
@IsOptional()
|
||||
@ValidateBookingFields_2024_06_14()
|
||||
bookingFields?: BookingField_2024_06_14[];
|
||||
|
||||
@IsBoolean()
|
||||
@IsOptional()
|
||||
disableGuests?: boolean;
|
||||
|
||||
@IsInt()
|
||||
@IsOptional()
|
||||
slotInterval?: number;
|
||||
|
||||
@IsInt()
|
||||
@Min(0)
|
||||
@IsOptional()
|
||||
minimumBookingNotice?: number;
|
||||
|
||||
@IsInt()
|
||||
@IsOptional()
|
||||
beforeEventBuffer?: number;
|
||||
|
||||
@IsInt()
|
||||
@IsOptional()
|
||||
afterEventBuffer?: number;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
export enum Editable {
|
||||
system = "system",
|
||||
systemButOptional = "system-but-optional",
|
||||
systemButHidden = "system-but-hidden",
|
||||
user = "user",
|
||||
userReadonly = "user-readonly",
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
export enum BaseFieldEnum {
|
||||
name = "name",
|
||||
number = "number",
|
||||
boolean = "boolean",
|
||||
address = "address",
|
||||
text = "text",
|
||||
textarea = "textarea",
|
||||
email = "email",
|
||||
phone = "phone",
|
||||
multiemail = "multiemail",
|
||||
select = "select",
|
||||
multiselect = "multiselect",
|
||||
checkbox = "checkbox",
|
||||
radio = "radio",
|
||||
radioInput = "radioInput",
|
||||
}
|
||||
|
||||
export type BaseFieldType = keyof typeof BaseFieldEnum;
|
||||
@@ -0,0 +1,9 @@
|
||||
export enum Frequency {
|
||||
YEARLY = 0,
|
||||
MONTHLY = 1,
|
||||
WEEKLY = 2,
|
||||
DAILY = 3,
|
||||
HOURLY = 4,
|
||||
MINUTELY = 5,
|
||||
SECONDLY = 6,
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
export enum PeriodType {
|
||||
UNLIMITED = "UNLIMITED",
|
||||
ROLLING = "ROLLING",
|
||||
RANGE = "RANGE",
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
export enum SchedulingType {
|
||||
ROUND_ROBIN = "ROUND_ROBIN",
|
||||
COLLECTIVE = "COLLECTIVE",
|
||||
MANAGED = "MANAGED",
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
import { Transform } from "class-transformer";
|
||||
import { IsOptional, IsString } from "class-validator";
|
||||
|
||||
export class GetEventTypesQuery_2024_06_14 {
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
username?: string;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
eventSlug?: string;
|
||||
|
||||
@IsOptional()
|
||||
@TransformUsernames()
|
||||
usernames?: string[];
|
||||
}
|
||||
|
||||
function TransformUsernames() {
|
||||
return Transform(({ value }) => {
|
||||
if (typeof value === "string") {
|
||||
return value.split(",").map((username) => username.trim());
|
||||
}
|
||||
return value;
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
export * from "./create-event-type.input";
|
||||
export * from "./locations.input";
|
||||
export * from "./booking-fields.input";
|
||||
export * from "./recurring-event.input";
|
||||
export * from "./update-event-type.input";
|
||||
export * from "./get-event-types-query.input";
|
||||
@@ -0,0 +1,122 @@
|
||||
import { BadRequestException } from "@nestjs/common";
|
||||
import { ApiProperty as DocsProperty } from "@nestjs/swagger";
|
||||
import { plainToInstance } from "class-transformer";
|
||||
import { IsString, IsUrl, IsIn, IsPhoneNumber, IsBoolean } from "class-validator";
|
||||
import type { ValidationOptions, ValidatorConstraintInterface } from "class-validator";
|
||||
import { registerDecorator, validate, ValidatorConstraint } from "class-validator";
|
||||
|
||||
const locations = ["address", "link", "integration", "phone"] as const;
|
||||
|
||||
export class AddressLocation_2024_06_14 {
|
||||
@IsIn(locations)
|
||||
type!: "address";
|
||||
|
||||
@IsString()
|
||||
@DocsProperty({ example: "123 Example St, City, Country" })
|
||||
address!: string;
|
||||
|
||||
@IsBoolean()
|
||||
public!: boolean;
|
||||
}
|
||||
|
||||
export class LinkLocation_2024_06_14 {
|
||||
@IsIn(locations)
|
||||
type!: "link";
|
||||
|
||||
@IsUrl()
|
||||
@DocsProperty({ example: "https://customvideo.com/join/123456" })
|
||||
link!: string;
|
||||
|
||||
@IsBoolean()
|
||||
public!: boolean;
|
||||
}
|
||||
|
||||
const integrations = ["cal-video"] as const;
|
||||
export type Integration_2024_06_14 = (typeof integrations)[number];
|
||||
|
||||
export class IntegrationLocation_2024_06_14 {
|
||||
@IsIn(locations)
|
||||
type!: "integration";
|
||||
|
||||
@IsIn(integrations)
|
||||
@DocsProperty({ example: integrations[0] })
|
||||
integration!: Integration_2024_06_14;
|
||||
}
|
||||
|
||||
export class PhoneLocation_2024_06_14 {
|
||||
@IsIn(locations)
|
||||
type!: "phone";
|
||||
|
||||
@IsPhoneNumber()
|
||||
@DocsProperty({ example: "+37120993151" })
|
||||
phone!: string;
|
||||
|
||||
@IsBoolean()
|
||||
public!: boolean;
|
||||
}
|
||||
|
||||
export type Location_2024_06_14 =
|
||||
| AddressLocation_2024_06_14
|
||||
| LinkLocation_2024_06_14
|
||||
| IntegrationLocation_2024_06_14
|
||||
| PhoneLocation_2024_06_14;
|
||||
|
||||
@ValidatorConstraint({ async: true })
|
||||
class LocationValidator_2024_06_14 implements ValidatorConstraintInterface {
|
||||
private classTypeMap: { [key: string]: new () => Location_2024_06_14 } = {
|
||||
address: AddressLocation_2024_06_14,
|
||||
link: LinkLocation_2024_06_14,
|
||||
integration: IntegrationLocation_2024_06_14,
|
||||
phone: PhoneLocation_2024_06_14,
|
||||
};
|
||||
|
||||
async validate(locations: { type: string }[]) {
|
||||
if (!Array.isArray(locations)) {
|
||||
throw new BadRequestException(`'locations' must be an array.`);
|
||||
}
|
||||
|
||||
if (!locations.length) {
|
||||
throw new BadRequestException(`'locations' must contain at least 1 location.`);
|
||||
}
|
||||
|
||||
for (const location of locations) {
|
||||
const { type } = location;
|
||||
if (!type) {
|
||||
throw new BadRequestException(`Each object in 'locations' must have a 'type' property.`);
|
||||
}
|
||||
|
||||
const ClassType = this.classTypeMap[type];
|
||||
if (!ClassType) {
|
||||
throw new BadRequestException(
|
||||
`Unsupported location type '${type}'. Valid types are address, link, integration, and phone.`
|
||||
);
|
||||
}
|
||||
|
||||
const instance = plainToInstance(ClassType, location);
|
||||
const errors = await validate(instance);
|
||||
if (errors.length > 0) {
|
||||
const message = errors.flatMap((error) => Object.values(error.constraints || {})).join(", ");
|
||||
throw new BadRequestException(`Validation failed for ${type} location: ${message}`);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
defaultMessage() {
|
||||
return `Validation failed for one or more location entries.`;
|
||||
}
|
||||
}
|
||||
|
||||
export function ValidateLocations_2024_06_14(validationOptions?: ValidationOptions) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
return function (object: any, propertyName: string) {
|
||||
registerDecorator({
|
||||
name: "ValidateLocation",
|
||||
target: object.constructor,
|
||||
propertyName: propertyName,
|
||||
options: validationOptions,
|
||||
validator: new LocationValidator_2024_06_14(),
|
||||
});
|
||||
};
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
import { IsInt, IsEnum, IsOptional, IsString, IsDateString } from "class-validator";
|
||||
|
||||
export enum Frequency {
|
||||
YEARLY = 0,
|
||||
MONTHLY = 1,
|
||||
WEEKLY = 2,
|
||||
DAILY = 3,
|
||||
HOURLY = 4,
|
||||
MINUTELY = 5,
|
||||
SECONDLY = 6,
|
||||
}
|
||||
|
||||
export class RecurringEvent_2024_06_14 {
|
||||
@IsOptional()
|
||||
@IsDateString()
|
||||
dtstart?: Date;
|
||||
|
||||
@IsInt()
|
||||
interval!: number;
|
||||
|
||||
@IsInt()
|
||||
count!: number;
|
||||
|
||||
@IsEnum(Frequency)
|
||||
freq!: Frequency;
|
||||
|
||||
@IsOptional()
|
||||
@IsDateString()
|
||||
until?: Date;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
tzid?: string;
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
import { IsString, IsInt, IsBoolean, IsOptional, Min } from "class-validator";
|
||||
|
||||
import type { BookingField_2024_06_14 } from "./booking-fields.input";
|
||||
import { ValidateBookingFields_2024_06_14 } from "./booking-fields.input";
|
||||
import { ValidateLocations_2024_06_14 } from "./locations.input";
|
||||
import type { Location_2024_06_14 } from "./locations.input";
|
||||
|
||||
export class UpdateEventTypeInput_2024_06_14 {
|
||||
@IsOptional()
|
||||
@IsInt()
|
||||
@Min(1)
|
||||
lengthInMinutes?: number;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
title?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
description?: string;
|
||||
|
||||
@IsOptional()
|
||||
@ValidateLocations_2024_06_14()
|
||||
locations?: Location_2024_06_14[];
|
||||
|
||||
@IsOptional()
|
||||
@ValidateBookingFields_2024_06_14()
|
||||
bookingFields?: BookingField_2024_06_14[];
|
||||
|
||||
@IsBoolean()
|
||||
@IsOptional()
|
||||
disableGuests?: boolean;
|
||||
|
||||
@IsInt()
|
||||
@IsOptional()
|
||||
slotInterval?: number;
|
||||
|
||||
@IsInt()
|
||||
@Min(0)
|
||||
@IsOptional()
|
||||
minimumBookingNotice?: number;
|
||||
|
||||
@IsInt()
|
||||
@IsOptional()
|
||||
beforeEventBuffer?: number;
|
||||
|
||||
@IsInt()
|
||||
@IsOptional()
|
||||
afterEventBuffer?: number;
|
||||
}
|
||||
+137
@@ -0,0 +1,137 @@
|
||||
import { ApiProperty as DocsProperty } from "@nestjs/swagger";
|
||||
import { Type } from "class-transformer";
|
||||
import { IsBoolean, IsEnum, IsInt, IsOptional, IsString, Min } from "class-validator";
|
||||
|
||||
import type { Location_2024_06_14, BookingField_2024_06_14 } from "../inputs";
|
||||
import { RecurringEvent_2024_06_14 } from "../inputs";
|
||||
import { ValidateBookingFields_2024_06_14 } from "../inputs/booking-fields.input";
|
||||
import { ValidateLocations_2024_06_14 } from "../inputs/locations.input";
|
||||
|
||||
enum SchedulingTypeEnum {
|
||||
ROUND_ROBIN = "ROUND_ROBIN",
|
||||
COLLECTIVE = "COLLECTIVE",
|
||||
MANAGED = "MANAGED",
|
||||
}
|
||||
|
||||
export type SchedulingType = "ROUND_ROBIN" | "COLLECTIVE" | "MANAGED";
|
||||
|
||||
class Schedule_2024_06_14 {
|
||||
@IsInt()
|
||||
id!: number;
|
||||
|
||||
@IsString()
|
||||
timeZone!: string | null;
|
||||
}
|
||||
|
||||
class User_2024_06_14 {
|
||||
@IsInt()
|
||||
id!: number;
|
||||
|
||||
@IsString()
|
||||
name!: string | null;
|
||||
|
||||
@IsString()
|
||||
username!: string | null;
|
||||
|
||||
@IsString()
|
||||
avatarUrl!: string | null;
|
||||
|
||||
@IsString()
|
||||
weekStart!: string;
|
||||
|
||||
@IsString()
|
||||
brandColor!: string | null;
|
||||
|
||||
@IsString()
|
||||
darkBrandColor!: string | null;
|
||||
|
||||
metadata!: Record<string, unknown>;
|
||||
}
|
||||
|
||||
export class EventTypeOutput_2024_06_14 {
|
||||
@IsInt()
|
||||
@DocsProperty({ example: 1 })
|
||||
id!: number;
|
||||
|
||||
@IsInt()
|
||||
ownerId!: number;
|
||||
|
||||
@IsInt()
|
||||
@Min(1)
|
||||
lengthInMinutes!: number;
|
||||
|
||||
@IsString()
|
||||
title!: string;
|
||||
|
||||
@IsString()
|
||||
slug!: string;
|
||||
|
||||
@IsString()
|
||||
description!: string;
|
||||
|
||||
@ValidateLocations_2024_06_14()
|
||||
locations!: Location_2024_06_14[];
|
||||
|
||||
@ValidateBookingFields_2024_06_14()
|
||||
bookingFields!: BookingField_2024_06_14[];
|
||||
|
||||
@IsBoolean()
|
||||
disableGuests!: boolean;
|
||||
|
||||
@IsInt()
|
||||
@IsOptional()
|
||||
slotInterval?: number | null;
|
||||
|
||||
@IsInt()
|
||||
@Min(0)
|
||||
@IsOptional()
|
||||
minimumBookingNotice?: number;
|
||||
|
||||
@IsInt()
|
||||
@IsOptional()
|
||||
beforeEventBuffer?: number;
|
||||
|
||||
@IsInt()
|
||||
@IsOptional()
|
||||
afterEventBuffer?: number;
|
||||
|
||||
@IsEnum(SchedulingTypeEnum)
|
||||
schedulingType!: SchedulingType | null;
|
||||
|
||||
@Type(() => RecurringEvent_2024_06_14)
|
||||
recurringEvent!: RecurringEvent_2024_06_14 | null;
|
||||
|
||||
@Type(() => Object)
|
||||
metadata!: Record<string, unknown>;
|
||||
|
||||
@IsBoolean()
|
||||
requiresConfirmation!: boolean;
|
||||
|
||||
@IsInt()
|
||||
price!: number;
|
||||
|
||||
@IsString()
|
||||
currency!: string;
|
||||
|
||||
@IsBoolean()
|
||||
lockTimeZoneToggleOnBookingPage!: boolean;
|
||||
|
||||
@IsInt()
|
||||
seatsPerTimeSlot!: number | null;
|
||||
|
||||
@IsBoolean()
|
||||
forwardParamsSuccessRedirect!: boolean | null;
|
||||
|
||||
@IsString()
|
||||
successRedirectUrl!: string | null;
|
||||
|
||||
@IsBoolean()
|
||||
seatsShowAvailabilityCount!: boolean | null;
|
||||
|
||||
@IsBoolean()
|
||||
isInstantEvent!: boolean;
|
||||
|
||||
users!: User_2024_06_14[];
|
||||
|
||||
schedule!: Schedule_2024_06_14 | null;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export * from "./event-type.output";
|
||||
@@ -0,0 +1 @@
|
||||
export * from "./event-types_2024_06_14";
|
||||
@@ -6,3 +6,4 @@ export * from "./calendars";
|
||||
export * from "./bookings";
|
||||
export * from "./billing";
|
||||
export * from "./schedules";
|
||||
export * from "./event-types";
|
||||
Reference in new issue
Block a user