Skip to content

Commit

Permalink
Merge pull request #516 from nwplus/hackcamp-work-around
Browse files Browse the repository at this point in the history
HackCamp Whitelist Work Around
  • Loading branch information
meleongg authored Nov 8, 2023
2 parents 8a05e3c + 5c5b697 commit 6c01476
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 28 deletions.
48 changes: 28 additions & 20 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
import React, { useEffect, useState } from 'react'
import { Redirect, Route, Switch } from 'wouter'
import GlobalStyle from './theme/GlobalStyle'
import ThemeProvider from './theme/ThemeProvider'
import Navbar from './components/Navbar'
import Form from './components/ApplicationForm'
import Navbar from './components/Navbar'
import Page from './components/Page'
import {
NotFound,
Login,
Application,
ApplicationConfirmation,
ApplicationForm,
ApplicationReview,
Charcuterie,
Home,
DiscordBot,
Faq,
Sponsors,
Gallery,
GettingStarted,
Schedule,
Home,
Judging,
JudgingAdmin,
JudgingView,
DiscordBot,
Submission,
Login,
NotFound,
ProjectView,
ApplicationForm,
ApplicationReview,
ApplicationConfirmation,
Application,
Gallery,
Schedule,
Sponsors,
Submission,
} from './pages'
import Page from './components/Page'
import { db, getLivesiteDoc } from './utility/firebase'
import { APPLICATION_STATUS, DB_COLLECTION, DB_HACKATHON, IS_DEVICE_IOS } from './utility/Constants'
import notifications from './utility/notifications'
import Area51 from './pages/Area51'
import GlobalStyle from './theme/GlobalStyle'
import ThemeProvider from './theme/ThemeProvider'
import { AuthProvider, getRedirectUrl, useAuth } from './utility/Auth'
import { APPLICATION_STATUS, DB_COLLECTION, DB_HACKATHON, IS_DEVICE_IOS } from './utility/Constants'
import { HackerApplicationProvider, useHackerApplication } from './utility/HackerApplicationContext'
import { db, getLivesiteDoc } from './utility/firebase'
import notifications from './utility/notifications'

// only notify user if announcement was created within last 5 secs
const notifyUser = announcement => {
Expand Down Expand Up @@ -67,7 +68,11 @@ const AuthPageRoute = ({ path, children }) => {
}
return (
<Route path={path}>
{user?.status === APPLICATION_STATUS.accepted ? <Page>{children}</Page> : <Redirect to="/" />}
{user?.status === APPLICATION_STATUS.accepted ? (
<Page>{children}</Page>
) : (
<Redirect to="/application/closed" />
)}
</Route>
)
}
Expand Down Expand Up @@ -255,6 +260,9 @@ function App() {
<AdminAuthPageRoute path="/judging/admin">
<JudgingAdmin />
</AdminAuthPageRoute>
<AdminAuthPageRoute path="/area51">
<Area51 />
</AdminAuthPageRoute>
<Route path="/judging/view/:id" component={JudgingViewContainer} />
<Route path="/projects" component={GalleryContainer} />
<Route path="/projects/:id" component={ProjectViewContainer} />
Expand Down
19 changes: 19 additions & 0 deletions src/pages/Area51.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react'
import { Button } from '../components/Input'
import { setWhitelist } from '../utility/firebase'

export default () => {
return (
<div>
<Button
color="secondary"
width="flex"
onClick={() => {
setWhitelist()
}}
>
Add current whitelist
</Button>
</div>
)
}
6 changes: 3 additions & 3 deletions src/utility/Constants.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
export const DB_COLLECTION = 'Hackathons'

// CHANGE: firebase collection name for this hackathon
export const DB_HACKATHON = 'nwHacks2024'
export const DB_HACKATHON = 'HackCamp2023'
export const DAYOF_COLLECTION = 'DayOf'
export const FAQ_COLLECTION = 'FAQ'
export const NOTIFICATION_SETTINGS_CACHE_KEY = 'livesiteNotificationSettings'
export const IS_DEVICE_IOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream
export const copyText = Object.freeze({
// CHANGE: name of hackathon to be displayed on login splash
hackathonName: 'nwHacks 2024',
hackathonNameShort: 'nwHacks',
hackathonName: 'HackCamp 2023',
hackathonNameShort: 'HackCamp',
})

export const PROJECTS_TO_JUDGE_COUNT = 4
Expand Down
70 changes: 65 additions & 5 deletions src/utility/firebase.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import 'firebase/analytics'
import firebase from 'firebase/app'
import 'firebase/firestore'
import 'firebase/analytics'
import 'firebase/storage'
import {
HACKER_APPLICATION_TEMPLATE,
REDIRECT_STATUS,
DB_COLLECTION,
ANALYTICS_EVENTS,
APPLICATION_STATUS,
DB_COLLECTION,
DB_HACKATHON,
ANALYTICS_EVENTS,
HACKER_APPLICATION_TEMPLATE,
REDIRECT_STATUS,
} from '../utility/Constants'

if (!firebase.apps.length) {
Expand Down Expand Up @@ -42,6 +42,49 @@ export const getLivesiteDoc = callback => {
})
}

// -----------------------------------------------------
// TODO: Delete temporary code that whitelists users that have RSVP'd (all the commented bars)
export const setWhitelist = async () => {
let batch = db.batch()

let whitelistedArr = [
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
]

for (let i = 0; i < whitelistedArr.length; i++) {
batch.set(
db.collection(DB_COLLECTION).doc(DB_HACKATHON).collection('Whitelist').doc(whitelistedArr[i]),
{}
)
}

batch.commit().then(() => {
alert('uploaded successfully')
})
}
// -----------------------------------------------------

// -----------------------------------------------------
export const getWhitelisted = async () => {
// db.collection('Hackathons').doc('HackCamp2023').collection('Whitelist')
const whitelisted = []
await db
.collection(DB_COLLECTION)
.doc(DB_HACKATHON)
.collection('Whitelist')
.get()
.then(querySnapshot => {
querySnapshot.forEach(doc => {
whitelisted.push(doc.id)
})
})
return whitelisted
}
// -----------------------------------------------------

const createNewApplication = async user => {
analytics.logEvent(ANALYTICS_EVENTS.signup, { userId: user.uid })
const userId = {
Expand Down Expand Up @@ -82,6 +125,23 @@ const createNewApplication = async user => {
...judging,
}

// -----------------------------------------------------
// If not whitelisted, no
const whitelisted = await getWhitelisted()
if (whitelisted.includes(user.email)) {
// good to go
newApplication = {
...newApplication,
status: {
applicationStatus: 'acceptedAndAttending',
responded: true,
attending: true,
},
}
// else, the default application template will block them from submissions -> redirect to "Applications for this hackathon are closed"
}
// -----------------------------------------------------

await applicantsRef.doc(user.uid).set(newApplication)
}

Expand Down

0 comments on commit 6c01476

Please sign in to comment.