diff --git a/pages/[user].tsx b/pages/[user].tsx index c41f3907..096f4349 100644 --- a/pages/[user].tsx +++ b/pages/[user].tsx @@ -3,7 +3,7 @@ import Link from 'next/link'; import prisma from '../lib/prisma'; export default function User(props) { - const eventTypes = props.user.eventTypes.map(type => + const eventTypes = props.eventTypes.map(type =>
  • @@ -46,9 +46,10 @@ export default function User(props) { export async function getServerSideProps(context) { const user = await prisma.user.findFirst({ where: { - username: context.query.user, + username: context.query.user, }, select: { + id: true, username: true, name: true, bio: true, @@ -63,9 +64,17 @@ export async function getServerSideProps(context) { } } + const eventTypes = await prisma.eventType.findMany({ + where: { + userId: user.id, + hidden: false + } + }); + return { props: { - user + user, + eventTypes }, } } \ No newline at end of file diff --git a/pages/api/availability/eventtype.ts b/pages/api/availability/eventtype.ts index 1d118ffd..77875a69 100644 --- a/pages/api/availability/eventtype.ts +++ b/pages/api/availability/eventtype.ts @@ -26,12 +26,14 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) const title = req.body.title; const description = req.body.description; const length = parseInt(req.body.length); + const hidden = req.body.hidden; const createEventType = await prisma.eventType.create({ data: { title: title, description: description, length: length, + hidden: hidden, userId: user.id, }, }); @@ -56,6 +58,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) const title = req.body.title; const description = req.body.description; const length = parseInt(req.body.length); + const hidden = req.body.hidden; const updateEventType = await prisma.eventType.update({ where: { @@ -64,7 +67,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) data: { title: title, description: description, - length: length + length: length, + hidden: hidden }, }); diff --git a/pages/availability/event/[type].tsx b/pages/availability/event/[type].tsx index ece56d12..c66f9a6f 100644 --- a/pages/availability/event/[type].tsx +++ b/pages/availability/event/[type].tsx @@ -12,6 +12,7 @@ export default function EventType(props) { const titleRef = useRef(); const descriptionRef = useRef(); const lengthRef = useRef(); + const isHiddenRef = useRef(); if (loading) { return

    Loading...

    ; @@ -27,12 +28,13 @@ export default function EventType(props) { const enteredTitle = titleRef.current.value; const enteredDescription = descriptionRef.current.value; const enteredLength = lengthRef.current.value; + const enteredIsHidden = isHiddenRef.current.checked; // TODO: Add validation const response = await fetch('/api/availability/eventtype', { method: 'PATCH', - body: JSON.stringify({id: props.eventType.id, title: enteredTitle, description: enteredDescription, length: enteredLength}), + body: JSON.stringify({id: props.eventType.id, title: enteredTitle, description: enteredDescription, length: enteredLength, hidden: enteredIsHidden}), headers: { 'Content-Type': 'application/json' } @@ -88,6 +90,26 @@ export default function EventType(props) { +
    +
    +
    + +
    +
    + +

    Hide the event type from your page, so it can only be booked through it's URL.

    +
    +
    +
    Cancel @@ -129,7 +151,8 @@ export async function getServerSideProps(context) { id: true, title: true, description: true, - length: true + length: true, + hidden: true } }); diff --git a/pages/availability/index.tsx b/pages/availability/index.tsx index 6dc5570d..205e7617 100644 --- a/pages/availability/index.tsx +++ b/pages/availability/index.tsx @@ -17,6 +17,7 @@ export default function Availability(props) { const titleRef = useRef(); const descriptionRef = useRef(); const lengthRef = useRef(); + const isHiddenRef = useRef(); const startHoursRef = useRef(); const startMinsRef = useRef(); @@ -55,12 +56,13 @@ export default function Availability(props) { const enteredTitle = titleRef.current.value; const enteredDescription = descriptionRef.current.value; const enteredLength = lengthRef.current.value; + const enteredIsHidden = isHiddenRef.current.checked; // TODO: Add validation const response = await fetch('/api/availability/eventtype', { method: 'POST', - body: JSON.stringify({title: enteredTitle, description: enteredDescription, length: enteredLength}), + body: JSON.stringify({title: enteredTitle, description: enteredDescription, length: enteredLength, hidden: enteredIsHidden}), headers: { 'Content-Type': 'application/json' } @@ -139,6 +141,11 @@ export default function Availability(props) { {eventType.title} + {eventType.hidden && + + Hidden + + } {eventType.description} @@ -221,6 +228,25 @@ export default function Availability(props) { +
    +
    +
    + +
    +
    + +

    Hide the event type from your page, so it can only be booked through it's URL.

    +
    +
    +
    {/* TODO: Add an error message when required input fields empty*/}