dynamic group links (#2239)

* --init

* added default event types

* updated lib path

* updated group link design

* fixed collective description

* added default minimum booking notice

* Accept multi user query for a default event type

* check types

* check types --WIP

* check types still --WIP

* --WIP

* --WIP

* fixed single user type not working

* check fix

* --import path fix

* functional collective eventtype page

* fixed check type

* minor fixes and --WIP

* typefix

* custominput in defaultevent fix

* added booking page compatibility for dynamic group links

* added /book compatibility for dynamic group links

* checktype fix --WIP

* checktype fix

* Success page compatibility added

* added migrations

* added dynamic group booking slug to booking creation

* reschedule and database fix

* daily integration

* daily integration --locationtype fetch

* fixed reschedule

* added index to key parameter in eventtype list

* fix + added after last group slug

* added user setting option for dynamic booking

* changed defaultEvents location based on recent changes

* updated default event name in updated import

* disallow booking when one in group disallows it

* fixed setting checkbox association

* cleanup

* udded better error handling for disabled dynamic group bookings

* cleanup

* added tooltip to allow dynamic setting and enable by default

* Update yarn.lock

* Fix: Embed Fixes, UI configuration PRO Only, Tests (#2341)

* #2325 Followup (#2369)

* Adds initial MDX implementation for App Store pages

* Adds endpoint to serve app store static files

* Replaces zoom icon with dynamic-served one

* Fixes zoom icon

* Makes Slider reusable

* Adds gray-matter for MDX

* Adds zoom screenshots

* Update yarn.lock

* Slider improvements

* WIP

* Update TrendingAppsSlider.tsx

* WIP

* Adds MS teams screenshots

* Adds stripe screenshots

* Cleanup

* Update index.ts

* WIP

* Cleanup

* Cleanup

* Adds jitsi screenshot

* Adds Google meet screenshots

* Adds office 365 calendar screenshots

* Adds google calendar screenshots

* Follow #2325

Co-authored-by: Peer Richelsen <[email protected]>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>

* requested changes

* further requested changes

* more changes

* type fix

* fixed prisma/client import path

* added e2e test

* test-fix

* E2E fixes

* Fixes circular dependency

* Fixed paid bookings seeder

* Added missing imports

* requested changes

* added username slugs as part of event description

* updated event description

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: zomars <[email protected]>
Co-authored-by: Peer Richelsen <[email protected]>
This commit is contained in:
authored and GitHub committed 2022-04-06 10:20:30 -07:00
1 parent d340ee62bb
commit d1ffd1edae
23 files changed
+719 -205

No files matched your search

+57 -31
View File
@@ -12,6 +12,7 @@ import { v5 as uuidv5 } from "uuid";
import { getBusyCalendarTimes } from "@calcom/core/CalendarManager";
import EventManager from "@calcom/core/EventManager";
import { getBusyVideoTimes } from "@calcom/core/videoClient";
import { getDefaultEvent, getUsernameList } from "@calcom/lib/defaultEvents";
import { getErrorFromUnknown } from "@calcom/lib/errors";
import logger from "@calcom/lib/logger";
import notEmpty from "@calcom/lib/notEmpty";
@@ -181,30 +182,8 @@ const getUserNameWithBookingCounts = async (eventTypeId: number, selectedUserNam
return userNamesWithBookingCounts;
};
type User = Prisma.UserGetPayload<typeof userSelect>;
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
const reqBody = req.body as BookingCreateBody;
const eventTypeId = reqBody.eventTypeId;
const tAttendees = await getTranslation(reqBody.language ?? "en", "common");
const tGuests = await getTranslation("en", "common");
log.debug(`Booking eventType ${eventTypeId} started`);
const isTimeInPast = (time: string): boolean => {
return dayjs(time).isBefore(new Date(), "day");
};
if (isTimeInPast(reqBody.start)) {
const error = {
errorCode: "BookingDateInPast",
message: "Attempting to create a meeting in the past.",
};
log.error(`Booking ${eventTypeId} failed`, error);
return res.status(400).json(error);
}
const eventType = await prisma.eventType.findUnique({
const getEventTypesFromDB = async (eventTypeId: number) => {
return await prisma.eventType.findUnique({
rejectOnNotFound: true,
where: {
id: eventTypeId,
@@ -235,10 +214,48 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
hideCalendarNotes: true,
},
});
};
type User = Prisma.UserGetPayload<typeof userSelect>;
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
const reqBody = req.body as BookingCreateBody;
// handle dynamic user
const dynamicUserList = getUsernameList(reqBody.user as string);
const eventTypeSlug = reqBody.eventTypeSlug;
const eventTypeId = reqBody.eventTypeId;
const tAttendees = await getTranslation(reqBody.language ?? "en", "common");
const tGuests = await getTranslation("en", "common");
log.debug(`Booking eventType ${eventTypeId} started`);
const isTimeInPast = (time: string): boolean => {
return dayjs(time).isBefore(new Date(), "day");
};
if (isTimeInPast(reqBody.start)) {
const error = {
errorCode: "BookingDateInPast",
message: "Attempting to create a meeting in the past.",
};
log.error(`Booking ${eventTypeId} failed`, error);
return res.status(400).json(error);
}
const eventType = !eventTypeId ? getDefaultEvent(eventTypeSlug) : await getEventTypesFromDB(eventTypeId);
if (!eventType) return res.status(404).json({ message: "eventType.notFound" });
let users = eventType.users;
let users = !eventTypeId
? await prisma.user.findMany({
where: {
username: {
in: dynamicUserList,
},
},
...userSelect,
})
: eventType.users;
/* If this event was pre-relationship migration */
if (!users.length && eventType.userId) {
@@ -340,7 +357,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
},
attendees: attendeesList,
location: reqBody.location, // Will be processed by the EventManager later.
/** For team events, we will need to handle each member destinationCalendar eventually */
/** For team events & dynamic collective events, we will need to handle each member destinationCalendar eventually */
destinationCalendar: eventType.destinationCalendar || users[0].destinationCalendar,
hideCalendarNotes: eventType.hideCalendarNotes,
};
@@ -362,6 +379,17 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
await verifyAccount(web3Details.userSignature, web3Details.userWallet);
}
const eventTypeRel = !eventTypeId
? {}
: {
connect: {
id: eventTypeId,
},
};
const dynamicEventSlugRef = !eventTypeId ? eventTypeSlug : null;
const dynamicGroupSlugRef = !eventTypeId ? (reqBody.user as string).toLowerCase() : null;
return prisma.booking.create({
include: {
user: {
@@ -377,11 +405,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
description: evt.description,
confirmed: (!eventType.requiresConfirmation && !eventType.price) || !!rescheduleUid,
location: evt.location,
eventType: {
connect: {
id: eventTypeId,
},
},
eventType: eventTypeRel,
attendees: {
createMany: {
data: evt.attendees.map((attendee) => {
@@ -397,6 +421,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
}),
},
},
dynamicEventSlugRef,
dynamicGroupSlugRef,
user: {
connect: {
id: users[0].id,