stop votes after midnight

This commit is contained in:
Belle 2024-08-28 07:40:24 +05:30
parent 0c0880ae4d
commit 79307e765d
4 changed files with 88 additions and 61 deletions

View file

@ -54,6 +54,7 @@
"jszip": "^3.10.1",
"jszip-utils": "^0.1.0",
"lodash": "^4.17.21",
"luxon": "^3.5.0",
"million": "^2.6.4",
"next": "^12.3.1",
"next-transpile-modules": "^10.0.1",

View file

@ -1,7 +1,17 @@
import AirtablePlus from 'airtable-plus'
import { ensureAuthed } from '../login/test'
import { DateTime } from 'luxon'
export default async function handler(req, res) {
const deadline = DateTime.fromISO('2024-08-27T20:59:59', {
zone: 'America/New_York'
})
const now = DateTime.now().setZone('America/New_York')
if (now > deadline) {
return res.status(403).json({ error: 'The submission period has ended' })
}
const authToken = req.body?.authToken
if (!authToken) {
return res.status(401).json({ error: 'No auth token provided' })

View file

@ -6,6 +6,7 @@ import styles from '../../../components/arcade/showcase/my.module.css'
// import Countdown from 'react-countdown'
import Icon from '@hackclub/icons'
import ProjectAddView from '../../../components/arcade/showcase/project-add'
import { DateTime } from 'luxon'
/** @jsxImportSource theme-ui */
const styled = `
@ -54,45 +55,48 @@ a {
}
`
const ProjectGallery = ({ projects, loadProjects }) => {
const ProjectGallery = ({ projects, loadProjects, submissionClose }) => {
return (
<div className={styles.feed}>
<div className={styles.container}>
<Box
target="_blank"
rel="noopener"
className="gaegu"
sx={{
border: '3px dashed #09AFB4',
my: 2,
display: 'flex',
color: '#09AFB4',
borderRadius: '10px',
flexDirection: 'column',
width: '100%',
height: '100%',
textDecoration: 'none',
textAlign: 'center',
py: 2,
alignItems: 'center',
justifyContent: 'center',
cursor: 'pointer',
transitionDuration: '0.4s',
'&:hover': {
background: '#09AFB4',
color: '#F4E7C7'
}
}}
onClick={e => {
document.getElementById('add-project').showModal()
}}
>
<Icon glyph="plus" sx={{ marginX: 'auto' }} />
<Text variant="subtitle" sx={{ mt: 0 }}>
Add a Project
</Text>
</Box>
</div>
{submissionClose ? null : (
<div className={styles.container}>
<Box
target="_blank"
rel="noopener"
className="gaegu"
sx={{
border: '3px dashed #09AFB4',
my: 2,
display: 'flex',
color: '#09AFB4',
borderRadius: '10px',
flexDirection: 'column',
width: '100%',
height: '100%',
textDecoration: 'none',
textAlign: 'center',
py: 2,
alignItems: 'center',
justifyContent: 'center',
cursor: 'pointer',
transitionDuration: '0.4s',
'&:hover': {
background: '#09AFB4',
color: '#F4E7C7'
}
}}
onClick={e => {
document.getElementById('add-project').showModal()
}}
>
<Icon glyph="plus" sx={{ marginX: 'auto' }} />
<Text variant="subtitle" sx={{ mt: 0 }}>
Add a Project
</Text>
</Box>
</div>
)}
{projects.map(project => (
<CohortCard
key={project.id}
@ -136,9 +140,14 @@ const ErrorMessage = () => (
</div>
)
const VoteCountdown = ({ isActive }) => {
const VoteCountdown = ({ isActive, submissionClose }) => {
if (!isActive) {
return (<span sx={{ color: '#FF5C00' }}>Voting round opening soon!</span>)
return (
<span sx={{ color: '#FF5C00' }}>
Submissions {submissionClose ? 'ended' : 'end on'} Aug 27 at 11:59pm ET.
Voting round opening soon!
</span>
)
} else {
return (
<div sx={{ width: '100%' }}>
@ -172,7 +181,18 @@ const My = () => {
const [name, setName] = useState('')
const [status, setStatus] = useState('loading')
const [errorMsg, setError] = useState(null)
const [submissionClose, setSubmissionClose] = useState(false)
const deadline = DateTime.fromISO('2024-08-27T23:59:59', {
zone: 'America/New_York'
})
const now = DateTime.now().setZone('America/New_York')
useEffect(() => {
if (now > deadline) {
setSubmissionClose(true)
}
}, [])
// const launchDate = new Date(2025, 7, 25, 8, 0, 0, 0)
// Spotlight effect
@ -223,8 +243,7 @@ const My = () => {
headers: {
Authorization: `Bearer ${token}`
}
}).catch(e => {
})
}).catch(e => {})
const data = await response.json()
if (!data.error && !data.voted) {
setVoteOpen(true)
@ -314,7 +333,11 @@ const My = () => {
}}
className="gaegu"
>
<VoteCountdown isActive={voteOpen} startTime={null} />
<VoteCountdown
isActive={voteOpen}
startTime={null}
submissionClose={submissionClose}
/>
</div>
</Heading>
</SlideDown>
@ -324,7 +347,11 @@ const My = () => {
{status == 'error' && <ErrorMessage />}
{status == 'success' && (
<ProjectGallery projects={projects} loadProjects={loadProjects} />
<ProjectGallery
projects={projects}
loadProjects={loadProjects}
submissionClose={submissionClose}
/>
)}
<dialog
id="add-project"

View file

@ -5804,6 +5804,11 @@ lru-cache@^5.1.1:
dependencies:
yallist "^3.0.2"
luxon@^3.5.0:
version "3.5.0"
resolved "https://registry.yarnpkg.com/luxon/-/luxon-3.5.0.tgz#6b6f65c5cd1d61d1fd19dbf07ee87a50bf4b8e20"
integrity sha512-rh+Zjr6DNfUYR3bPwJEnuwDdqMbxZW7LOQfUN4B54+Cl+0o5zaU9RJ6bcidfDtC1cWCZXQ+nvX8bf6bAji37QQ==
make-dir@^3.0.2:
version "3.1.0"
resolved "https://registry.yarnpkg.com/make-dir/-/make-dir-3.1.0.tgz#415e967046b3a7f1d185277d84aa58203726a13f"
@ -8531,16 +8536,7 @@ string-hash@1.1.3:
resolved "https://registry.yarnpkg.com/string-hash/-/string-hash-1.1.3.tgz#e8aafc0ac1855b4666929ed7dd1275df5d6c811b"
integrity sha512-kJUvRUFK49aub+a7T1nNE66EJbZBMnBgoC1UbCZ5n6bsZKBRga4KgBRTMn/pFkeCZSYtNeSyMxPDM0AXWELk2A==
"string-width-cjs@npm:string-width@^4.2.0":
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
dependencies:
emoji-regex "^8.0.0"
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"
string-width@^4.1.0:
"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0:
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
@ -8651,7 +8647,7 @@ stringify-entities@^4.0.0:
character-entities-html4 "^2.0.0"
character-entities-legacy "^3.0.0"
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
@ -8665,13 +8661,6 @@ strip-ansi@6.0.0:
dependencies:
ansi-regex "^5.0.0"
strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
dependencies:
ansi-regex "^5.0.1"
strip-ansi@^7.0.1:
version "7.1.0"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.1.0.tgz#d5b6568ca689d8561370b0707685d22434faff45"