-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* enable intellisence for css via typescript-plugin-css-modules * big brain moment with types. refactor fn to return ThemedClass type instead of generic string * fix import styles errors that arose thanks to typescript-plugin-css-modules * implement model and api for hackathon-settings * implement hackathon settings to view/change important dates * fix codeql vuln * install dayjs bc antd wants it :( * why do timezones even exist zzzzzz
- Loading branch information
1 parent
bd7f81c
commit 002d196
Showing
13 changed files
with
583 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
{ | ||
"deepscan.enable": true | ||
"deepscan.enable": true, | ||
"typescript.tsdk": "node_modules/typescript/lib" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import { Button, DatePicker, Space } from 'antd'; | ||
import dayjs from 'dayjs'; | ||
import React, { useContext, useEffect, useState } from 'react'; | ||
import { handleSubmitFailure, handleSubmitSuccess } from '../../../lib/helpers'; | ||
import { getBaseColor, ThemeContext } from '../../../theme/themeProvider'; | ||
import { HackathonSettingsData } from '../../../types/database'; | ||
|
||
const HackathonSettings = () => { | ||
const { baseTheme } = useContext(ThemeContext); | ||
const [hackathonSetting, setHackathonSetting] = useState<HackathonSettingsData | undefined>(undefined); | ||
const [loading, setLoading] = useState<boolean>(false); | ||
const [statusMessage, setStatusMessage] = useState<string>(''); | ||
|
||
// fetch hackathon settings on load at /api/hackathon-settings | ||
useEffect(() => { | ||
const fetchHackathonSettings = async () => { | ||
const res = await fetch('/api/hackathon-settings'); | ||
if (res.ok) { | ||
const settings = await res.json(); | ||
setHackathonSetting(settings as HackathonSettingsData); | ||
setLoading(false); | ||
} | ||
}; | ||
setLoading(true); | ||
fetchHackathonSettings(); | ||
}, []); | ||
|
||
// handle save button | ||
const handleSave = async () => { | ||
if ( | ||
window.confirm( | ||
'IMPORTANT: \nAre you sure you wish to save these dates?\nMake sure you know what you are doing!' | ||
) | ||
) { | ||
const res = await fetch('/api/hackathon-settings', { | ||
method: 'PATCH', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify(hackathonSetting), | ||
}); | ||
if (res.ok) { | ||
const settings = await res.json(); | ||
setHackathonSetting(settings as HackathonSettingsData); | ||
setStatusMessage('Successfully saved to database!'); | ||
handleSubmitSuccess('Successfully saved to database!'); | ||
} else { | ||
setStatusMessage('Failed to save to database!'); | ||
handleSubmitFailure('Failed to save to database!'); | ||
} | ||
} | ||
}; | ||
|
||
const handleHackathonChange = (_: any, dateStrings: [string, string]) => { | ||
const newHackathonStart = dayjs(dateStrings[0], 'MM-DD-YYYY hh:mm A').format('MM/DD/YYYY hh:mm A'); | ||
const newHackathonEnd = dayjs(dateStrings[1], { utc: true }).format('MM/DD/YYYY hh:mm A'); | ||
console.log('Changing Hackathon: ', newHackathonStart); | ||
console.log('Changing Hackathon: ', newHackathonEnd); | ||
setHackathonSetting(prev => { | ||
if (prev) | ||
return { | ||
...prev, | ||
HACKATHON_START: newHackathonStart, | ||
HACKATHON_END: newHackathonEnd, | ||
}; | ||
return undefined; | ||
}); | ||
setStatusMessage('Changes not saved yet.'); | ||
}; | ||
|
||
const handleJudgingChange = (_: any, dateStrings: [string, string]) => { | ||
const newJudgingStart = dayjs(dateStrings[0], { utc: true }).format('MM/DD/YYYY hh:mm A'); | ||
const newJudgingEnd = dayjs(dateStrings[1], { utc: true }).format('MM/DD/YYYY hh:mm A'); | ||
setHackathonSetting(prev => { | ||
if (prev) | ||
return { | ||
...prev, | ||
JUDGING_START: newJudgingStart, | ||
JUDGING_END: newJudgingEnd, | ||
}; | ||
return undefined; | ||
}); | ||
setStatusMessage('Changes not saved yet.'); | ||
}; | ||
|
||
if (loading) return <div>Loading...</div>; | ||
|
||
return ( | ||
<div style={{ color: getBaseColor(baseTheme) }}> | ||
<div>Hackathon Start & End</div> | ||
<DatePicker.RangePicker | ||
format="MM/DD/YYYY hh:mm A" | ||
showTime={{ format: 'hh:mm A' }} | ||
onChange={handleHackathonChange} | ||
defaultValue={[dayjs(hackathonSetting?.HACKATHON_START), dayjs(hackathonSetting?.HACKATHON_END)]} | ||
/> | ||
|
||
<br /> | ||
|
||
<div>Judging Start & End</div> | ||
<DatePicker.RangePicker | ||
format="MM/DD/YYYY hh:mm A" | ||
showTime={{ format: 'hh:mm A' }} | ||
onChange={handleJudgingChange} | ||
defaultValue={[dayjs(hackathonSetting?.JUDGING_START), dayjs(hackathonSetting?.JUDGING_END)]} | ||
/> | ||
|
||
<br /> | ||
<br /> | ||
|
||
<Button onClick={handleSave}>Save dates to database</Button> | ||
|
||
{statusMessage && <div>{statusMessage}</div>} | ||
</div> | ||
); | ||
}; | ||
|
||
export default HackathonSettings; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
import HackathonSettings from './HackathonSettings'; | ||
import ThemeControl from './ThemeControl'; | ||
|
||
const SettingsTab = () => { | ||
return <ThemeControl />; | ||
return ( | ||
<> | ||
<HackathonSettings /> | ||
<hr /> | ||
<ThemeControl /> | ||
</> | ||
); | ||
}; | ||
|
||
export default SettingsTab; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import mongoose, { Schema } from 'mongoose'; | ||
|
||
const HackathonSchema = new Schema({ | ||
HACKATHON_START: { type: String, required: true }, // MM/DD/YYYY hh:mm A | ||
HACKATHON_END: { type: String, required: true }, // MM/DD/YYYY hh:mm A | ||
JUDGING_START: { type: String, required: true }, // MM/DD/YYYY hh:mm A | ||
JUDGING_END: { type: String, required: true }, // MM/DD/YYYY hh:mm A | ||
}); | ||
|
||
// prevent recompilation of model if it already exists | ||
export default mongoose.models.Hackathon || mongoose.model('Hackathon', HackathonSchema); |
Oops, something went wrong.
002d196
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
witness – ./
witness-vandyhacks-witness.vercel.app
witness-git-main-vandyhacks-witness.vercel.app
apply.vandyhacks.org