Skip to content

Commit

Permalink
Merge pull request #305 from nwplus/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
DonaldKLee authored Jan 16, 2025
2 parents c9e1f47 + 0aea362 commit 55ee438
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 8 deletions.
39 changes: 37 additions & 2 deletions pages/[id]/rewards.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export default function Rewards({ id, hackathons }) {
const [alertMsg, setAlertMsg] = useState('')
const { email: user } = useAuth().user

const REWARD_TYPES = [{ label: 'Reward' }, { label: 'Raffle' }]

const fetchRewards = async () => {
const rewardsFetched = await getRewards(id)
if (Object.keys(rewardsFetched).length > 0) {
Expand Down Expand Up @@ -116,6 +118,7 @@ export default function Rewards({ id, hackathons }) {
return (
<TableRow>
<TableData>{props.reward}</TableData>
<TableData>{props.type}</TableData>
<TableData>{props.blurb}</TableData>
<TableData>{props.prizesAvailable}</TableData>
<TableData>{props.requiredPoints}</TableData>
Expand Down Expand Up @@ -143,11 +146,12 @@ export default function Rewards({ id, hackathons }) {
<CardButtonContainer>
<Button
type={NEW}
onClick={() =>
onClick={() => {
setNewReward({
date: setHours(setMinutes(new Date(), 0), 13),
type: 'Reward',
})
}
}}
>
New Reward
</Button>
Expand Down Expand Up @@ -175,6 +179,7 @@ export default function Rewards({ id, hackathons }) {
<thead>
<TableRow>
<TableHeader>Reward</TableHeader>
<TableHeader>Type</TableHeader>
<TableHeader>Blurb</TableHeader>
<TableHeader>Number of Prizes Available</TableHeader>
<TableHeader>Required Points</TableHeader>
Expand All @@ -189,6 +194,7 @@ export default function Rewards({ id, hackathons }) {
key={rewards[curr].rewardID}
rewardID={rewards[curr].rewardID}
reward={rewards[curr].reward}
type={rewards[curr].type}
blurb={rewards[curr].blurb}
prizesAvailable={rewards[curr].prizesAvailable}
requiredPoints={rewards[curr].requiredPoints}
Expand Down Expand Up @@ -216,6 +222,17 @@ export default function Rewards({ id, hackathons }) {
onChange={reward => handleInput('reward', reward.target.value, newReward, setNewReward)}
/>
</ModalContent>
<ModalContent columns={1}>
<ModalField
label="Type"
modalAction={NEW}
dropdown
dropdownOptions={REWARD_TYPES}
onChange={type => {
handleInput('type', type.label, newReward, setNewReward)
}}
/>
</ModalContent>
<ModalContent columns={1}>
<ModalField
label="Blurb"
Expand Down Expand Up @@ -271,6 +288,9 @@ export default function Rewards({ id, hackathons }) {
<ModalContent columns={1}>
<ModalField label="Reward" value={rewardViewing.reward} modalAction={VIEW} />
</ModalContent>
<ModalContent columns={1}>
<ModalField label="Type" value={rewardViewing.type} modalAction={VIEW} />
</ModalContent>
<ModalContent columns={1}>
<ModalField label="Blurb" value={rewardViewing.blurb} modalAction={VIEW} />
</ModalContent>
Expand Down Expand Up @@ -303,6 +323,18 @@ export default function Rewards({ id, hackathons }) {
}}
/>
</ModalContent>
<ModalContent columns={1}>
<ModalField
label="Type"
modalAction={NEW}
dropdown
dropdownOptions={REWARD_TYPES}
value={rewardEditing?.type || undefined}
onChange={type => {
handleInput('type', type.label, rewardEditing, setRewardEditing)
}}
/>
</ModalContent>
<ModalContent columns={1}>
<ModalField
label="Blurb"
Expand Down Expand Up @@ -363,6 +395,9 @@ export default function Rewards({ id, hackathons }) {
<ModalContent columns={1}>
<ModalField label="Reward" value={rewardConfirm.rewardConfirm} modalAction={VIEW} />
</ModalContent>
<ModalContent columns={1}>
<ModalField label="Type" value={rewardConfirm.type} modalAction={VIEW} />
</ModalContent>
<ModalContent columns={1}>
<ModalField label="Blurb" value={rewardConfirm.blurb} modalAction={VIEW} />
</ModalContent>
Expand Down
12 changes: 7 additions & 5 deletions utility/firebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export const getReward = (rewardID, data) => {
rewardID,
reward: data.reward || 'Empty reward field', // Title of the reward
key: data.key || rewardID, // Key of the reward (defaults to rewardID)
type: data.type, // Reward type
blurb: data.blurb || 'Empty blurb description for reward', // Short description of the reward
from: data.from || 'None', // Source or sponsor of the reward
imgName: data.imgName || 'None', // Image name (if applicable)
Expand Down Expand Up @@ -185,6 +186,7 @@ export const addReward = async (hackathon, reward) => {
await ref.set({
reward: reward.reward, // Title of the reward
key: ref.id, // Key generated for the reward
type: reward.type, // Reward type
blurb: reward.blurb, // Short description of the reward
imgName: reward.imgName, // Image name (if applicable)
imgURL: reward.imgURL, // URL to the reward image
Expand All @@ -202,6 +204,7 @@ export const updateReward = async (hackathon, reward) => {
await ref.update({
reward: reward.reward || 'Empty reward field',
key: reward.key || reward.rewardID,
type: reward.type,
blurb: reward.blurb || 'Empty blurb description for reward',
from: reward.from || 'None',
imgName: reward.imgName || 'None',
Expand Down Expand Up @@ -592,11 +595,10 @@ export const getHackerInfo = async (callback, hackathon, collection) => {
.doc(hackathon)
.collection(collection)
.onSnapshot(snap => {
callback(
snap.docs.map(doc => {
return orderObj(flattenObj(filterHackerInfoFields(doc.data(), collection)))
})
)
const hackerInfoPromises = snap.docs.map(async doc => {
return orderObj(flattenObj(await filterHackerInfoFields(db, doc.data(), hackathon, collection)))
})
Promise.all(hackerInfoPromises).then(callback)
})
return res
}
Expand Down
9 changes: 8 additions & 1 deletion utility/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ const createStringFromSelection = (selection, other = '') => {
}

// Specifically for hacker info page - fixes/removes certain fields for table display
export const filterHackerInfoFields = (obj, collection) => {
// Take `db` as a parameter to avoid circular dependency with firebase.js
export const filterHackerInfoFields = async (db, obj, hackathon, collection) => {
let newObj = {}
if (collection === 'Applicants') {
delete obj.questionnaire?.eventsAttended
Expand Down Expand Up @@ -144,6 +145,12 @@ export const filterHackerInfoFields = (obj, collection) => {
newObj.longAnswers3 = obj.skills?.longAnswers3 || false

newObj.attendedEvents = obj.dayOf?.events?.map(e => e.eventName).join(', ') ?? ''

const dayOfDocsPromises = obj.dayOf?.events?.map(e =>
db.collection('Hackathons').doc(hackathon).collection('DayOf').doc(e.eventId).get()
)
const dayOfDocs = await Promise.all(dayOfDocsPromises ?? [])
newObj.points = dayOfDocs.reduce((acc, curr) => acc + Number(curr.data().points ?? 0), 0)
} else if (collection === 'Projects') {
newObj = { ...obj }
delete newObj.grades
Expand Down

0 comments on commit 55ee438

Please sign in to comment.