Skip to content

Commit

Permalink
added new reward type to create edit + view reward modal
Browse files Browse the repository at this point in the history
  • Loading branch information
byronwang93 committed Jan 10, 2025
1 parent d3dfe34 commit 15863d0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 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
3 changes: 3 additions & 0 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

0 comments on commit 15863d0

Please sign in to comment.