import { CalendarIcon, XIcon, RefreshIcon } from "@heroicons/react/solid"; import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@radix-ui/react-collapsible"; import { GetServerSidePropsContext } from "next"; import { useRouter } from "next/router"; import { useState } from "react"; import dayjs from "@calcom/dayjs"; 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 prisma, { bookingMinimalSelect } from "@calcom/prisma"; import { Button } from "@calcom/ui/Button"; import { TextField } from "@calcom/ui/form/fields"; import { asStringOrUndefined } from "@lib/asStringOrNull"; import { getSession } from "@lib/auth"; import { collectPageParameters, telemetryEventTypes, useTelemetry } from "@lib/telemetry"; import { detectBrowserTimeFormat } from "@lib/timeFormat"; import { inferSSRProps } from "@lib/types/inferSSRProps"; import CustomBranding from "@components/CustomBranding"; import { HeadSeo } from "@components/seo/head-seo"; import { ssrInit } from "@server/lib/ssr"; export default function Type(props: inferSSRProps) { const { t } = useLocale(); // Get router variables const router = useRouter(); const { uid } = 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 booking = await prisma.booking.findUnique({ where: { uid: asStringOrUndefined(context.query.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) { recurringInstances = await prisma.booking.findMany({ where: { recurringEventId: booking.recurringEventId, }, 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(), }, }; };