fix cancelled bookings error

pull/434/head
joshsny 2021-08-10 10:46:02 +02:00
parent 7874e17b1c
commit 747d8f56d3
1 changed files with 59 additions and 50 deletions

View File

@ -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 { CalendarIcon, ClockIcon, XIcon } from "@heroicons/react/solid";
import isSameOrBefore from "dayjs/plugin/isSameOrBefore"; import dayjs from "dayjs";
import isBetween from "dayjs/plugin/isBetween"; 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 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"; import { collectPageParameters, telemetryEventTypes, useTelemetry } from "../../lib/telemetry";
dayjs.extend(isSameOrBefore); dayjs.extend(isSameOrBefore);
@ -23,7 +23,7 @@ export default function Type(props) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
const [is24h, setIs24h] = useState(false); const [is24h, setIs24h] = useState(false);
const [loading, setLoading] = 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(); const telemetry = useTelemetry();
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
@ -57,7 +57,8 @@ export default function Type(props) {
<div> <div>
<Head> <Head>
<title> <title>
Cancel {props.booking.title} | {props.user.name || props.user.username} | Calendso Cancel {props.booking && `${props.booking.title} | ${props.user.name || props.user.username} `}|
Calendso
</title> </title>
<link rel="icon" href="/favicon.ico" /> <link rel="icon" href="/favicon.ico" />
</Head> </Head>
@ -86,6 +87,7 @@ export default function Type(props) {
</div> </div>
)} )}
{!error && ( {!error && (
<>
<div> <div>
<div className="mx-auto flex items-center justify-center h-12 w-12 rounded-full bg-red-100"> <div className="mx-auto flex items-center justify-center h-12 w-12 rounded-full bg-red-100">
<XIcon className="h-6 w-6 text-red-600" /> <XIcon className="h-6 w-6 text-red-600" />
@ -112,7 +114,6 @@ export default function Type(props) {
</div> </div>
</div> </div>
</div> </div>
)}
<div className="mt-5 sm:mt-6 text-center"> <div className="mt-5 sm:mt-6 text-center">
<div className="mt-5"> <div className="mt-5">
<button <button
@ -131,6 +132,8 @@ export default function Type(props) {
</button> </button>
</div> </div>
</div> </div>
</>
)}
</div> </div>
</div> </div>
</div> </div>
@ -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) // Workaround since Next.js has problems serializing date objects (see https://github.com/vercel/next.js/issues/11993)
const bookingObj = Object.assign({}, booking, { const bookingObj = Object.assign({}, booking, {
startTime: booking.startTime.toString(), startTime: booking.startTime.toString(),