2023-02-16 22:39:57 +00:00
|
|
|
import type { Prisma } from "@prisma/client";
|
|
|
|
import { PeriodType, SchedulingType } from "@prisma/client";
|
2022-06-10 18:38:46 +00:00
|
|
|
|
2022-08-26 00:48:50 +00:00
|
|
|
import { DailyLocationType } from "@calcom/app-store/locations";
|
2023-03-02 18:15:28 +00:00
|
|
|
import { getBookingFieldsWithSystemFields } from "@calcom/features/bookings/lib/getBookingFields";
|
2023-02-16 22:39:57 +00:00
|
|
|
import type { userSelect } from "@calcom/prisma/selects";
|
|
|
|
import type { CustomInputSchema } from "@calcom/prisma/zod-utils";
|
|
|
|
import { EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
|
2022-06-10 18:38:46 +00:00
|
|
|
|
2022-08-12 19:29:29 +00:00
|
|
|
type User = Prisma.UserGetPayload<typeof userSelect>;
|
2022-04-06 17:20:30 +00:00
|
|
|
|
|
|
|
type UsernameSlugLinkProps = {
|
|
|
|
users: {
|
|
|
|
id?: number;
|
|
|
|
username: string | null;
|
|
|
|
email?: string;
|
|
|
|
name?: string | null;
|
|
|
|
bio?: string | null;
|
|
|
|
avatar?: string | null;
|
|
|
|
theme?: string | null;
|
|
|
|
away?: boolean;
|
|
|
|
verified?: boolean | null;
|
|
|
|
allowDynamicBooking?: boolean | null;
|
|
|
|
}[];
|
|
|
|
slug: string;
|
|
|
|
};
|
|
|
|
|
2022-08-12 19:29:29 +00:00
|
|
|
const user: User = {
|
|
|
|
theme: null,
|
|
|
|
credentials: [],
|
|
|
|
username: "john.doe",
|
|
|
|
timeZone: "",
|
|
|
|
bufferTime: 0,
|
|
|
|
availability: [],
|
|
|
|
id: 0,
|
|
|
|
startTime: 0,
|
|
|
|
endTime: 0,
|
|
|
|
selectedCalendars: [],
|
|
|
|
schedules: [],
|
|
|
|
defaultScheduleId: null,
|
|
|
|
locale: "en",
|
|
|
|
email: "john.doe@example.com",
|
|
|
|
name: "John doe",
|
|
|
|
avatar: "",
|
|
|
|
destinationCalendar: null,
|
|
|
|
hideBranding: true,
|
|
|
|
brandColor: "#797979",
|
|
|
|
darkBrandColor: "#efefef",
|
|
|
|
allowDynamicBooking: true,
|
2023-03-13 16:49:48 +00:00
|
|
|
timeFormat: 12,
|
2022-08-12 19:29:29 +00:00
|
|
|
};
|
|
|
|
|
2022-12-01 21:53:52 +00:00
|
|
|
const customInputs: CustomInputSchema[] = [];
|
2022-04-06 17:20:30 +00:00
|
|
|
|
|
|
|
const commons = {
|
2022-06-06 09:41:11 +00:00
|
|
|
isDynamic: true,
|
2022-04-06 17:20:30 +00:00
|
|
|
periodCountCalendarDays: true,
|
|
|
|
periodStartDate: null,
|
|
|
|
periodEndDate: null,
|
|
|
|
beforeEventBuffer: 0,
|
|
|
|
afterEventBuffer: 0,
|
|
|
|
periodType: PeriodType.UNLIMITED,
|
|
|
|
periodDays: null,
|
|
|
|
slotInterval: null,
|
2022-08-26 00:48:50 +00:00
|
|
|
locations: [{ type: DailyLocationType }],
|
2022-04-06 17:20:30 +00:00
|
|
|
customInputs,
|
|
|
|
disableGuests: true,
|
|
|
|
minimumBookingNotice: 120,
|
|
|
|
schedule: null,
|
|
|
|
timeZone: null,
|
|
|
|
successRedirectUrl: "",
|
2022-08-12 19:29:29 +00:00
|
|
|
teamId: null,
|
|
|
|
scheduleId: null,
|
2022-04-06 17:20:30 +00:00
|
|
|
availability: [],
|
|
|
|
price: 0,
|
|
|
|
currency: "usd",
|
|
|
|
schedulingType: SchedulingType.COLLECTIVE,
|
2022-05-24 13:19:12 +00:00
|
|
|
seatsPerTimeSlot: null,
|
2022-10-18 19:41:50 +00:00
|
|
|
seatsShowAttendees: null,
|
2022-04-06 17:20:30 +00:00
|
|
|
id: 0,
|
|
|
|
hideCalendarNotes: false,
|
2022-06-10 00:32:34 +00:00
|
|
|
recurringEvent: null,
|
2022-04-06 17:20:30 +00:00
|
|
|
destinationCalendar: null,
|
|
|
|
team: null,
|
|
|
|
requiresConfirmation: false,
|
2022-10-12 05:29:04 +00:00
|
|
|
bookingLimits: null,
|
2023-03-10 20:00:19 +00:00
|
|
|
durationLimits: null,
|
2022-04-06 17:20:30 +00:00
|
|
|
hidden: false,
|
|
|
|
userId: 0,
|
2023-01-12 21:09:12 +00:00
|
|
|
owner: null,
|
2022-07-14 00:10:45 +00:00
|
|
|
workflows: [],
|
2022-08-12 19:29:29 +00:00
|
|
|
users: [user],
|
2023-01-12 21:09:12 +00:00
|
|
|
hosts: [],
|
2022-10-14 16:24:43 +00:00
|
|
|
metadata: EventTypeMetaDataSchema.parse({}),
|
2023-03-02 18:15:28 +00:00
|
|
|
bookingFields: getBookingFieldsWithSystemFields({
|
|
|
|
bookingFields: [],
|
|
|
|
customInputs: [],
|
|
|
|
// Default value of disableGuests from DB.
|
|
|
|
disableGuests: false,
|
|
|
|
metadata: {},
|
|
|
|
workflows: [],
|
|
|
|
}),
|
2022-04-06 17:20:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const min15Event = {
|
|
|
|
length: 15,
|
2022-04-08 16:50:10 +00:00
|
|
|
slug: "15",
|
2022-04-06 17:20:30 +00:00
|
|
|
title: "15min",
|
|
|
|
eventName: "Dynamic Collective 15min Event",
|
|
|
|
description: "Dynamic Collective 15min Event",
|
2022-09-12 10:04:42 +00:00
|
|
|
descriptionAsSafeHTML: "Dynamic Collective 15min Event",
|
2022-08-12 19:29:29 +00:00
|
|
|
position: 0,
|
2022-04-06 17:20:30 +00:00
|
|
|
...commons,
|
|
|
|
};
|
|
|
|
const min30Event = {
|
|
|
|
length: 30,
|
2022-04-08 16:50:10 +00:00
|
|
|
slug: "30",
|
2022-04-06 17:20:30 +00:00
|
|
|
title: "30min",
|
|
|
|
eventName: "Dynamic Collective 30min Event",
|
|
|
|
description: "Dynamic Collective 30min Event",
|
2022-09-12 10:04:42 +00:00
|
|
|
descriptionAsSafeHTML: "Dynamic Collective 30min Event",
|
2022-08-12 19:29:29 +00:00
|
|
|
position: 1,
|
2022-04-06 17:20:30 +00:00
|
|
|
...commons,
|
|
|
|
};
|
|
|
|
const min60Event = {
|
|
|
|
length: 60,
|
2022-04-08 16:50:10 +00:00
|
|
|
slug: "60",
|
2022-04-06 17:20:30 +00:00
|
|
|
title: "60min",
|
|
|
|
eventName: "Dynamic Collective 60min Event",
|
|
|
|
description: "Dynamic Collective 60min Event",
|
2022-09-12 10:04:42 +00:00
|
|
|
descriptionAsSafeHTML: "Dynamic Collective 60min Event",
|
2022-08-12 19:29:29 +00:00
|
|
|
position: 2,
|
2022-04-06 17:20:30 +00:00
|
|
|
...commons,
|
|
|
|
};
|
|
|
|
|
|
|
|
const defaultEvents = [min15Event, min30Event, min60Event];
|
|
|
|
|
|
|
|
export const getDynamicEventDescription = (dynamicUsernames: string[], slug: string): string => {
|
2022-04-08 16:50:10 +00:00
|
|
|
return `Book a ${slug} min event with ${dynamicUsernames.join(", ")}`;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getDynamicEventName = (dynamicNames: string[], slug: string): string => {
|
|
|
|
const lastUser = dynamicNames.pop();
|
|
|
|
return `Dynamic Collective ${slug} min event with ${dynamicNames.join(", ")} & ${lastUser}`;
|
2022-04-06 17:20:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const getDefaultEvent = (slug: string) => {
|
|
|
|
const event = defaultEvents.find((obj) => {
|
|
|
|
return obj.slug === slug;
|
|
|
|
});
|
|
|
|
return event || min15Event;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getGroupName = (usernameList: string[]): string => {
|
|
|
|
return usernameList.join(", ");
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getUsernameSlugLink = ({ users, slug }: UsernameSlugLinkProps): string => {
|
|
|
|
let slugLink = ``;
|
|
|
|
if (users.length > 1) {
|
2022-04-07 14:34:11 +00:00
|
|
|
const combinedUsername = users.map((user) => user.username).join("+");
|
2022-04-06 17:20:30 +00:00
|
|
|
slugLink = `/${combinedUsername}/${slug}`;
|
|
|
|
} else {
|
|
|
|
slugLink = `/${users[0].username}/${slug}`;
|
|
|
|
}
|
|
|
|
return slugLink;
|
|
|
|
};
|
|
|
|
|
2022-06-15 20:54:31 +00:00
|
|
|
const arrayCast = (value: unknown | unknown[]) => {
|
|
|
|
return Array.isArray(value) ? value : value ? [value] : [];
|
|
|
|
};
|
|
|
|
|
2022-04-12 17:10:18 +00:00
|
|
|
export const getUsernameList = (users: string | string[] | undefined): string[] => {
|
|
|
|
// Multiple users can come in case of a team round-robin booking and in that case dynamic link won't be a user.
|
|
|
|
// So, even though this code handles even if individual user is dynamic link, that isn't a possibility right now.
|
2022-06-15 20:54:31 +00:00
|
|
|
users = arrayCast(users);
|
|
|
|
|
|
|
|
const allUsers = users.map((user) =>
|
|
|
|
user
|
2022-12-22 18:09:31 +00:00
|
|
|
.toLowerCase()
|
2022-06-15 20:54:31 +00:00
|
|
|
.replace(/( |%20)/g, "+")
|
|
|
|
.split("+")
|
|
|
|
);
|
|
|
|
|
|
|
|
return Array.prototype.concat(...allUsers);
|
2022-04-06 17:20:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default defaultEvents;
|