| 
									
										
										
										
											2021-09-22 19:52:38 +00:00
										 |  |  | import { ExclamationIcon } from "@heroicons/react/solid"; | 
					
						
							|  |  |  | import { SchedulingType } from "@prisma/client"; | 
					
						
							| 
									
										
										
										
											2021-09-23 17:18:29 +00:00
										 |  |  | import { Dayjs } from "dayjs"; | 
					
						
							| 
									
										
										
										
											2021-06-19 22:50:47 +00:00
										 |  |  | import Link from "next/link"; | 
					
						
							| 
									
										
										
										
											2021-06-24 22:15:18 +00:00
										 |  |  | import { useRouter } from "next/router"; | 
					
						
							| 
									
										
										
										
											2021-12-15 10:26:39 +00:00
										 |  |  | import React, { FC, useEffect, useState } from "react"; | 
					
						
							| 
									
										
										
										
											2021-09-22 19:52:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-27 19:48:13 +00:00
										 |  |  | import { nameOfDay } from "@calcom/lib/weekday"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-15 10:26:39 +00:00
										 |  |  | import classNames from "@lib/classNames"; | 
					
						
							| 
									
										
										
										
											2021-10-08 11:43:48 +00:00
										 |  |  | import { useLocale } from "@lib/hooks/useLocale"; | 
					
						
							| 
									
										
										
										
											2021-09-22 19:52:38 +00:00
										 |  |  | import { useSlots } from "@lib/hooks/useSlots"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-04 19:39:59 +00:00
										 |  |  | import Loader from "@components/Loader"; | 
					
						
							| 
									
										
										
										
											2021-06-19 22:50:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-23 17:18:29 +00:00
										 |  |  | type AvailableTimesProps = { | 
					
						
							|  |  |  |   timeFormat: string; | 
					
						
							|  |  |  |   minimumBookingNotice: number; | 
					
						
							| 
									
										
										
										
											2022-03-04 10:19:03 +00:00
										 |  |  |   beforeBufferTime: number; | 
					
						
							|  |  |  |   afterBufferTime: number; | 
					
						
							| 
									
										
										
										
											2021-09-23 17:18:29 +00:00
										 |  |  |   eventTypeId: number; | 
					
						
							|  |  |  |   eventLength: number; | 
					
						
							| 
									
										
										
										
											2021-12-19 12:11:31 +00:00
										 |  |  |   slotInterval: number | null; | 
					
						
							| 
									
										
										
										
											2021-09-23 17:18:29 +00:00
										 |  |  |   date: Dayjs; | 
					
						
							|  |  |  |   users: { | 
					
						
							|  |  |  |     username: string | null; | 
					
						
							|  |  |  |   }[]; | 
					
						
							|  |  |  |   schedulingType: SchedulingType | null; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const AvailableTimes: FC<AvailableTimesProps> = ({ | 
					
						
							| 
									
										
										
										
											2021-07-08 21:14:29 +00:00
										 |  |  |   date, | 
					
						
							|  |  |  |   eventLength, | 
					
						
							|  |  |  |   eventTypeId, | 
					
						
							| 
									
										
										
										
											2021-12-19 12:11:31 +00:00
										 |  |  |   slotInterval, | 
					
						
							| 
									
										
										
										
											2021-07-22 22:52:27 +00:00
										 |  |  |   minimumBookingNotice, | 
					
						
							| 
									
										
										
										
											2021-07-08 21:14:29 +00:00
										 |  |  |   timeFormat, | 
					
						
							| 
									
										
										
										
											2021-09-14 08:45:28 +00:00
										 |  |  |   users, | 
					
						
							|  |  |  |   schedulingType, | 
					
						
							| 
									
										
										
										
											2022-03-04 10:19:03 +00:00
										 |  |  |   beforeBufferTime, | 
					
						
							|  |  |  |   afterBufferTime, | 
					
						
							| 
									
										
										
										
											2021-07-08 21:14:29 +00:00
										 |  |  | }) => { | 
					
						
							| 
									
										
										
										
											2021-12-20 11:55:49 +00:00
										 |  |  |   const { t, i18n } = useLocale(); | 
					
						
							| 
									
										
										
										
											2021-06-19 22:50:47 +00:00
										 |  |  |   const router = useRouter(); | 
					
						
							| 
									
										
										
										
											2021-06-27 22:30:11 +00:00
										 |  |  |   const { rescheduleUid } = router.query; | 
					
						
							| 
									
										
										
										
											2021-09-14 08:45:28 +00:00
										 |  |  |   const { slots, loading, error } = useSlots({ | 
					
						
							| 
									
										
										
										
											2021-07-08 21:14:29 +00:00
										 |  |  |     date, | 
					
						
							| 
									
										
										
										
											2021-12-19 12:11:31 +00:00
										 |  |  |     slotInterval, | 
					
						
							| 
									
										
										
										
											2021-07-08 21:14:29 +00:00
										 |  |  |     eventLength, | 
					
						
							| 
									
										
										
										
											2021-09-14 08:45:28 +00:00
										 |  |  |     schedulingType, | 
					
						
							|  |  |  |     users, | 
					
						
							| 
									
										
										
										
											2021-07-22 22:52:27 +00:00
										 |  |  |     minimumBookingNotice, | 
					
						
							| 
									
										
										
										
											2022-03-04 10:19:03 +00:00
										 |  |  |     beforeBufferTime, | 
					
						
							|  |  |  |     afterBufferTime, | 
					
						
							| 
									
										
										
										
											2021-09-23 17:18:29 +00:00
										 |  |  |     eventTypeId, | 
					
						
							| 
									
										
										
										
											2021-07-08 21:14:29 +00:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-15 10:26:39 +00:00
										 |  |  |   const [brand, setBrand] = useState("#292929"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   useEffect(() => { | 
					
						
							|  |  |  |     setBrand(getComputedStyle(document.documentElement).getPropertyValue("--brand-color").trim()); | 
					
						
							|  |  |  |   }, []); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-19 22:50:47 +00:00
										 |  |  |   return ( | 
					
						
							| 
									
										
										
										
											2022-02-09 00:05:13 +00:00
										 |  |  |     <div className="mt-8 flex flex-col text-center sm:mt-0 sm:w-1/3 sm:pl-4 md:-mb-5"> | 
					
						
							|  |  |  |       <div className="mb-4 text-left text-lg font-light text-gray-600"> | 
					
						
							| 
									
										
										
										
											2021-11-18 01:03:19 +00:00
										 |  |  |         <span className="w-1/2 text-gray-600 dark:text-white"> | 
					
						
							| 
									
										
										
										
											2022-03-27 19:48:13 +00:00
										 |  |  |           <strong>{nameOfDay(i18n.language, Number(date.format("d")))}</strong> | 
					
						
							| 
									
										
										
										
											2021-10-08 11:43:48 +00:00
										 |  |  |           <span className="text-gray-500"> | 
					
						
							| 
									
										
										
										
											2021-12-20 11:55:49 +00:00
										 |  |  |             {date.format(", D ")} | 
					
						
							|  |  |  |             {date.toDate().toLocaleString(i18n.language, { month: "long" })} | 
					
						
							| 
									
										
										
										
											2021-10-08 11:43:48 +00:00
										 |  |  |           </span> | 
					
						
							| 
									
										
										
										
											2021-08-12 17:10:57 +00:00
										 |  |  |         </span> | 
					
						
							| 
									
										
										
										
											2021-06-19 22:50:47 +00:00
										 |  |  |       </div> | 
					
						
							| 
									
										
										
										
											2022-02-09 00:05:13 +00:00
										 |  |  |       <div className="flex-grow overflow-y-auto md:h-[364px]"> | 
					
						
							| 
									
										
										
										
											2021-09-22 14:44:38 +00:00
										 |  |  |         {!loading && | 
					
						
							|  |  |  |           slots?.length > 0 && | 
					
						
							|  |  |  |           slots.map((slot) => { | 
					
						
							| 
									
										
										
										
											2021-10-12 13:11:33 +00:00
										 |  |  |             type BookingURL = { | 
					
						
							|  |  |  |               pathname: string; | 
					
						
							|  |  |  |               query: Record<string, string | number | string[] | undefined>; | 
					
						
							|  |  |  |             }; | 
					
						
							|  |  |  |             const bookingUrl: BookingURL = { | 
					
						
							| 
									
										
										
										
											2021-09-22 14:44:38 +00:00
										 |  |  |               pathname: "book", | 
					
						
							|  |  |  |               query: { | 
					
						
							|  |  |  |                 ...router.query, | 
					
						
							|  |  |  |                 date: slot.time.format(), | 
					
						
							|  |  |  |                 type: eventTypeId, | 
					
						
							|  |  |  |               }, | 
					
						
							|  |  |  |             }; | 
					
						
							| 
									
										
										
										
											2021-09-14 08:45:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-22 14:44:38 +00:00
										 |  |  |             if (rescheduleUid) { | 
					
						
							| 
									
										
										
										
											2021-10-12 13:11:33 +00:00
										 |  |  |               bookingUrl.query.rescheduleUid = rescheduleUid as string; | 
					
						
							| 
									
										
										
										
											2021-09-22 14:44:38 +00:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2021-09-14 08:45:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-22 14:44:38 +00:00
										 |  |  |             if (schedulingType === SchedulingType.ROUND_ROBIN) { | 
					
						
							|  |  |  |               bookingUrl.query.user = slot.users; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2021-09-14 08:45:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-22 14:44:38 +00:00
										 |  |  |             return ( | 
					
						
							|  |  |  |               <div key={slot.time.format()}> | 
					
						
							|  |  |  |                 <Link href={bookingUrl}> | 
					
						
							| 
									
										
										
										
											2021-10-18 21:07:06 +00:00
										 |  |  |                   <a | 
					
						
							| 
									
										
										
										
											2021-12-15 10:26:39 +00:00
										 |  |  |                     className={classNames( | 
					
						
							| 
									
										
										
										
											2022-03-05 15:37:46 +00:00
										 |  |  |                       "text-primary-500 hover:bg-brand hover:text-brandcontrast dark:hover:bg-darkmodebrand dark:hover:text-darkmodebrandcontrast mb-2 block rounded-sm border bg-white py-4 font-medium hover:text-white dark:border-transparent dark:bg-gray-600 dark:text-neutral-200 dark:hover:border-black", | 
					
						
							| 
									
										
										
										
											2021-12-15 10:26:39 +00:00
										 |  |  |                       brand === "#fff" || brand === "#ffffff" ? "border-brandcontrast" : "border-brand" | 
					
						
							|  |  |  |                     )} | 
					
						
							| 
									
										
										
										
											2021-10-18 21:07:06 +00:00
										 |  |  |                     data-testid="time"> | 
					
						
							| 
									
										
										
										
											2021-09-22 14:44:38 +00:00
										 |  |  |                     {slot.time.format(timeFormat)} | 
					
						
							|  |  |  |                   </a> | 
					
						
							|  |  |  |                 </Link> | 
					
						
							|  |  |  |               </div> | 
					
						
							|  |  |  |             ); | 
					
						
							|  |  |  |           })} | 
					
						
							|  |  |  |         {!loading && !error && !slots.length && ( | 
					
						
							| 
									
										
										
										
											2022-02-09 00:05:13 +00:00
										 |  |  |           <div className="-mt-4 flex h-full w-full flex-col content-center items-center justify-center"> | 
					
						
							| 
									
										
										
										
											2021-10-08 11:43:48 +00:00
										 |  |  |             <h1 className="my-6 text-xl text-black dark:text-white">{t("all_booked_today")}</h1> | 
					
						
							| 
									
										
										
										
											2021-09-22 14:44:38 +00:00
										 |  |  |           </div> | 
					
						
							|  |  |  |         )} | 
					
						
							| 
									
										
										
										
											2021-06-27 22:30:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-22 14:44:38 +00:00
										 |  |  |         {loading && <Loader />} | 
					
						
							| 
									
										
										
										
											2021-06-27 22:30:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-22 14:44:38 +00:00
										 |  |  |         {error && ( | 
					
						
							| 
									
										
										
										
											2022-02-09 00:05:13 +00:00
										 |  |  |           <div className="border-l-4 border-yellow-400 bg-yellow-50 p-4"> | 
					
						
							| 
									
										
										
										
											2021-09-22 14:44:38 +00:00
										 |  |  |             <div className="flex"> | 
					
						
							|  |  |  |               <div className="flex-shrink-0"> | 
					
						
							| 
									
										
										
										
											2022-02-09 00:05:13 +00:00
										 |  |  |                 <ExclamationIcon className="h-5 w-5 text-yellow-400" aria-hidden="true" /> | 
					
						
							| 
									
										
										
										
											2021-09-22 14:44:38 +00:00
										 |  |  |               </div> | 
					
						
							| 
									
										
										
										
											2022-02-01 22:17:37 +00:00
										 |  |  |               <div className="ltr:ml-3 rtl:mr-3"> | 
					
						
							| 
									
										
										
										
											2021-10-08 11:43:48 +00:00
										 |  |  |                 <p className="text-sm text-yellow-700">{t("slots_load_fail")}</p> | 
					
						
							| 
									
										
										
										
											2021-09-22 14:44:38 +00:00
										 |  |  |               </div> | 
					
						
							| 
									
										
										
										
											2021-06-27 22:30:11 +00:00
										 |  |  |             </div> | 
					
						
							| 
									
										
										
										
											2021-06-27 22:02:27 +00:00
										 |  |  |           </div> | 
					
						
							| 
									
										
										
										
											2021-09-22 14:44:38 +00:00
										 |  |  |         )} | 
					
						
							|  |  |  |       </div> | 
					
						
							| 
									
										
										
										
											2021-06-19 22:50:47 +00:00
										 |  |  |     </div> | 
					
						
							|  |  |  |   ); | 
					
						
							| 
									
										
										
										
											2021-06-24 22:15:18 +00:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2021-06-19 22:50:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-22 15:19:28 +00:00
										 |  |  | export default AvailableTimes; |