Skip to content

Commit

Permalink
Modify application scoring to store last updated metadata by question
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-panhead committed Dec 9, 2024
1 parent 5730621 commit 63b8d9f
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 24 deletions.
26 changes: 12 additions & 14 deletions components/Evaluator/Scoring.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import moment from 'moment'
import { useContext, useEffect, useState } from 'react'
import styled from 'styled-components'
import { APPLICATION_STATUS, COLOR, MAX_SCORE, SCORING, TAGS } from '../../constants'
Expand Down Expand Up @@ -36,11 +35,6 @@ const StyledButton = styled(Button)`
margin-top: 12px;
`

const SmallText = styled.div`
font-size: 0.8em;
color: ${COLOR.GREY_500};
`

// const Label = styled.p`
// color: ${ASSESSMENT_COLOR.LIGHT_GRAY};
// `;
Expand Down Expand Up @@ -92,15 +86,25 @@ export default function Scoring({ shouldDisplay, applicant }) {
break
}
const newScores = { ...scores }
newScores[field] = score
newScores[field] = {
...newScores[field],
score,
}
newScores.BonusScore = qualifyingBonus()
setScores(newScores)
setTotalScore(calculateTotalScore(newScores))
}

const handleSave = async () => {
await updateApplicantScore(applicant._id, scores, comment, user.email)
const updatedScores = await updateApplicantScore(
applicant._id,
scores,
applicant?.score?.scores,
comment,
user.email
)
await updateApplicantStatus(applicant._id, APPLICATION_STATUS.scored.text)
setScores(updatedScores)
}

return (
Expand Down Expand Up @@ -164,12 +168,6 @@ export default function Scoring({ shouldDisplay, applicant }) {
<BottomSection>
<AddTagButton allTags={TAGS} hacker={applicant} />
Total Score: {totalScore} / {MAX_SCORE}
{applicant && (
<SmallText>
Last updated by: {applicant?.score?.lastUpdatedBy} at{' '}
{moment(applicant?.score?.lastUpdated.toDate()).format('MMM Do, YYYY h:mm:ss A')}
</SmallText>
)}
<StyledButton color={COLOR.MIDNIGHT_PURPLE_LIGHT} contentColor={COLOR.WHITE} onClick={handleSave}>
Save
</StyledButton>
Expand Down
20 changes: 16 additions & 4 deletions components/Evaluator/scoreInput.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// these are the blue buttons for the applicantScore sidebar
import React from 'react'
import styled from 'styled-components'
import { ASSESSMENT_COLOR } from '../../constants'
import moment from 'moment'
import { ASSESSMENT_COLOR, COLOR } from '../../constants'
import Number from './numberIcon'

const Container = styled.div`
Expand All @@ -10,14 +11,19 @@ const Container = styled.div`

const ScoreContainer = styled.div`
display: flex;
padding-top: 8px;
padding: 8px 0;
gap: 0.5rem;
`

const Label = styled.label`
color: ${ASSESSMENT_COLOR.LIGHT_GRAY};
`

const SmallText = styled.div`
font-size: 0.8em;
color: ${COLOR.GREY_500};
`

export default function ScoreInput({ label, score, handleClick, maxScore, hasMinusOne }) {
const arr = hasMinusOne ? [-1, ...Array(maxScore.value + 1).keys()] : [...Array(maxScore.value + 1).keys()]

Expand All @@ -33,12 +39,18 @@ export default function ScoreInput({ label, score, handleClick, maxScore, hasMin
{arr.map(num => {
const isActive =
maxScore.weight === 0
? score === num // directly compare score when weight is 0
: score / maxScore.weight === num // use weighted logic otherwise
? score.score === num // directly compare score when weight is 0
: score.score / maxScore.weight === num // use weighted logic otherwise

return <Number label={label} number={num} active={isActive} key={num} handleClick={handleMultipier} />
})}
</ScoreContainer>
{score?.lastUpdated && score?.lastUpdatedBy && (
<SmallText>
Last updated by: {score?.lastUpdatedBy} at{' '}
{moment(score?.lastUpdated.toDate()).format('MMM Do, YYYY h:mm:ss A')}
</SmallText>
)}
</Container>
)
}
25 changes: 20 additions & 5 deletions utility/firebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ if (!firebase.apps.length) {
messagingSenderId: process.env.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID,
}
firebase.initializeApp(config)
firebase.firestore().settings({
ignoreUndefinedProperties: true,
})
}

export const db = firebase.firestore()
Expand Down Expand Up @@ -821,21 +824,33 @@ export const getAllResumes = async () => {
download(finishedZip, 'Resumes', 'application/zip')
}

export const updateApplicantScore = async (applicantID, scores, comment, adminEmail) => {
const totalScore = scores ? calculateTotalScore(scores) : null
export const updateApplicantScore = async (applicantID, newScores, oldScores, comment, adminEmail) => {
const totalScore = newScores ? calculateTotalScore(newScores) : null
const scoresWithUpdatedTimes = Object.entries(newScores).reduce((prev, [question, scoreObj]) => {
const scoreChanged = oldScores[question]?.score !== scoreObj.score
return {
...prev,
[question]: {
...scoreObj,
lastUpdated: scoreChanged ? getTimestamp() : oldScores[question].lastUpdated,
lastUpdatedBy: scoreChanged ? adminEmail : oldScores[question].lastUpdatedBy,
},
}
}, {})

db.collection('Hackathons')
.doc(HackerEvaluationHackathon)
.collection('Applicants')
.doc(applicantID)
.update({
score: {
scores,
scores: scoresWithUpdatedTimes,
totalScore,
comment,
lastUpdated: firebase.firestore.Timestamp.now(),
lastUpdatedBy: adminEmail,
},
})

return scoresWithUpdatedTimes
}

export const updateApplicantStatus = async (userId, applicationStatus, hackathon) => {
Expand Down
4 changes: 3 additions & 1 deletion utility/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ export const calculateTotalScore = hackerScore => {
return scoringItem && scoringItem.weight !== 0
})

const totalScore = Object.values(validScores).reduce(reducer, 0)
const totalScore = Object.values(validScores)
.map(score => score?.score ?? 0)
.reduce(reducer, 0)

return Math.min(maxScore, totalScore)
}
Expand Down

0 comments on commit 63b8d9f

Please sign in to comment.