| 
									
										
										
										
											2021-08-27 12:35:20 +00:00
										 |  |  | import prisma from "@lib/prisma"; | 
					
						
							| 
									
										
										
										
											2021-09-03 20:51:21 +00:00
										 |  |  | import { useSession } from "next-auth/client"; | 
					
						
							| 
									
										
										
										
											2021-08-27 12:35:20 +00:00
										 |  |  | import Shell from "@components/Shell"; | 
					
						
							| 
									
										
										
										
											2021-07-17 12:30:29 +00:00
										 |  |  | import { useRouter } from "next/router"; | 
					
						
							| 
									
										
										
										
											2021-08-03 00:22:17 +00:00
										 |  |  | import dayjs from "dayjs"; | 
					
						
							| 
									
										
										
										
											2021-08-03 08:34:43 +00:00
										 |  |  | import { Fragment } from "react"; | 
					
						
							| 
									
										
										
										
											2021-09-14 08:20:24 +00:00
										 |  |  | // TODO: replace headlessui with radix-ui
 | 
					
						
							| 
									
										
										
										
											2021-08-03 08:34:43 +00:00
										 |  |  | import { Menu, Transition } from "@headlessui/react"; | 
					
						
							|  |  |  | import { DotsHorizontalIcon } from "@heroicons/react/solid"; | 
					
						
							|  |  |  | import classNames from "@lib/classNames"; | 
					
						
							| 
									
										
										
										
											2021-09-17 19:25:23 +00:00
										 |  |  | import { ClockIcon, XIcon, CheckIcon, BanIcon } from "@heroicons/react/outline"; | 
					
						
							| 
									
										
										
										
											2021-08-08 20:31:08 +00:00
										 |  |  | import Loader from "@components/Loader"; | 
					
						
							| 
									
										
										
										
											2021-09-14 08:45:28 +00:00
										 |  |  | import { Button } from "@components/ui/Button"; | 
					
						
							| 
									
										
										
										
											2021-09-03 20:51:21 +00:00
										 |  |  | import { getSession } from "@lib/auth"; | 
					
						
							| 
									
										
										
										
											2021-09-15 15:47:49 +00:00
										 |  |  | import { BookingStatus, User } from "@prisma/client"; | 
					
						
							| 
									
										
										
										
											2021-06-24 13:36:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | export default function Bookings({ bookings }) { | 
					
						
							| 
									
										
										
										
											2021-08-03 10:29:51 +00:00
										 |  |  |   // eslint-disable-next-line @typescript-eslint/no-unused-vars
 | 
					
						
							| 
									
										
										
										
											2021-08-03 09:09:15 +00:00
										 |  |  |   const [session, loading] = useSession(); | 
					
						
							| 
									
										
										
										
											2021-08-03 10:29:51 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-17 12:30:29 +00:00
										 |  |  |   const router = useRouter(); | 
					
						
							| 
									
										
										
										
											2021-06-24 13:36:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (loading) { | 
					
						
							| 
									
										
										
										
											2021-08-08 20:31:08 +00:00
										 |  |  |     return <Loader />; | 
					
						
							| 
									
										
										
										
											2021-06-24 13:36:31 +00:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-17 12:30:29 +00:00
										 |  |  |   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); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-24 13:36:31 +00:00
										 |  |  |   return ( | 
					
						
							|  |  |  |     <div> | 
					
						
							| 
									
										
										
										
											2021-08-02 14:10:24 +00:00
										 |  |  |       <Shell heading="Bookings" subtitle="See upcoming and past events booked through your event type links."> | 
					
						
							| 
									
										
										
										
											2021-08-02 16:54:27 +00:00
										 |  |  |         <div className="-mx-4 sm:mx-auto flex flex-col"> | 
					
						
							| 
									
										
										
										
											2021-06-24 13:36:31 +00:00
										 |  |  |           <div className="-my-2 overflow-x-auto sm:-mx-6 lg:-mx-8"> | 
					
						
							|  |  |  |             <div className="py-2 align-middle inline-block min-w-full sm:px-6 lg:px-8"> | 
					
						
							| 
									
										
										
										
											2021-08-05 11:36:24 +00:00
										 |  |  |               <div className="border border-gray-200 overflow-hidden border-b rounded-sm"> | 
					
						
							| 
									
										
										
										
											2021-06-24 13:36:31 +00:00
										 |  |  |                 <table className="min-w-full divide-y divide-gray-200"> | 
					
						
							| 
									
										
										
										
											2021-09-14 08:45:28 +00:00
										 |  |  |                   <tbody className="bg-white divide-y divide-gray-200" data-testid="bookings"> | 
					
						
							| 
									
										
										
										
											2021-07-17 12:30:29 +00:00
										 |  |  |                     {bookings | 
					
						
							| 
									
										
										
										
											2021-09-13 08:57:56 +00:00
										 |  |  |                       .filter((booking) => booking.status !== BookingStatus.CANCELLED) | 
					
						
							| 
									
										
										
										
											2021-07-17 12:30:29 +00:00
										 |  |  |                       .map((booking) => ( | 
					
						
							|  |  |  |                         <tr key={booking.id}> | 
					
						
							| 
									
										
										
										
											2021-08-02 16:54:27 +00:00
										 |  |  |                           <td className={"px-6 py-4" + (booking.rejected ? " line-through" : "")}> | 
					
						
							| 
									
										
										
										
											2021-07-17 12:30:29 +00:00
										 |  |  |                             {!booking.confirmed && !booking.rejected && ( | 
					
						
							| 
									
										
										
										
											2021-08-12 13:55:09 +00:00
										 |  |  |                               <span className="mb-2 inline-flex items-center px-1.5 py-0.5 rounded-sm text-xs font-medium bg-yellow-100 text-yellow-800"> | 
					
						
							| 
									
										
										
										
											2021-07-17 12:30:29 +00:00
										 |  |  |                                 Unconfirmed | 
					
						
							|  |  |  |                               </span> | 
					
						
							|  |  |  |                             )} | 
					
						
							| 
									
										
										
										
											2021-08-03 09:09:15 +00:00
										 |  |  |                             <div className="text-sm text-neutral-900 font-medium  truncate max-w-60 md:max-w-96"> | 
					
						
							| 
									
										
										
										
											2021-09-15 14:27:55 +00:00
										 |  |  |                               {booking.eventType?.team && <strong>{booking.eventType.team.name}: </strong>} | 
					
						
							| 
									
										
										
										
											2021-08-03 09:32:37 +00:00
										 |  |  |                               {booking.title} | 
					
						
							| 
									
										
										
										
											2021-08-02 16:54:27 +00:00
										 |  |  |                             </div> | 
					
						
							| 
									
										
										
										
											2021-08-03 08:47:01 +00:00
										 |  |  |                             <div className="sm:hidden"> | 
					
						
							|  |  |  |                               <div className="text-sm text-gray-900"> | 
					
						
							|  |  |  |                                 {dayjs(booking.startTime).format("D MMMM YYYY")}:{" "} | 
					
						
							|  |  |  |                                 <small className="text-sm text-gray-500"> | 
					
						
							|  |  |  |                                   {dayjs(booking.startTime).format("HH:mm")} -{" "} | 
					
						
							|  |  |  |                                   {dayjs(booking.endTime).format("HH:mm")} | 
					
						
							|  |  |  |                                 </small> | 
					
						
							|  |  |  |                               </div> | 
					
						
							|  |  |  |                             </div> | 
					
						
							| 
									
										
										
										
											2021-09-13 08:57:56 +00:00
										 |  |  |                             {booking.attendees.length !== 0 && ( | 
					
						
							|  |  |  |                               <div className="text-sm text-blue-500"> | 
					
						
							|  |  |  |                                 <a href={"mailto:" + booking.attendees[0].email}> | 
					
						
							|  |  |  |                                   {booking.attendees[0].email} | 
					
						
							|  |  |  |                                 </a> | 
					
						
							|  |  |  |                               </div> | 
					
						
							|  |  |  |                             )} | 
					
						
							| 
									
										
										
										
											2021-07-17 12:30:29 +00:00
										 |  |  |                           </td> | 
					
						
							| 
									
										
										
										
											2021-08-03 08:47:01 +00:00
										 |  |  |                           <td className="hidden sm:table-cell px-6 py-4 whitespace-nowrap"> | 
					
						
							| 
									
										
										
										
											2021-08-03 00:22:17 +00:00
										 |  |  |                             <div className="text-sm text-gray-900"> | 
					
						
							|  |  |  |                               {dayjs(booking.startTime).format("D MMMM YYYY")} | 
					
						
							|  |  |  |                             </div> | 
					
						
							|  |  |  |                             <div className="text-sm text-gray-500"> | 
					
						
							| 
									
										
										
										
											2021-08-03 08:30:35 +00:00
										 |  |  |                               {dayjs(booking.startTime).format("HH:mm")} -{" "} | 
					
						
							|  |  |  |                               {dayjs(booking.endTime).format("HH:mm")} | 
					
						
							| 
									
										
										
										
											2021-08-03 00:22:17 +00:00
										 |  |  |                             </div> | 
					
						
							| 
									
										
										
										
											2021-08-03 08:30:35 +00:00
										 |  |  |                           </td> | 
					
						
							| 
									
										
										
										
											2021-07-17 12:30:29 +00:00
										 |  |  |                           <td className="px-6 py-4 whitespace-nowrap text-right text-sm font-medium"> | 
					
						
							|  |  |  |                             {!booking.confirmed && !booking.rejected && ( | 
					
						
							|  |  |  |                               <> | 
					
						
							| 
									
										
										
										
											2021-09-17 19:25:23 +00:00
										 |  |  |                                 <div className="space-x-2 hidden lg:block"> | 
					
						
							|  |  |  |                                   <Button | 
					
						
							|  |  |  |                                     onClick={() => confirmBookingHandler(booking, true)} | 
					
						
							|  |  |  |                                     StartIcon={CheckIcon} | 
					
						
							|  |  |  |                                     color="secondary"> | 
					
						
							|  |  |  |                                     Confirm | 
					
						
							|  |  |  |                                   </Button> | 
					
						
							|  |  |  |                                   <Button | 
					
						
							|  |  |  |                                     onClick={() => confirmBookingHandler(booking, false)} | 
					
						
							|  |  |  |                                     StartIcon={BanIcon} | 
					
						
							|  |  |  |                                     color="secondary"> | 
					
						
							|  |  |  |                                     Reject | 
					
						
							|  |  |  |                                   </Button> | 
					
						
							|  |  |  |                                 </div> | 
					
						
							|  |  |  |                                 <Menu as="div" className="inline-block lg:hidden text-left "> | 
					
						
							|  |  |  |                                   {({ open }) => ( | 
					
						
							|  |  |  |                                     <> | 
					
						
							|  |  |  |                                       <div> | 
					
						
							|  |  |  |                                         <Menu.Button className="text-neutral-400 mt-1 p-2 border border-transparent hover:border-gray-200"> | 
					
						
							|  |  |  |                                           <span className="sr-only">Open options</span> | 
					
						
							|  |  |  |                                           <DotsHorizontalIcon className="h-5 w-5" aria-hidden="true" /> | 
					
						
							|  |  |  |                                         </Menu.Button> | 
					
						
							|  |  |  |                                       </div> | 
					
						
							|  |  |  |                                       <Transition | 
					
						
							|  |  |  |                                         show={open} | 
					
						
							|  |  |  |                                         as={Fragment} | 
					
						
							|  |  |  |                                         enter="transition ease-out duration-100" | 
					
						
							|  |  |  |                                         enterFrom="transform opacity-0 scale-95" | 
					
						
							|  |  |  |                                         enterTo="transform opacity-100 scale-100" | 
					
						
							|  |  |  |                                         leave="transition ease-in duration-75" | 
					
						
							|  |  |  |                                         leaveFrom="transform opacity-100 scale-100" | 
					
						
							|  |  |  |                                         leaveTo="transform opacity-0 scale-95"> | 
					
						
							|  |  |  |                                         <Menu.Items | 
					
						
							|  |  |  |                                           static | 
					
						
							|  |  |  |                                           className="origin-top-right absolute right-0 mt-2 w-56 rounded-sm shadow-lg bg-white ring-1 ring-black ring-opacity-5 focus:outline-none divide-y divide-neutral-100"> | 
					
						
							|  |  |  |                                           <div className="py-1"> | 
					
						
							|  |  |  |                                             <Menu.Item> | 
					
						
							|  |  |  |                                               {({ active }) => ( | 
					
						
							|  |  |  |                                                 <span | 
					
						
							|  |  |  |                                                   onClick={() => confirmBookingHandler(booking, true)} | 
					
						
							|  |  |  |                                                   className={classNames( | 
					
						
							|  |  |  |                                                     active | 
					
						
							|  |  |  |                                                       ? "bg-neutral-100 text-neutral-900" | 
					
						
							|  |  |  |                                                       : "text-neutral-700", | 
					
						
							|  |  |  |                                                     "group flex items-center px-4 py-2 text-sm font-medium" | 
					
						
							|  |  |  |                                                   )}> | 
					
						
							|  |  |  |                                                   <CheckIcon | 
					
						
							|  |  |  |                                                     className="mr-3 h-5 w-5 text-neutral-400 group-hover:text-neutral-500" | 
					
						
							|  |  |  |                                                     aria-hidden="true" | 
					
						
							|  |  |  |                                                   /> | 
					
						
							|  |  |  |                                                   Confirm | 
					
						
							|  |  |  |                                                 </span> | 
					
						
							|  |  |  |                                               )} | 
					
						
							|  |  |  |                                             </Menu.Item> | 
					
						
							|  |  |  |                                             <Menu.Item> | 
					
						
							|  |  |  |                                               {({ active }) => ( | 
					
						
							|  |  |  |                                                 <span | 
					
						
							|  |  |  |                                                   onClick={() => confirmBookingHandler(booking, false)} | 
					
						
							|  |  |  |                                                   className={classNames( | 
					
						
							|  |  |  |                                                     active | 
					
						
							|  |  |  |                                                       ? "bg-neutral-100 text-neutral-900" | 
					
						
							|  |  |  |                                                       : "text-neutral-700", | 
					
						
							|  |  |  |                                                     "group flex items-center px-4 py-2 text-sm w-full font-medium" | 
					
						
							|  |  |  |                                                   )}> | 
					
						
							|  |  |  |                                                   <BanIcon | 
					
						
							|  |  |  |                                                     className="mr-3 h-5 w-5 text-neutral-400 group-hover:text-neutral-500" | 
					
						
							|  |  |  |                                                     aria-hidden="true" | 
					
						
							|  |  |  |                                                   /> | 
					
						
							|  |  |  |                                                   Reject | 
					
						
							|  |  |  |                                                 </span> | 
					
						
							|  |  |  |                                               )} | 
					
						
							|  |  |  |                                             </Menu.Item> | 
					
						
							|  |  |  |                                           </div> | 
					
						
							|  |  |  |                                         </Menu.Items> | 
					
						
							|  |  |  |                                       </Transition> | 
					
						
							|  |  |  |                                     </> | 
					
						
							|  |  |  |                                   )} | 
					
						
							|  |  |  |                                 </Menu> | 
					
						
							| 
									
										
										
										
											2021-07-17 12:30:29 +00:00
										 |  |  |                               </> | 
					
						
							|  |  |  |                             )} | 
					
						
							|  |  |  |                             {booking.confirmed && !booking.rejected && ( | 
					
						
							| 
									
										
										
										
											2021-09-17 19:25:23 +00:00
										 |  |  |                               <> | 
					
						
							|  |  |  |                                 <div className="space-x-2 hidden lg:block"> | 
					
						
							|  |  |  |                                   <Button | 
					
						
							|  |  |  |                                     data-testid="cancel" | 
					
						
							|  |  |  |                                     href={"/cancel/" + booking.uid} | 
					
						
							|  |  |  |                                     StartIcon={XIcon} | 
					
						
							|  |  |  |                                     color="secondary"> | 
					
						
							|  |  |  |                                     Cancel | 
					
						
							|  |  |  |                                   </Button> | 
					
						
							|  |  |  |                                   <Button | 
					
						
							|  |  |  |                                     href={"reschedule/" + booking.uid} | 
					
						
							|  |  |  |                                     StartIcon={ClockIcon} | 
					
						
							|  |  |  |                                     color="secondary"> | 
					
						
							|  |  |  |                                     Reschedule | 
					
						
							|  |  |  |                                   </Button> | 
					
						
							|  |  |  |                                 </div> | 
					
						
							| 
									
										
										
										
											2021-08-03 08:34:43 +00:00
										 |  |  |                                 <Menu as="div" className="inline-block lg:hidden text-left "> | 
					
						
							|  |  |  |                                   {({ open }) => ( | 
					
						
							|  |  |  |                                     <> | 
					
						
							|  |  |  |                                       <div> | 
					
						
							| 
									
										
										
										
											2021-08-05 19:03:33 +00:00
										 |  |  |                                         <Menu.Button className="text-neutral-400 mt-1 p-2 border border-transparent hover:border-gray-200"> | 
					
						
							| 
									
										
										
										
											2021-08-03 08:34:43 +00:00
										 |  |  |                                           <span className="sr-only">Open options</span> | 
					
						
							|  |  |  |                                           <DotsHorizontalIcon className="h-5 w-5" aria-hidden="true" /> | 
					
						
							|  |  |  |                                         </Menu.Button> | 
					
						
							|  |  |  |                                       </div> | 
					
						
							| 
									
										
										
										
											2021-08-03 08:30:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-03 08:34:43 +00:00
										 |  |  |                                       <Transition | 
					
						
							|  |  |  |                                         show={open} | 
					
						
							|  |  |  |                                         as={Fragment} | 
					
						
							|  |  |  |                                         enter="transition ease-out duration-100" | 
					
						
							|  |  |  |                                         enterFrom="transform opacity-0 scale-95" | 
					
						
							|  |  |  |                                         enterTo="transform opacity-100 scale-100" | 
					
						
							|  |  |  |                                         leave="transition ease-in duration-75" | 
					
						
							|  |  |  |                                         leaveFrom="transform opacity-100 scale-100" | 
					
						
							|  |  |  |                                         leaveTo="transform opacity-0 scale-95"> | 
					
						
							|  |  |  |                                         <Menu.Items | 
					
						
							|  |  |  |                                           static | 
					
						
							|  |  |  |                                           className="origin-top-right absolute right-0 mt-2 w-56 rounded-sm shadow-lg bg-white ring-1 ring-black ring-opacity-5 focus:outline-none divide-y divide-neutral-100"> | 
					
						
							|  |  |  |                                           <div className="py-1"> | 
					
						
							|  |  |  |                                             <Menu.Item> | 
					
						
							|  |  |  |                                               {({ active }) => ( | 
					
						
							|  |  |  |                                                 <a | 
					
						
							|  |  |  |                                                   href={window.location.href + "/../cancel/" + booking.uid} | 
					
						
							|  |  |  |                                                   className={classNames( | 
					
						
							|  |  |  |                                                     active | 
					
						
							|  |  |  |                                                       ? "bg-neutral-100 text-neutral-900" | 
					
						
							|  |  |  |                                                       : "text-neutral-700", | 
					
						
							|  |  |  |                                                     "group flex items-center px-4 py-2 text-sm font-medium" | 
					
						
							|  |  |  |                                                   )}> | 
					
						
							| 
									
										
										
										
											2021-08-03 08:47:01 +00:00
										 |  |  |                                                   <XIcon | 
					
						
							|  |  |  |                                                     className="mr-3 h-5 w-5 text-neutral-400 group-hover:text-neutral-500" | 
					
						
							|  |  |  |                                                     aria-hidden="true" | 
					
						
							|  |  |  |                                                   /> | 
					
						
							| 
									
										
										
										
											2021-08-03 08:34:43 +00:00
										 |  |  |                                                   Cancel | 
					
						
							|  |  |  |                                                 </a> | 
					
						
							|  |  |  |                                               )} | 
					
						
							|  |  |  |                                             </Menu.Item> | 
					
						
							|  |  |  |                                             <Menu.Item> | 
					
						
							|  |  |  |                                               {({ active }) => ( | 
					
						
							|  |  |  |                                                 <a | 
					
						
							|  |  |  |                                                   href={ | 
					
						
							|  |  |  |                                                     window.location.href + "/../reschedule/" + booking.uid | 
					
						
							|  |  |  |                                                   } | 
					
						
							|  |  |  |                                                   className={classNames( | 
					
						
							|  |  |  |                                                     active | 
					
						
							|  |  |  |                                                       ? "bg-neutral-100 text-neutral-900" | 
					
						
							|  |  |  |                                                       : "text-neutral-700", | 
					
						
							|  |  |  |                                                     "group flex items-center px-4 py-2 text-sm w-full font-medium" | 
					
						
							|  |  |  |                                                   )}> | 
					
						
							| 
									
										
										
										
											2021-08-03 08:47:01 +00:00
										 |  |  |                                                   <ClockIcon | 
					
						
							|  |  |  |                                                     className="mr-3 h-5 w-5 text-neutral-400 group-hover:text-neutral-500" | 
					
						
							|  |  |  |                                                     aria-hidden="true" | 
					
						
							|  |  |  |                                                   /> | 
					
						
							| 
									
										
										
										
											2021-08-03 08:34:43 +00:00
										 |  |  |                                                   Reschedule | 
					
						
							|  |  |  |                                                 </a> | 
					
						
							|  |  |  |                                               )} | 
					
						
							|  |  |  |                                             </Menu.Item> | 
					
						
							|  |  |  |                                           </div> | 
					
						
							|  |  |  |                                         </Menu.Items> | 
					
						
							|  |  |  |                                       </Transition> | 
					
						
							|  |  |  |                                     </> | 
					
						
							|  |  |  |                                   )} | 
					
						
							|  |  |  |                                 </Menu> | 
					
						
							| 
									
										
										
										
											2021-09-17 19:25:23 +00:00
										 |  |  |                               </> | 
					
						
							| 
									
										
										
										
											2021-07-17 12:30:29 +00:00
										 |  |  |                             )} | 
					
						
							|  |  |  |                             {!booking.confirmed && booking.rejected && ( | 
					
						
							|  |  |  |                               <div className="text-sm text-gray-500">Rejected</div> | 
					
						
							|  |  |  |                             )} | 
					
						
							|  |  |  |                           </td> | 
					
						
							|  |  |  |                         </tr> | 
					
						
							|  |  |  |                       ))} | 
					
						
							| 
									
										
										
										
											2021-06-24 13:36:31 +00:00
										 |  |  |                   </tbody> | 
					
						
							|  |  |  |                 </table> | 
					
						
							|  |  |  |               </div> | 
					
						
							|  |  |  |             </div> | 
					
						
							|  |  |  |           </div> | 
					
						
							|  |  |  |         </div> | 
					
						
							|  |  |  |       </Shell> | 
					
						
							|  |  |  |     </div> | 
					
						
							|  |  |  |   ); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export async function getServerSideProps(context) { | 
					
						
							|  |  |  |   const session = await getSession(context); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (!session) { | 
					
						
							|  |  |  |     return { redirect: { permanent: false, destination: "/auth/login" } }; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2021-09-15 15:47:49 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   const user: User = await prisma.user.findUnique({ | 
					
						
							|  |  |  |     where: { | 
					
						
							|  |  |  |       id: session.user.id, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     select: { | 
					
						
							|  |  |  |       email: true, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-03 00:29:38 +00:00
										 |  |  |   const b = await prisma.booking.findMany({ | 
					
						
							| 
									
										
										
										
											2021-06-24 13:36:31 +00:00
										 |  |  |     where: { | 
					
						
							| 
									
										
										
										
											2021-09-14 08:45:28 +00:00
										 |  |  |       OR: [ | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           userId: session.user.id, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           attendees: { | 
					
						
							|  |  |  |             some: { | 
					
						
							| 
									
										
										
										
											2021-09-15 15:47:49 +00:00
										 |  |  |               email: user.email, | 
					
						
							| 
									
										
										
										
											2021-09-14 08:45:28 +00:00
										 |  |  |             }, | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       ], | 
					
						
							| 
									
										
										
										
											2021-06-24 13:36:31 +00:00
										 |  |  |     }, | 
					
						
							|  |  |  |     select: { | 
					
						
							|  |  |  |       uid: true, | 
					
						
							|  |  |  |       title: true, | 
					
						
							|  |  |  |       description: true, | 
					
						
							|  |  |  |       attendees: true, | 
					
						
							| 
									
										
										
										
											2021-07-17 12:30:29 +00:00
										 |  |  |       confirmed: true, | 
					
						
							|  |  |  |       rejected: true, | 
					
						
							|  |  |  |       id: true, | 
					
						
							| 
									
										
										
										
											2021-08-03 00:22:17 +00:00
										 |  |  |       startTime: true, | 
					
						
							|  |  |  |       endTime: true, | 
					
						
							| 
									
										
										
										
											2021-09-14 08:45:28 +00:00
										 |  |  |       eventType: { | 
					
						
							|  |  |  |         select: { | 
					
						
							|  |  |  |           team: { | 
					
						
							|  |  |  |             select: { | 
					
						
							|  |  |  |               name: true, | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }, | 
					
						
							| 
									
										
										
										
											2021-09-13 08:57:56 +00:00
										 |  |  |       status: true, | 
					
						
							| 
									
										
										
										
											2021-06-24 13:36:31 +00:00
										 |  |  |     }, | 
					
						
							| 
									
										
										
										
											2021-06-30 14:14:10 +00:00
										 |  |  |     orderBy: { | 
					
						
							| 
									
										
										
										
											2021-08-03 00:22:17 +00:00
										 |  |  |       startTime: "asc", | 
					
						
							| 
									
										
										
										
											2021-06-30 14:14:10 +00:00
										 |  |  |     }, | 
					
						
							| 
									
										
										
										
											2021-06-24 13:36:31 +00:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-03 08:34:43 +00:00
										 |  |  |   const bookings = b.reverse().map((booking) => { | 
					
						
							|  |  |  |     return { ...booking, startTime: booking.startTime.toISOString(), endTime: booking.endTime.toISOString() }; | 
					
						
							| 
									
										
										
										
											2021-08-03 00:22:17 +00:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-24 13:36:31 +00:00
										 |  |  |   return { props: { bookings } }; | 
					
						
							|  |  |  | } |