import Head from "next/head"; import prisma from "../../lib/prisma"; import { getSession, useSession } from "next-auth/client"; import Shell from "../../components/Shell"; import { useRouter } from "next/router"; export default function Bookings({ bookings }) { const [, loading] = useSession(); const router = useRouter(); if (loading) { return

Loading...

; } async function confirmBookingHandler(booking, confirm: boolean) { const res = await fetch("/api/book/confirm", { method: "PATCH", body: JSON.stringify({ id: booking.id, confirmed: confirm }), headers: { "Content-Type": "application/json", }, }); if (res.ok) { await router.replace(router.asPath); } } return (
Bookings | Calendso
{/* */} {bookings .filter((booking) => !booking.confirmed && !booking.rejected) .concat(bookings.filter((booking) => booking.confirmed || booking.rejected)) .map((booking) => ( {/* */} ))}
Person Event Date Actions
{!booking.confirmed && !booking.rejected && ( Unconfirmed )}
{booking.attendees[0].name}
{booking.attendees[0].email}
{booking.title}
{booking.description}
{dayjs(booking.startTime).format("D MMMM YYYY HH:mm")}
{!booking.confirmed && !booking.rejected && ( <> confirmBookingHandler(booking, true)} className="cursor-pointer text-blue-600 hover:text-blue-900"> Confirm confirmBookingHandler(booking, false)} className="cursor-pointer ml-4 text-blue-600 hover:text-blue-900"> Reject )} {booking.confirmed && !booking.rejected && ( <> Reschedule Cancel )} {!booking.confirmed && booking.rejected && (
Rejected
)}
); } export async function getServerSideProps(context) { const session = await getSession(context); if (!session) { return { redirect: { permanent: false, destination: "/auth/login" } }; } const user = await prisma.user.findFirst({ where: { email: session.user.email, }, select: { id: true, }, }); const bookings = await prisma.booking.findMany({ where: { userId: user.id, }, select: { uid: true, title: true, description: true, attendees: true, confirmed: true, rejected: true, id: true, }, orderBy: { startTime: "desc", }, }); return { props: { bookings } }; }