import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@radix-ui/react-collapsible"; import { GetServerSidePropsContext } from "next"; import { useRouter } from "next/router"; import { useState } from "react"; import z from "zod"; import dayjs from "@calcom/dayjs"; import CustomBranding from "@calcom/lib/CustomBranding"; import classNames from "@calcom/lib/classNames"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { parseRecurringEvent } from "@calcom/lib/isRecurringEvent"; import { getEveryFreqFor } from "@calcom/lib/recurringStrings"; import { collectPageParameters, telemetryEventTypes, useTelemetry } from "@calcom/lib/telemetry"; import { detectBrowserTimeFormat } from "@calcom/lib/timeFormat"; import prisma, { bookingMinimalSelect } from "@calcom/prisma"; import { Button } from "@calcom/ui/Button"; import { Icon } from "@calcom/ui/Icon"; import { TextField } from "@calcom/ui/form/fields"; import { getSession } from "@lib/auth"; import { inferSSRProps } from "@lib/types/inferSSRProps"; import { HeadSeo } from "@components/seo/head-seo"; import { ssrInit } from "@server/lib/ssr"; const querySchema = z.object({ uid: z.string(), allRemainingBookings: z .string() .optional() .transform((val) => (val ? JSON.parse(val) : false)), }); export default function Type(props: inferSSRProps) { const { t } = useLocale(); // Get router variables const router = useRouter(); const { uid, allRemainingBookings } = querySchema.parse(router.query); const [loading, setLoading] = useState(false); const [error, setError] = useState(props.booking ? null : t("booking_already_cancelled")); const [cancellationReason, setCancellationReason] = useState(""); const [moreEventsVisible, setMoreEventsVisible] = useState(false); const telemetry = useTelemetry(); return (
); } export const getServerSideProps = async (context: GetServerSidePropsContext) => { const ssr = await ssrInit(context); const session = await getSession(context); const { allRemainingBookings, uid } = querySchema.parse(context.query); const booking = await prisma.booking.findUnique({ where: { uid, }, select: { ...bookingMinimalSelect, recurringEventId: true, user: { select: { id: true, username: true, name: true, brandColor: true, darkBrandColor: true, }, }, eventType: { select: { length: true, recurringEvent: true, team: { select: { slug: true, name: true, }, }, }, }, }, }); if (!booking) { // TODO: Booking is already cancelled return { props: { booking: null }, }; } const bookingObj = Object.assign({}, booking, { startTime: booking.startTime.toString(), endTime: booking.endTime.toString(), eventType: { ...booking.eventType, recurringEvent: parseRecurringEvent(booking.eventType?.recurringEvent), }, }); let recurringInstances = null; if (booking.eventType?.recurringEvent && allRemainingBookings) { recurringInstances = await prisma.booking.findMany({ where: { recurringEventId: booking.recurringEventId, startTime: { gte: new Date(), }, NOT: [{ status: "CANCELLED" }, { status: "REJECTED" }], }, select: { startTime: true, endTime: true, }, }); recurringInstances = recurringInstances.map((recurr) => ({ ...recurr, startTime: recurr.startTime.toString(), endTime: recurr.endTime.toString(), })); } const profile = { name: booking.eventType?.team?.name || booking.user?.name || null, slug: booking.eventType?.team?.slug || booking.user?.username || null, brandColor: booking.user?.brandColor || null, darkBrandColor: booking.user?.darkBrandColor || null, }; return { props: { profile, booking: bookingObj, recurringInstances, cancellationAllowed: (!!session?.user && session.user?.id === booking.user?.id) || booking.startTime >= new Date(), trpcState: ssr.dehydrate(), }, }; };