Fixes 3 issues related to 404 links (#2979)

pull/2986/head
Hariom Balhara 2022-06-06 15:10:56 +05:30 committed by GitHub
parent dd09854932
commit 03e787ad5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 9 deletions

View File

@ -204,7 +204,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,

View File

@ -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";
@ -667,7 +668,7 @@ function RecurringBookings({
}
const getEventTypesFromDB = async (id: number) => {
return await prisma.eventType.findUnique({
const eventType = await prisma.eventType.findUnique({
where: {
id,
},
@ -705,6 +706,15 @@ const getEventTypesFromDB = async (id: number) => {
metadata: true,
},
});
if (!eventType) {
return eventType;
}
return {
isDynamic: false,
...eventType,
};
};
const strToNumber = z.string().transform((val, ctx) => {
@ -743,7 +753,6 @@ export async function getServerSideProps(context: GetServerSidePropsContext) {
} = parsedQuery.data;
const eventTypeRaw = !eventTypeId ? getDefaultEvent(eventTypeSlug) : await getEventTypesFromDB(eventTypeId);
if (!eventTypeRaw) {
return {
notFound: true,
@ -807,13 +816,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,

View File

@ -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 */,

View File

@ -31,6 +31,7 @@ type UsernameSlugLinkProps = {
const customInputs: EventTypeCustomInput[] = [];
const commons = {
isDynamic: true,
periodCountCalendarDays: true,
periodStartDate: null,
periodEndDate: null,