| 
									
										
										
										
											2021-09-24 10:16:46 +00:00
										 |  |  | import { GetServerSidePropsContext } from "next"; | 
					
						
							| 
									
										
										
										
											2021-09-03 20:51:21 +00:00
										 |  |  | import { useSession } from "next-auth/client"; | 
					
						
							| 
									
										
										
										
											2021-09-22 19:52:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-03 20:51:21 +00:00
										 |  |  | import { getSession } from "@lib/auth"; | 
					
						
							| 
									
										
										
										
											2021-09-22 19:52:38 +00:00
										 |  |  | import prisma from "@lib/prisma"; | 
					
						
							| 
									
										
										
										
											2021-09-24 10:16:46 +00:00
										 |  |  | import { inferSSRProps } from "@lib/types/inferSSRProps"; | 
					
						
							| 
									
										
										
										
											2021-09-22 19:52:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | import Loader from "@components/Loader"; | 
					
						
							| 
									
										
										
										
											2021-09-29 21:33:18 +00:00
										 |  |  | import SettingsShell from "@components/SettingsShell"; | 
					
						
							| 
									
										
										
										
											2021-09-22 19:52:38 +00:00
										 |  |  | import Shell from "@components/Shell"; | 
					
						
							| 
									
										
										
										
											2021-05-26 16:24:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-24 10:16:46 +00:00
										 |  |  | export default function Embed(props: inferSSRProps<typeof getServerSideProps>) { | 
					
						
							|  |  |  |   const [, loading] = useSession(); | 
					
						
							| 
									
										
										
										
											2021-05-26 16:24:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-24 20:24:00 +00:00
										 |  |  |   if (loading) { | 
					
						
							| 
									
										
										
										
											2021-08-05 11:36:24 +00:00
										 |  |  |     return <Loader />; | 
					
						
							| 
									
										
										
										
											2021-07-24 20:24:00 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2021-05-26 16:24:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-24 10:16:46 +00:00
										 |  |  |   const iframeTemplate = `<iframe src="${process.env.NEXT_PUBLIC_APP_URL}/${props.user?.username}" frameborder="0" allowfullscreen></iframe>`; | 
					
						
							|  |  |  |   const htmlTemplate = `<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Schedule a meeting</title><style>body {margin: 0;}iframe {height: calc(100vh - 4px);width: calc(100vw - 4px);box-sizing: border-box;}</style></head><body>${iframeTemplate}</body></html>`; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-24 20:24:00 +00:00
										 |  |  |   return ( | 
					
						
							| 
									
										
										
										
											2021-10-05 01:30:00 +00:00
										 |  |  |     <Shell heading="Embed" subtitle="Integrate with your website using our embed options."> | 
					
						
							| 
									
										
										
										
											2021-07-24 20:24:00 +00:00
										 |  |  |       <SettingsShell> | 
					
						
							| 
									
										
										
										
											2021-10-05 01:30:00 +00:00
										 |  |  |         <div className="py-6 lg:pb-8 lg:col-span-9"> | 
					
						
							|  |  |  |           <div className="mb-6"> | 
					
						
							|  |  |  |             <h2 className="font-cal text-lg leading-6 font-medium text-gray-900">iframe Embed</h2> | 
					
						
							|  |  |  |             <p className="mt-1 text-sm text-gray-500">The easiest way to embed Cal.com on your website.</p> | 
					
						
							|  |  |  |           </div> | 
					
						
							|  |  |  |           <div className="grid grid-cols-2 space-x-4"> | 
					
						
							|  |  |  |             <div> | 
					
						
							|  |  |  |               <label htmlFor="iframe" className="block text-sm font-medium text-gray-700"> | 
					
						
							|  |  |  |                 Standard iframe | 
					
						
							|  |  |  |               </label> | 
					
						
							|  |  |  |               <div className="mt-1"> | 
					
						
							|  |  |  |                 <textarea | 
					
						
							|  |  |  |                   id="iframe" | 
					
						
							|  |  |  |                   className="h-32 shadow-sm focus:ring-black focus:border-black block w-full sm:text-sm border-gray-300 rounded-sm" | 
					
						
							|  |  |  |                   placeholder="Loading..." | 
					
						
							|  |  |  |                   defaultValue={iframeTemplate} | 
					
						
							|  |  |  |                   readOnly | 
					
						
							|  |  |  |                 /> | 
					
						
							| 
									
										
										
										
											2021-07-24 20:24:00 +00:00
										 |  |  |               </div> | 
					
						
							|  |  |  |             </div> | 
					
						
							| 
									
										
										
										
											2021-10-05 01:30:00 +00:00
										 |  |  |             <div> | 
					
						
							|  |  |  |               <label htmlFor="fullscreen" className="block text-sm font-medium text-gray-700"> | 
					
						
							|  |  |  |                 Responsive full screen iframe | 
					
						
							|  |  |  |               </label> | 
					
						
							|  |  |  |               <div className="mt-1"> | 
					
						
							|  |  |  |                 <textarea | 
					
						
							|  |  |  |                   id="fullscreen" | 
					
						
							|  |  |  |                   className="h-32 shadow-sm focus:ring-black focus:border-black block w-full sm:text-sm border-gray-300 rounded-sm" | 
					
						
							|  |  |  |                   placeholder="Loading..." | 
					
						
							|  |  |  |                   defaultValue={htmlTemplate} | 
					
						
							|  |  |  |                   readOnly | 
					
						
							|  |  |  |                 /> | 
					
						
							| 
									
										
										
										
											2021-10-04 23:40:52 +00:00
										 |  |  |               </div> | 
					
						
							|  |  |  |             </div> | 
					
						
							| 
									
										
										
										
											2021-07-24 20:24:00 +00:00
										 |  |  |           </div> | 
					
						
							| 
									
										
										
										
											2021-10-05 01:30:00 +00:00
										 |  |  |           <div className="my-6"> | 
					
						
							|  |  |  |             <h2 className="font-cal text-lg leading-6 font-medium text-gray-900">Cal.com API</h2> | 
					
						
							|  |  |  |             <p className="mt-1 text-sm text-gray-500"> | 
					
						
							|  |  |  |               Leverage our API for full control and customizability. | 
					
						
							|  |  |  |             </p> | 
					
						
							|  |  |  |           </div> | 
					
						
							|  |  |  |           <a href="https://developer.cal.com/api" className="btn btn-primary"> | 
					
						
							|  |  |  |             Browse our API documentation | 
					
						
							|  |  |  |           </a> | 
					
						
							|  |  |  |         </div> | 
					
						
							| 
									
										
										
										
											2021-07-24 20:24:00 +00:00
										 |  |  |       </SettingsShell> | 
					
						
							|  |  |  |     </Shell> | 
					
						
							|  |  |  |   ); | 
					
						
							| 
									
										
										
										
											2021-05-26 16:24:10 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-24 10:16:46 +00:00
										 |  |  | export async function getServerSideProps(context: GetServerSidePropsContext) { | 
					
						
							| 
									
										
										
										
											2021-07-24 20:24:00 +00:00
										 |  |  |   const session = await getSession(context); | 
					
						
							| 
									
										
										
										
											2021-09-24 10:16:46 +00:00
										 |  |  |   if (!session?.user?.email) { | 
					
						
							| 
									
										
										
										
											2021-07-24 20:24:00 +00:00
										 |  |  |     return { redirect: { permanent: false, destination: "/auth/login" } }; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2021-05-26 16:24:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-24 20:24:00 +00:00
										 |  |  |   const user = await prisma.user.findFirst({ | 
					
						
							|  |  |  |     where: { | 
					
						
							| 
									
										
										
										
											2021-10-05 01:30:00 +00:00
										 |  |  |       email: session.user.email, | 
					
						
							| 
									
										
										
										
											2021-07-24 20:24:00 +00:00
										 |  |  |     }, | 
					
						
							|  |  |  |     select: { | 
					
						
							|  |  |  |       id: true, | 
					
						
							|  |  |  |       username: true, | 
					
						
							|  |  |  |       name: true, | 
					
						
							|  |  |  |       email: true, | 
					
						
							|  |  |  |       bio: true, | 
					
						
							|  |  |  |       avatar: true, | 
					
						
							|  |  |  |       timeZone: true, | 
					
						
							|  |  |  |       weekStart: true, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2021-05-26 16:24:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-24 20:24:00 +00:00
										 |  |  |   return { | 
					
						
							| 
									
										
										
										
											2021-09-24 10:16:46 +00:00
										 |  |  |     props: { session, user }, | 
					
						
							| 
									
										
										
										
											2021-07-24 20:24:00 +00:00
										 |  |  |   }; | 
					
						
							| 
									
										
										
										
											2021-07-22 11:04:15 +00:00
										 |  |  | } |