From 5bedd1f8b26118ac20ce228593656184cd990867 Mon Sep 17 00:00:00 2001 From: Bailey Pumfleet Date: Wed, 7 Apr 2021 21:37:41 +0100 Subject: [PATCH] Fix route parameters --- pages/[user]/[type].tsx | 7 ++++++- pages/[user]/book.tsx | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pages/[user]/[type].tsx b/pages/[user]/[type].tsx index 276452bcb3..f9c1917f0f 100644 --- a/pages/[user]/[type].tsx +++ b/pages/[user]/[type].tsx @@ -2,6 +2,7 @@ import {useEffect, useState} from 'react' import Head from 'next/head' import Link from 'next/link' import prisma from '../../lib/prisma' +import { useRouter } from 'next/router' const dayjs = require('dayjs') const isSameOrBefore = require('dayjs/plugin/isSameOrBefore') dayjs.extend(isSameOrBefore) @@ -13,6 +14,10 @@ export default function Type(props) { const [loading, setLoading] = useState(false); const [busy, setBusy] = useState([]); + // Get router variables + const router = useRouter() + const { user } = router.query + // Handle month changes const incrementMonth = () => { setSelectedMonth(selectedMonth + 1) @@ -38,7 +43,7 @@ export default function Type(props) { // Handle date change useEffect(async () => { setLoading(true); - const res = await fetch('http://localhost:3000/api/availability/bailey?date=' + dayjs(selectedDate).format("YYYY-MM-DD")) + const res = await fetch('/api/availability/' + user + '?date=' + dayjs(selectedDate).format("YYYY-MM-DD")) const data = await res.json() setBusy(data.primary.busy) setLoading(false) diff --git a/pages/[user]/book.tsx b/pages/[user]/book.tsx index 0c38b0b6ec..e3baf4defa 100644 --- a/pages/[user]/book.tsx +++ b/pages/[user]/book.tsx @@ -6,12 +6,12 @@ const dayjs = require('dayjs') export default function Book(props) { const router = useRouter() - const { date } = router.query + const { date, user } = router.query const bookingHandler = event => { event.preventDefault() const res = fetch( - 'http://localhost:3000/api/book/bailey', + 'http://localhost:3000/api/book/' + user, { body: JSON.stringify({ start: dayjs(date).format(),