Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/web/components/booking/BookingListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ function BookingListItem(booking: BookingItemProps) {
pathname: "/success",
query: {
date: booking.startTime,
type: booking.eventType.id,
// TODO: Booking when fetched should have id 0 already(for Dynamic Events).
type: booking.eventType.id || 0,
eventSlug: booking.eventType.slug,
user: user?.username || "",
name: booking.attendees[0] ? booking.attendees[0].name : undefined,
Expand Down
38 changes: 30 additions & 8 deletions apps/web/pages/success.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
import { getDefaultEvent } from "@calcom/lib/defaultEvents";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { localStorage } from "@calcom/lib/webstorage";
import { Prisma } from "@calcom/prisma/client";
import { RecurringEvent } from "@calcom/types/Calendar";
import Button from "@calcom/ui/Button";
import { EmailInput } from "@calcom/ui/form/fields";
Expand Down Expand Up @@ -665,7 +666,7 @@ function RecurringBookings({
}

const getEventTypesFromDB = async (id: number) => {
return await prisma.eventType.findUnique({
const eventType = await prisma.eventType.findUnique({
where: {
id,
},
Expand Down Expand Up @@ -703,6 +704,15 @@ const getEventTypesFromDB = async (id: number) => {
metadata: true,
},
});

if (!eventType) {
return eventType;
}

return {
isDynamic: false,
...eventType,
};
};

const strToNumber = z.string().transform((val, ctx) => {
Expand Down Expand Up @@ -741,7 +751,6 @@ export async function getServerSideProps(context: GetServerSidePropsContext) {
} = parsedQuery.data;

const eventTypeRaw = !eventTypeId ? getDefaultEvent(eventTypeSlug) : await getEventTypesFromDB(eventTypeId);

if (!eventTypeRaw) {
return {
notFound: true,
Expand Down Expand Up @@ -805,13 +814,26 @@ export async function getServerSideProps(context: GetServerSidePropsContext) {
slug: eventType.team?.slug || eventType.users[0]?.username || null,
};

const where: Prisma.BookingWhereInput = {
id: bookingId,
attendees: { some: { email, name } },
};
// Dynamic Event uses EventType from @calcom/lib/defaultEvents(a fake EventType) which doesn't have a real user/team/eventTypeId
// So, you can't look them up in DB.
if (!eventType.isDynamic) {
// A Team Event doesn't have a correct user query param as of now. It is equal to team/{eventSlug} which is not a user, so you can't look it up in DB.
if (!eventType.team) {
// username being equal to profile.slug isn't applicable for Team or Dynamic Events.
where.user = { username };
}
where.eventTypeId = eventType.id;
} else {
// username being equal to eventSlug for Dynamic Event Booking, it can't be used for user lookup. So, just use eventTypeId which would always be null for Dynamic Event Bookings
where.eventTypeId = null;
}

const bookingInfo = await prisma.booking.findFirst({
where: {
id: bookingId,
eventTypeId: eventType.id,
user: { username },
attendees: { some: { email, name } },
},
where,
select: {
title: true,
uid: true,
Expand Down
1 change: 1 addition & 0 deletions apps/web/pages/team/[slug]/book.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export async function getServerSideProps(context: GetServerSidePropsContext) {
locationLabels: getLocationLabels(t),
profile: {
...eventTypeObject.team,
// FIXME: This slug is used as username on success page which is wrong. This is correctly set as username for user booking.
slug: "team/" + eventTypeObject.slug,
image: eventTypeObject.team?.logo || null,
theme: null /* Teams don't have a theme, and `BookingPage` uses it */,
Expand Down
1 change: 1 addition & 0 deletions packages/lib/defaultEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type UsernameSlugLinkProps = {
const customInputs: EventTypeCustomInput[] = [];

const commons = {
isDynamic: true,
periodCountCalendarDays: true,
periodStartDate: null,
periodEndDate: null,
Expand Down