Skip to content

Commit

Permalink
Successfully get the settings
Browse files Browse the repository at this point in the history
  • Loading branch information
JiashuHarryHuang committed Oct 7, 2023
1 parent e5ba5bb commit 0c3b8a7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion components/hacker/HackerDash.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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', {
Expand Down Expand Up @@ -690,6 +699,7 @@ export default function HackerDash({ userApplicationStatus, setUserApplicationSt
<>
<div style={{ padding: '20px' }}>
<Header user={user} signOut={signOut} />
<p style={{ color: 'white' }}>{setting?.HACKATHON_START}</p>
{/* TODO: conditionally render hacking start and end code based on time stored in db */}
{/* Hacking start code */}
{/* <div style={{ display: 'flex', justifyContent: 'center', paddingBottom: '10px' }}>
Expand Down
2 changes: 1 addition & 1 deletion pages/api/hackathon-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import hackathon from '../../models/hackathon';

export default async function handler(req: NextApiRequest, res: NextApiResponse<any>) {
const session = await getSession({ req });
if (session?.userType !== 'ORGANIZER') return res.status(403).send('Forbidden');

await dbConnect();
switch (req.method) {
Expand All @@ -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;

Expand Down

0 comments on commit 0c3b8a7

Please sign in to comment.