From 747d8f56d3e77b9a82f734c38c2cea3767337031 Mon Sep 17 00:00:00 2001 From: joshsny Date: Tue, 10 Aug 2021 10:46:02 +0200 Subject: [PATCH] fix cancelled bookings error --- pages/cancel/[uid].tsx | 109 ++++++++++++++++++++++------------------- 1 file changed, 59 insertions(+), 50 deletions(-) diff --git a/pages/cancel/[uid].tsx b/pages/cancel/[uid].tsx index 06af00d123..2e9d1fa5f7 100644 --- a/pages/cancel/[uid].tsx +++ b/pages/cancel/[uid].tsx @@ -1,13 +1,13 @@ -import { useState } from "react"; -import Head from "next/head"; -import prisma from "../../lib/prisma"; -import { useRouter } from "next/router"; -import dayjs from "dayjs"; import { CalendarIcon, ClockIcon, XIcon } from "@heroicons/react/solid"; -import isSameOrBefore from "dayjs/plugin/isSameOrBefore"; +import dayjs from "dayjs"; import isBetween from "dayjs/plugin/isBetween"; -import utc from "dayjs/plugin/utc"; +import isSameOrBefore from "dayjs/plugin/isSameOrBefore"; import timezone from "dayjs/plugin/timezone"; +import utc from "dayjs/plugin/utc"; +import Head from "next/head"; +import { useRouter } from "next/router"; +import { useState } from "react"; +import prisma from "../../lib/prisma"; import { collectPageParameters, telemetryEventTypes, useTelemetry } from "../../lib/telemetry"; dayjs.extend(isSameOrBefore); @@ -23,7 +23,7 @@ export default function Type(props) { // eslint-disable-next-line @typescript-eslint/no-unused-vars const [is24h, setIs24h] = useState(false); const [loading, setLoading] = useState(false); - const [error, setError] = useState(null); + const [error, setError] = useState(props.booking ? null : "This booking was already cancelled"); const telemetry = useTelemetry(); // eslint-disable-next-line @typescript-eslint/no-unused-vars @@ -57,7 +57,8 @@ export default function Type(props) {
- Cancel {props.booking.title} | {props.user.name || props.user.username} | Calendso + Cancel {props.booking && `${props.booking.title} | ${props.user.name || props.user.username} `}| + Calendso @@ -86,51 +87,53 @@ export default function Type(props) {
)} {!error && ( -
-
- -
-
- -
-

Instead, you could also reschedule it.

+ <> +
+
+
-
-

{props.booking.title}

-

- - {props.eventType.length} minutes -

-

- - {dayjs - .utc(props.booking.startTime) - .format((is24h ? "H:mm" : "h:mma") + ", dddd DD MMMM YYYY")} -

+
+ +
+

Instead, you could also reschedule it.

+
+
+

{props.booking.title}

+

+ + {props.eventType.length} minutes +

+

+ + {dayjs + .utc(props.booking.startTime) + .format((is24h ? "H:mm" : "h:mma") + ", dddd DD MMMM YYYY")} +

+
-
+
+
+ + +
+
+ )} -
-
- - -
-
@@ -163,6 +166,12 @@ export async function getServerSideProps(context) { }, }); + if (!booking) { + return { + props: { booking: null }, + }; + } + // Workaround since Next.js has problems serializing date objects (see https://github.com/vercel/next.js/issues/11993) const bookingObj = Object.assign({}, booking, { startTime: booking.startTime.toString(),