Skip to content

Commit

Permalink
add lasteditedby and lastedited at
Browse files Browse the repository at this point in the history
  • Loading branch information
tdanielles committed Jul 29, 2024
1 parent 172d36e commit dd563df
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 1 deletion.
25 changes: 25 additions & 0 deletions pages/hackerapps/[id]/basicinfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@ import {
getHackathonPaths,
getHackathons,
updateHackerAppQuestions,
getHackerAppQuestionsMetadata,
formatDate,
getTimestamp,
updateHackerAppQuestionsMetadata,
} from '../../../utility/firebase'
import Page from '../../../components/page'
import { HACKER_APP_NAVBAR, COLOR } from '../../../constants'
import QuestionCard from '../../../components/questionCard'
import Icon from '../../../components/Icon'
import Button from '../../../components/button'
import { useAuth } from '../../../utility/auth'

const HeaderContainer = styled.div`
display: flex;
Expand Down Expand Up @@ -51,17 +56,31 @@ const StyledButton = styled(Button)`
right: 80px;
`

const StyledMetadataP = styled.p`
position: absolute;
top: 100px;
right: 80px;
color: ${COLOR.MIDNIGHT_PURPLE};
`

export default ({ id, hackathons }) => {
const [questions, setQuestions] = useState([
{ title: '', description: '', type: '', options: [''], other: false, required: false },
])
const [metadata, setMetadata] = useState({})
const { email: user } = useAuth().user

useEffect(() => {
const fetchQuestions = async () => {
const appQuestions = await getHackerAppQuestions(id, 'BasicInfo')
setQuestions(appQuestions)
}
const fetchMetadata = async () => {
const fetchedMetadata = await getHackerAppQuestionsMetadata(id, 'BasicInfo')
setMetadata(fetchedMetadata)
}
fetchQuestions()
fetchMetadata()
}, [id])

const addQuestion = index => {
Expand Down Expand Up @@ -113,6 +132,9 @@ export default ({ id, hackathons }) => {

const handleSave = async hackathon => {
await updateHackerAppQuestions(hackathon, questions, 'BasicInfo')
const newMetadata = { lastEditedAt: getTimestamp(), lastEditedBy: user }
setMetadata(newMetadata)
await updateHackerAppQuestionsMetadata(hackathon, 'BasicInfo', newMetadata)
alert('Questions were saved to the database!')
}

Expand All @@ -135,6 +157,9 @@ export default ({ id, hackathons }) => {
<Icon color={COLOR.WHITE} icon="save" />
Save
</StyledButton>
<StyledMetadataP>{`Last Edited by ${metadata.lastEditedBy} at ${formatDate(
metadata.lastEditedAt?.seconds
)}`}</StyledMetadataP>
<HeaderContainer>
<Header>2. Add basic information questions</Header>
</HeaderContainer>
Expand Down
25 changes: 25 additions & 0 deletions pages/hackerapps/[id]/skills.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@ import {
getHackathons,
getHackerAppQuestions,
updateHackerAppQuestions,
getHackerAppQuestionsMetadata,
formatDate,
getTimestamp,
updateHackerAppQuestionsMetadata,
} from '../../../utility/firebase'
import Page from '../../../components/page'
import { HACKER_APP_NAVBAR, COLOR } from '../../../constants'
import QuestionCard from '../../../components/questionCard'
import Icon from '../../../components/Icon'
import Button from '../../../components/button'
import { useAuth } from '../../../utility/auth'

const HeaderContainer = styled.div`
display: flex;
Expand Down Expand Up @@ -51,17 +56,31 @@ const StyledButton = styled(Button)`
right: 80px;
`

const StyledMetadataP = styled.p`
position: absolute;
top: 100px;
right: 80px;
color: ${COLOR.MIDNIGHT_PURPLE};
`

export default ({ id, hackathons }) => {
const [questions, setQuestions] = useState([
{ title: '', description: '', type: '', options: [''], other: false, required: false },
])
const [metadata, setMetadata] = useState({})
const { email: user } = useAuth().user

useEffect(() => {
const fetchQuestions = async () => {
const appQuestions = await getHackerAppQuestions(id, 'Skills')
setQuestions(appQuestions)
}
const fetchMetadata = async () => {
const fetchedMetadata = await getHackerAppQuestionsMetadata(id, 'Skills')
setMetadata(fetchedMetadata)
}
fetchQuestions()
fetchMetadata()
}, [id])

const addQuestion = index => {
Expand Down Expand Up @@ -113,6 +132,9 @@ export default ({ id, hackathons }) => {

const handleSave = async hackathon => {
await updateHackerAppQuestions(hackathon, questions, 'Skills')
const newMetadata = { lastEditedAt: getTimestamp(), lastEditedBy: user }
setMetadata(newMetadata)
await updateHackerAppQuestionsMetadata(hackathon, 'Skills', newMetadata)
alert('Questions were saved to the database!')
}

Expand All @@ -135,6 +157,9 @@ export default ({ id, hackathons }) => {
<Icon color={COLOR.WHITE} icon="save" />
Save
</StyledButton>
<StyledMetadataP>{`Last Edited by ${metadata.lastEditedBy} at ${formatDate(
metadata.lastEditedAt?.seconds
)}`}</StyledMetadataP>
<HeaderContainer>
<Header>3. Add skills and long answer questions</Header>
</HeaderContainer>
Expand Down
25 changes: 25 additions & 0 deletions pages/hackerapps/[id]/welcome.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ import {
getHackathons,
updateHackerAppQuestions,
getHackerAppQuestions,
getHackerAppQuestionsMetadata,
formatDate,
getTimestamp,
updateHackerAppQuestionsMetadata,
} from '../../../utility/firebase'
import Button from '../../../components/button'
import Icon from '../../../components/Icon'
import { useAuth } from '../../../utility/auth'

const ReactQuill = dynamic(() => import('react-quill'), { ssr: false })

Expand Down Expand Up @@ -62,6 +67,13 @@ const StyledButton = styled(Button)`
right: 80px;
`

const StyledMetadataP = styled.p`
position: absolute;
top: 100px;
right: 80px;
color: ${COLOR.MIDNIGHT_PURPLE};
`

const descModules = {
toolbar: [
['bold', 'italic', 'underline', 'strike', 'blockquote'],
Expand All @@ -76,19 +88,29 @@ const formats = ['bold', 'italic', 'underline', 'strike', 'blockquote', 'list',
export default ({ id, hackathons }) => {
const [title, setTitle] = useState('')
const [content, setContent] = useState('')
const [metadata, setMetadata] = useState({})
const { email: user } = useAuth().user

useEffect(() => {
const fetchQuestions = async () => {
const questions = await getHackerAppQuestions(id, 'Welcome')
setTitle(questions[0].title || '')
setContent(questions[0].content || '')
}
const fetchMetadata = async () => {
const fetchedMetadata = await getHackerAppQuestionsMetadata(id, 'Welcome')
setMetadata(fetchedMetadata)
}
fetchQuestions()
fetchMetadata()
}, [id])

const handleSave = async hackathon => {
const questions = [{ title: title, content: content }]
await updateHackerAppQuestions(hackathon, questions, 'Welcome')
const newMetadata = { lastEditedAt: getTimestamp(), lastEditedBy: user }
setMetadata(newMetadata)
await updateHackerAppQuestionsMetadata(hackathon, 'Welcome', newMetadata)
alert('Questions were saved to the database!')
}

Expand All @@ -111,6 +133,9 @@ export default ({ id, hackathons }) => {
<Icon color={COLOR.WHITE} icon="save" />
Save
</StyledButton>
<StyledMetadataP>{`Last Edited by ${metadata.lastEditedBy} at ${formatDate(
metadata.lastEditedAt?.seconds
)}`}</StyledMetadataP>
<HeaderContainer>
<Header>1. Add a title and description</Header>
</HeaderContainer>
Expand Down
16 changes: 15 additions & 1 deletion utility/firebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ export const updateApplicantTags = async (userId, applicantTags) => {
.update({ applicantTags })
}

// hacker application questions
// hacker application questions specific
export const getHackerAppQuestions = async (selectedHackathon, category) => {
const data = await db.collection('HackerAppQuestions').doc(selectedHackathon.slice(0, -4)).collection(category).get()
return data.docs.map(doc => doc.data())
Expand All @@ -771,3 +771,17 @@ export const updateHackerAppQuestions = async (selectedHackathon, questions, cat
})
await batch.commit()
}

export const getHackerAppQuestionsMetadata = async (selectedHackathon, category) => {
const categoryRef = await db.collection('HackerAppQuestions').doc(selectedHackathon.slice(0, -4)).get()
return categoryRef.data()[category]
}

export const updateHackerAppQuestionsMetadata = async (selectedHackathon, category, updatedMetadata) => {
const doc = {
[category]: updatedMetadata,
}
return db.collection('HackerAppQuestions').doc(selectedHackathon.slice(0, -4)).set(doc, { merge: true })
}

// hacker application questions specific end

0 comments on commit dd563df

Please sign in to comment.