Skip to content

Commit

Permalink
Allow a nomination to be viewed if it is yours or it is voting period
Browse files Browse the repository at this point in the history
Signed-off-by: miam-miam100 <[email protected]>
  • Loading branch information
miam-miam committed Mar 2, 2024
1 parent 756782a commit 5bab7d4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/app/(pages)/elections/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default async function Elections() {
</p>
<Positions
positions={positions}
electionId={id}
election={election}
canCreateNominations={canCreateNomination}
user={user}
/>
Expand Down
21 changes: 16 additions & 5 deletions src/app/_components/Nominations/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import classes from './index.module.scss'

export const Nominations: React.FC<{
positionId?: string
electionId?: string
election?: Election
user?: User
}> = props => {
const { positionId, electionId, user } = props
const { positionId, election, user } = props

let [nominations, setNominations] = useState<Nomination[] | null>(null)

Expand All @@ -47,7 +47,7 @@ export const Nominations: React.FC<{
},
],
},
{ election: { equals: electionId } },
{ election: { equals: election.id } },
{ position: { equals: positionId } },
],
},
Expand All @@ -69,8 +69,12 @@ export const Nominations: React.FC<{
}
}
getPositions().then(setNominations)
}, [user, positionId, electionId])
// underline nickname when the nomination has dropped out
}, [user, positionId, election.id])

const isBeingVoted =
new Date().getTime() >= Date.parse(election.votingStart) &&
new Date().getTime() <= Date.parse(election.votingEnd)

return (
<div>
{nominations?.map((nomination, index) => {
Expand All @@ -91,6 +95,13 @@ export const Nominations: React.FC<{
{nickname ?? nomineeNames} ({usernames}){' '}
</span>
)}
{(isBeingVoted || populatedNominees.map(n => n.id).includes(user.id)) && (
<Button
appearance={'primary'}
label={'View'}
href={`/nominations/${nomination.id}`}
/>
)}
<SupportNomination nominationId={id} supporters={supporters} />
</h5>
</Fragment>
Expand Down
8 changes: 4 additions & 4 deletions src/app/_components/Positions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ import classes from './index.module.scss'

export const Positions: React.FC<{
positions?: Position[]
electionId?: string
election?: Election
canCreateNominations?: boolean
user?: User
}> = props => {
const { user, positions, electionId, canCreateNominations } = props
const { user, positions, election, canCreateNominations } = props

// const { slug, title, categories, meta } = doc || {}
// const { description, image: metaImage } = meta || {}
Expand All @@ -48,12 +48,12 @@ export const Positions: React.FC<{
<p>{description}</p>
{canCreateNominations && (
<Button
href={`/nominations/${electionId}/${position.id}`}
href={`/nominations/${election.id}/${position.id}`}
appearance="primary"
label={'Create Nomination'}
></Button>
)}
<Nominations positionId={position.id} electionId={electionId} user={user} />
<Nominations positionId={position.id} election={election} user={user} />
</Fragment>
)
})}
Expand Down

0 comments on commit 5bab7d4

Please sign in to comment.