From ea316075989066b9480546a2033eca7056fa8850 Mon Sep 17 00:00:00 2001 From: Bailey Pumfleet Date: Thu, 29 Apr 2021 14:47:01 +0100 Subject: [PATCH] Fix a bunch of TypeScript errors --- components/Modal.tsx | 1 - lib/prisma.ts | 7 ++++--- pages/[user]/[type].tsx | 21 ++++++++++++--------- pages/availability/event/[type].tsx | 2 +- pages/availability/index.tsx | 4 ++-- pages/settings/profile.tsx | 2 +- 6 files changed, 20 insertions(+), 17 deletions(-) diff --git a/components/Modal.tsx b/components/Modal.tsx index 40f1a5a2ee..658bf7064d 100644 --- a/components/Modal.tsx +++ b/components/Modal.tsx @@ -1,4 +1,3 @@ -/* This example requires Tailwind CSS v2.0+ */ import { Fragment, useState } from 'react' import { Dialog, Transition } from '@headlessui/react' import { CheckIcon } from '@heroicons/react/outline' diff --git a/lib/prisma.ts b/lib/prisma.ts index 20e4d98c9a..4d3f847070 100644 --- a/lib/prisma.ts +++ b/lib/prisma.ts @@ -1,14 +1,15 @@ import { PrismaClient } from '@prisma/client'; let prisma: PrismaClient; +const globalAny:any = global; if (process.env.NODE_ENV === 'production') { prisma = new PrismaClient(); } else { - if (!global.prisma) { - global.prisma = new PrismaClient(); + if (!globalAny.prisma) { + globalAny.prisma = new PrismaClient(); } - prisma = global.prisma; + prisma = globalAny.prisma; } export default prisma; \ No newline at end of file diff --git a/pages/[user]/[type].tsx b/pages/[user]/[type].tsx index 8d7fcc8b67..8ca4d5d6cd 100644 --- a/pages/[user]/[type].tsx +++ b/pages/[user]/[type].tsx @@ -84,16 +84,19 @@ export default function Type(props) { )]; // Handle date change - useEffect(async () => { - if(!selectedDate) { - return + useEffect(() => { + const changeDate = async () => { + if (!selectedDate) { + return + } + + setLoading(true); + const res = await fetch(`/api/availability/${user}?dateFrom=${lowerBound.utc().format()}&dateTo=${upperBound.utc().format()}`); + const busyTimes = await res.json(); + if (busyTimes.length > 0) setBusy(busyTimes); + setLoading(false); } - - setLoading(true); - const res = await fetch(`/api/availability/${user}?dateFrom=${lowerBound.utc().format()}&dateTo=${upperBound.utc().format()}`); - const busyTimes = await res.json(); - if (busyTimes.length > 0) setBusy(busyTimes); - setLoading(false); + changeDate(); }, [selectedDate]); diff --git a/pages/availability/event/[type].tsx b/pages/availability/event/[type].tsx index 007ebcea8b..89deae62ac 100644 --- a/pages/availability/event/[type].tsx +++ b/pages/availability/event/[type].tsx @@ -11,7 +11,7 @@ export default function EventType(props) { const [ session, loading ] = useSession(); const titleRef = useRef(); const slugRef = useRef(); - const descriptionRef = useRef(); + const descriptionRef = useRef(); const lengthRef = useRef(); const isHiddenRef = useRef(); diff --git a/pages/availability/index.tsx b/pages/availability/index.tsx index 2c1163b570..9369a0b019 100644 --- a/pages/availability/index.tsx +++ b/pages/availability/index.tsx @@ -17,7 +17,7 @@ export default function Availability(props) { const [showChangeTimesModal, setShowChangeTimesModal] = useState(false); const titleRef = useRef(); const slugRef = useRef(); - const descriptionRef = useRef(); + const descriptionRef = useRef(); const lengthRef = useRef(); const isHiddenRef = useRef(); @@ -42,7 +42,7 @@ export default function Availability(props) { setShowChangeTimesModal(!showChangeTimesModal); } - const closeSuccessModal = () => { Router.reload(); } + const closeSuccessModal = () => { router.replace(router.asPath); } function convertMinsToHrsMins (mins) { let h = Math.floor(mins / 60); diff --git a/pages/settings/profile.tsx b/pages/settings/profile.tsx index 76039466f4..e536f8b148 100644 --- a/pages/settings/profile.tsx +++ b/pages/settings/profile.tsx @@ -15,7 +15,7 @@ export default function Settings(props) { const [successModalOpen, setSuccessModalOpen] = useState(false); const usernameRef = useRef(); const nameRef = useRef(); - const descriptionRef = useRef(); + const descriptionRef = useRef(); const avatarRef = useRef(); const [ selectedTimeZone, setSelectedTimeZone ] = useState({ value: props.user.timeZone });