import Head from 'next/head'; import Link from 'next/link'; import prisma from '../../lib/prisma'; import Shell from '../../components/Shell'; import Router from 'next/router'; import { useRef } from 'react'; import { useState } from 'react'; import { useSession, getSession } from 'next-auth/client'; export default function Availability(props) { const [ session, loading ] = useSession(); const [showAddModal, setShowAddModal] = useState(false); const titleRef = useRef(); const descriptionRef = useRef(); const lengthRef = useRef(); if (loading) { return

Loading...

; } else { if (!session) { window.location.href = "/auth/login"; } } function toggleAddModal() { setShowAddModal(!showAddModal); } async function createEventTypeHandler(event) { event.preventDefault(); const enteredTitle = titleRef.current.value; const enteredDescription = descriptionRef.current.value; const enteredLength = lengthRef.current.value; // TODO: Add validation const response = await fetch('/api/availability/eventtype', { method: 'POST', body: JSON.stringify({title: enteredTitle, description: enteredDescription, length: enteredLength}), headers: { 'Content-Type': 'application/json' } }); console.log(response); Router.reload(); } return(
Availability | Calendso

Event Types

{props.types.map((eventType) => )}
Name Description Length Edit
{eventType.title} {eventType.description} {eventType.length} minutes Edit
{showAddModal &&

Create a new event type for people to book times with.

minutes
}
); } export async function getServerSideProps(context) { const session = await getSession(context); const user = await prisma.user.findFirst({ where: { email: session.user.email, }, select: { id: true } }); const types = await prisma.eventType.findMany({ where: { userId: user.id, }, select: { id: true, title: true, description: true, length: true } }); return { props: {types}, // will be passed to the page component as props } }