From 15863d071f973dd10211f89a076b54c7f7203dec Mon Sep 17 00:00:00 2001 From: byronwang93 Date: Thu, 9 Jan 2025 16:15:51 -0800 Subject: [PATCH] added new reward type to create edit + view reward modal --- pages/[id]/rewards.js | 39 +++++++++++++++++++++++++++++++++++++-- utility/firebase.js | 3 +++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/pages/[id]/rewards.js b/pages/[id]/rewards.js index f854a902..7e740f40 100644 --- a/pages/[id]/rewards.js +++ b/pages/[id]/rewards.js @@ -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) { @@ -116,6 +118,7 @@ export default function Rewards({ id, hackathons }) { return ( {props.reward} + {props.type} {props.blurb} {props.prizesAvailable} {props.requiredPoints} @@ -143,11 +146,12 @@ export default function Rewards({ id, hackathons }) { @@ -175,6 +179,7 @@ export default function Rewards({ id, hackathons }) { Reward + Type Blurb Number of Prizes Available Required Points @@ -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} @@ -216,6 +222,17 @@ export default function Rewards({ id, hackathons }) { onChange={reward => handleInput('reward', reward.target.value, newReward, setNewReward)} /> + + { + handleInput('type', type.label, newReward, setNewReward) + }} + /> + + + + @@ -303,6 +323,18 @@ export default function Rewards({ id, hackathons }) { }} /> + + { + handleInput('type', type.label, rewardEditing, setRewardEditing) + }} + /> + + + + diff --git a/utility/firebase.js b/utility/firebase.js index dce8ef23..a356baf2 100644 --- a/utility/firebase.js +++ b/utility/firebase.js @@ -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) @@ -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 @@ -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',