fix/google-calendar-removes-attendees-when-seats-5336 (#5366)
* Adding missing code that copied booking attendees to event attendees * Clean up code * Fix types * Fix types * Doing deep clone for sending seats email
This commit is contained in:
1 parent
7517feb62a
commit
dff08dc5b9
9 files changed
+57
-30
No files matched your search
@@ -7,6 +7,7 @@ import {
|
||||
WebhookTriggerEvents,
|
||||
} from "@prisma/client";
|
||||
import async from "async";
|
||||
import { cloneDeep } from "lodash";
|
||||
import type { NextApiRequest } from "next";
|
||||
import { RRule } from "rrule";
|
||||
import short from "short-uuid";
|
||||
@@ -482,8 +483,9 @@ async function handler(req: NextApiRequest & { userId?: number | undefined }) {
|
||||
|
||||
// For seats, if the booking already exists then we want to add the new attendee to the existing booking
|
||||
if (reqBody.bookingUid) {
|
||||
if (!eventType.seatsPerTimeSlot)
|
||||
if (!eventType.seatsPerTimeSlot) {
|
||||
throw new HttpError({ statusCode: 404, message: "Event type does not have seats" });
|
||||
}
|
||||
|
||||
const booking = await prisma.booking.findUnique({
|
||||
where: {
|
||||
@@ -505,7 +507,9 @@ async function handler(req: NextApiRequest & { userId?: number | undefined }) {
|
||||
},
|
||||
},
|
||||
});
|
||||
if (!booking) throw new HttpError({ statusCode: 404, message: "Booking not found" });
|
||||
if (!booking) {
|
||||
throw new HttpError({ statusCode: 404, message: "Booking not found" });
|
||||
}
|
||||
|
||||
// Need to add translation for attendees to pass type checks. Since these values are never written to the db we can just use the new attendee language
|
||||
const bookingAttendees = booking.attendees.map((attendee) => {
|
||||
@@ -514,11 +518,13 @@ async function handler(req: NextApiRequest & { userId?: number | undefined }) {
|
||||
|
||||
evt = { ...evt, attendees: [...bookingAttendees, invitee[0]] };
|
||||
|
||||
if (eventType.seatsPerTimeSlot <= booking.attendees.length)
|
||||
if (eventType.seatsPerTimeSlot <= booking.attendees.length) {
|
||||
throw new HttpError({ statusCode: 409, message: "Booking seats are full" });
|
||||
}
|
||||
|
||||
if (booking.attendees.some((attendee) => attendee.email === invitee[0].email))
|
||||
if (booking.attendees.find((attendee) => attendee.email === invitee[0].email)) {
|
||||
throw new HttpError({ statusCode: 409, message: "Already signed up for time slot" });
|
||||
}
|
||||
|
||||
await prisma.booking.update({
|
||||
where: {
|
||||
@@ -537,8 +543,13 @@ async function handler(req: NextApiRequest & { userId?: number | undefined }) {
|
||||
});
|
||||
|
||||
const newSeat = booking.attendees.length !== 0;
|
||||
|
||||
await sendScheduledSeatsEmails(evt, invitee[0], newSeat, !!eventType.seatsShowAttendees);
|
||||
/**
|
||||
* Remember objects are passed into functions as references
|
||||
* so if you modify it in a inner function it will be modified in the outer function
|
||||
* deep cloning evt to avoid this
|
||||
*/
|
||||
const copyEvent = cloneDeep(evt);
|
||||
await sendScheduledSeatsEmails(copyEvent, invitee[0], newSeat, !!eventType.seatsShowAttendees);
|
||||
|
||||
const credentials = await refreshCredentials(organizerUser.credentials);
|
||||
const eventManager = new EventManager({ ...organizerUser, credentials });
|
||||
|
||||
@@ -5,9 +5,9 @@ import { FixedSizeList as List } from "react-window";
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import { CAL_URL } from "@calcom/lib/constants";
|
||||
import { inferQueryOutput, trpc } from "@calcom/trpc/react";
|
||||
import { Avatar } from "@calcom/ui/components/avatar";
|
||||
import Select from "@calcom/ui/form/Select";
|
||||
import TimezoneSelect, { ITimezone } from "@calcom/ui/form/TimezoneSelect";
|
||||
import { Avatar } from "@calcom/ui/components/avatar";
|
||||
import DatePicker from "@calcom/ui/v2/core/form/DatePicker";
|
||||
|
||||
import TeamAvailabilityTimes from "./TeamAvailabilityTimes";
|
||||
|
||||
@@ -5,9 +5,9 @@ import { FixedSizeList as List } from "react-window";
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import { CAL_URL } from "@calcom/lib/constants";
|
||||
import { inferQueryOutput, trpc } from "@calcom/trpc/react";
|
||||
import { Avatar } from "@calcom/ui/components/avatar";
|
||||
import Select from "@calcom/ui/form/Select";
|
||||
import TimezoneSelect, { ITimezone } from "@calcom/ui/form/TimezoneSelect";
|
||||
import { Avatar } from "@calcom/ui/components/avatar";
|
||||
import DatePicker from "@calcom/ui/v2/core/form/DatePicker";
|
||||
|
||||
import TeamAvailabilityTimes from "./TeamAvailabilityTimes";
|
||||
|
||||
@@ -6,8 +6,8 @@ import { HttpError } from "@calcom/lib/http-error";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import { Dialog, DialogClose, DialogContent, DialogTrigger } from "@calcom/ui/Dialog";
|
||||
import { Icon } from "@calcom/ui/Icon";
|
||||
import { Form } from "@calcom/ui/form/fields";
|
||||
import { Button } from "@calcom/ui/components/button";
|
||||
import { Form } from "@calcom/ui/form/fields";
|
||||
import showToast from "@calcom/ui/v2/core/notifications";
|
||||
|
||||
export function NewScheduleButton({ name = "new-schedule" }: { name?: string }) {
|
||||
|
||||
@@ -5,8 +5,8 @@ import { WEBAPP_URL } from "@calcom/lib/constants";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import { Icon } from "@calcom/ui";
|
||||
import { EmptyScreen, SkeletonText } from "@calcom/ui/v2";
|
||||
import { Button } from "@calcom/ui/components/button";
|
||||
import { EmptyScreen, SkeletonText } from "@calcom/ui/v2";
|
||||
import Meta from "@calcom/ui/v2/core/Meta";
|
||||
import { getLayout } from "@calcom/ui/v2/core/layouts/SettingsLayout";
|
||||
|
||||
|
||||
Reference in new issue
Block a user