From 0c3b8a7f7fc0f10133d0634abe9f1a4195d4765d Mon Sep 17 00:00:00 2001 From: Jiashu Huang Date: Sat, 7 Oct 2023 16:00:56 -0500 Subject: [PATCH] Successfully get the settings --- components/hacker/HackerDash.tsx | 12 +++++++++++- pages/api/hackathon-settings.ts | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/components/hacker/HackerDash.tsx b/components/hacker/HackerDash.tsx index f496f818..be22ddf6 100644 --- a/components/hacker/HackerDash.tsx +++ b/components/hacker/HackerDash.tsx @@ -19,7 +19,7 @@ import useSWR from 'swr'; import TeamManager from './TeamManager'; import TeamSetup from './TeamSetup'; import { TeamProfile } from '../../types/client'; -import { ApplicationStatus, UserData, JudgingSessionData } from '../../types/database'; +import { ApplicationStatus, UserData, JudgingSessionData, HackathonSettingsData } from '../../types/database'; import styles from '../../styles/Form.module.css'; import { signOut, useSession } from 'next-auth/react'; import TextArea from 'antd/lib/input/TextArea'; @@ -52,6 +52,15 @@ export default function HackerDash({ userApplicationStatus, setUserApplicationSt { revalidateOnFocus: false, revalidateOnMount: true } ); + const { data: setting } = useSWR( + '/api/hackathon-settings', + async url => { + const res = await fetch(url, { method: 'GET' }); + return (await res.json()) as HackathonSettingsData; + }, + { revalidateOnFocus: false, revalidateOnMount: true } + ); + const onFinish = async (values: any) => { setLoading(true); await fetch('/api/apply', { @@ -690,6 +699,7 @@ export default function HackerDash({ userApplicationStatus, setUserApplicationSt <>
+

{setting?.HACKATHON_START}

{/* TODO: conditionally render hacking start and end code based on time stored in db */} {/* Hacking start code */} {/*
diff --git a/pages/api/hackathon-settings.ts b/pages/api/hackathon-settings.ts index 214e8811..6ac5dfd4 100644 --- a/pages/api/hackathon-settings.ts +++ b/pages/api/hackathon-settings.ts @@ -5,7 +5,6 @@ import hackathon from '../../models/hackathon'; export default async function handler(req: NextApiRequest, res: NextApiResponse) { const session = await getSession({ req }); - if (session?.userType !== 'ORGANIZER') return res.status(403).send('Forbidden'); await dbConnect(); switch (req.method) { @@ -20,6 +19,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< } case 'PATCH': try { + if (session?.userType !== 'ORGANIZER') return res.status(403).send('Forbidden'); // extract variables from body const { HACKATHON_START, HACKATHON_END, JUDGING_START, JUDGING_END } = req.body;