Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion pages/[id]/HackerInfo.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState, useEffect, useRef, useMemo } from 'react'
import styled from 'styled-components'
import { CSVLink } from 'react-csv'
import { getHackathonPaths, getHackathons, getHackerInfo } from '../../utility/firebase'
import { getHackathonPaths, getHackathons, getHackerInfo, getRaffleWheelEmails } from '../../utility/firebase'
import Page from '../../components/page'
import Button from '../../components/button'
import Menu from '../../components/menu'
Expand Down Expand Up @@ -102,6 +102,7 @@
export default function HackerInfo({ id, hackathons }) {
const [unfilteredData, setUnfilteredData] = useState([])
const [filteredData, setFilteredData] = useState([])
const [raffleData, setRaffleData] = useState([])
const [currTable, setCurrTable] = useState('Applicants')
const [unfilteredTableKeys, setUnfilteredTableKeys] = useState([])
const [filteredTableKeys, setFilteredTableKeys] = useState([])
Expand All @@ -122,6 +123,7 @@
const [filter, setFilter] = useState({})
const [calculate, setCalculate] = useState({})
const downloadLink = useRef()
const raffleDownloadLink = useRef()
const [uniqueEvents, setUniqueEvents] = useState([])
const [selectedEvents, setSelectedEvents] = useState([])

Expand Down Expand Up @@ -229,6 +231,7 @@
})
}


Check failure on line 234 in pages/[id]/HackerInfo.js

View workflow job for this annotation

GitHub Actions / Linting

Delete `⏎··`
const HackerInfoRow = ({ data }) => {
return (
<TableRow>
Expand Down Expand Up @@ -329,6 +332,22 @@
</Button>
<CSVLink style={{ visibility: 'hidden' }} ref={downloadLink} filename="hackerinfo.csv" data={filteredData} />
</ExportButton>

{/* TODO raffle */}
<ExportButton>
<Button
onClick={async () => {
const data = await getRaffleWheelEmails()
setRaffleData(data)
raffleDownloadLink.current.link.click()
}}
>
cmd-f 2025 Raffle
</Button>
<CSVLink style={{ visibility: 'hidden' }} ref={raffleDownloadLink} filename="cmd-f2025-raffle-emails.csv" data={raffleData} />

Check failure on line 347 in pages/[id]/HackerInfo.js

View workflow job for this annotation

GitHub Actions / Linting

Replace `·style={{·visibility:·'hidden'·}}·ref={raffleDownloadLink}·filename="cmd-f2025-raffle-emails.csv"·data={raffleData}` with `⏎············style={{·visibility:·'hidden'·}}⏎············ref={raffleDownloadLink}⏎············filename="cmd-f2025-raffle-emails.csv"⏎············data={raffleData}⏎·········`
</ExportButton>

Check failure on line 348 in pages/[id]/HackerInfo.js

View workflow job for this annotation

GitHub Actions / Linting

Delete `⏎········⏎`


</Buttons>
<Filters>
<FilterPills>
Expand Down
140 changes: 140 additions & 0 deletions utility/firebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,146 @@
return CSV
}


Check failure on line 757 in utility/firebase.js

View workflow job for this annotation

GitHub Actions / Linting

Delete `⏎`
// export const getRaffleNumbers = async () => {
// const apps = await db
// .collection('Hackathons')
// .doc(HackerEvaluationHackathon)
// .collection('Applicants')
// .where('dayOf.checkedIn', '==', true)
// .get();

// // Use Promise.all to handle asynchronous logic for each applicant
// const CSV = await Promise.all(
// apps.docs.map(async (doc) => {
// const {
// basicInfo: {
// legalFirstName,
// legalLastName,
// preferredName,
// email,
// phoneNumber,
// },
// dayOf,
// } = doc.data();

// // Ensure dayOf.events exists before proceeding
// if (!dayOf?.events || !Array.isArray(dayOf.events)) return null;

// // Fetch event documents for each event in dayOf.events
// const dayOfDocsPromises = dayOf.events.map((e) =>
// db
// .collection('Hackathons')
// .doc(HackerEvaluationHackathon)
// .collection('DayOf')
// .doc(e.eventId)
// .get()
// );

Check failure on line 792 in utility/firebase.js

View workflow job for this annotation

GitHub Actions / Linting

Delete `······`
// // Wait for all dayOfDocs to resolve
// const dayOfDocs = await Promise.all(dayOfDocsPromises);

Check failure on line 795 in utility/firebase.js

View workflow job for this annotation

GitHub Actions / Linting

Delete `······`
// // Calculate total points from events
// const totalPoints = dayOfDocs.reduce(
// (acc, curr) => acc + Number(curr.data()?.points ?? 0),
// 0
// );

// // Calculate raffle entries based on total points
// const totalRaffleEntries = Math.floor(totalPoints / 15);

// return [
// legalFirstName,
// legalLastName,
// preferredName,
// email,
// phoneNumber,
// totalPoints.toString(),
// totalRaffleEntries.toString(),
// ];
// })
// );

// // Filter out null results (in case any docs didn't have events or checked-in status)
// const validCSV = CSV.filter((entry) => entry !== null);

// // Add headers to CSV
// validCSV.unshift([
// 'First Name',
// 'Last Name',
// 'Preferred Name',
// 'Email',
// 'Phone Number',
// 'Total Points',
// 'Raffle Entries',
// ]);

// console.log(validCSV);

// return validCSV;
// };


Check failure on line 836 in utility/firebase.js

View workflow job for this annotation

GitHub Actions / Linting

Delete `⏎`
export const getRaffleWheelEmails = async () => {
const apps = await db
.collection('Hackathons')
.doc(HackerEvaluationHackathon)
.collection('Applicants')
.where('dayOf.checkedIn', '==', true)
.get();

Check failure on line 843 in utility/firebase.js

View workflow job for this annotation

GitHub Actions / Linting

Delete `;`

// Create an array to hold all rows for the raffle entries
const raffleEntries = [];

Check failure on line 846 in utility/firebase.js

View workflow job for this annotation

GitHub Actions / Linting

Delete `;`

// Iterate over the documents and calculate raffle entries for each user
for (const doc of apps.docs) {
const {
basicInfo: { email },
dayOf,
} = doc.data();

Check failure on line 853 in utility/firebase.js

View workflow job for this annotation

GitHub Actions / Linting

Delete `;`

if (!dayOf?.events || !Array.isArray(dayOf.events)) continue;

// Fetch event documents for each event in dayOf.events
const dayOfDocsPromises = dayOf.events.map((e) =>
db
.collection('Hackathons')
.doc(HackerEvaluationHackathon)
.collection('DayOf')
.doc(e.eventId)
.get()
);

const dayOfDocs = await Promise.all(dayOfDocsPromises);

// Calculate total points from events
// +15 is from check in : cmd-f 2025
const totalPoints = 15 + dayOfDocs.reduce(
(acc, curr) => acc + Number(curr.data()?.points ?? 0),
0
);

// Calculate raffle entries based on total points
const totalRaffleEntries = Math.floor(totalPoints / 15);

// Add the user's email multiple times based on raffle entries
for (let i = 0; i < totalRaffleEntries; i++) {
raffleEntries.push(email); // Repeat the email for each raffle entry
}
}

// Prepare CSV with only the "Raffle Entries" column
const CSV = [
['Raffle Entries'],
...raffleEntries.map(email => [email]), // Convert to array format for CSV
];

console.log(CSV);

return CSV;
};


export const getResumeFile = async userId => {
try {
const ref = storage.ref(`applicantResumes/${userId}`)
Expand Down
Loading