Skip to content

Commit

Permalink
fix: allow author to vote
Browse files Browse the repository at this point in the history
  • Loading branch information
KaustubhKumar05 committed Mar 12, 2024
1 parent fe96a7b commit 34f1af4
Showing 1 changed file with 32 additions and 32 deletions.
64 changes: 32 additions & 32 deletions app/components/PollVotes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,37 @@ export const PollVotes = ({ poll }: { poll: HMSPoll }) => {
<ProgressBar percentage={totalCount ? voteCount[index] / totalCount : 0} />
</div>
))}

<button
style={{
width: '100%',
textAlign: 'center',
background: 'var(--primary_default)',
color: 'white',
display: 'block',
padding: '0.75rem',
margin: '18px 0',
}}
disabled={hasVoted}
onClick={async () => {
try {
await hmsActions.interactivityCenter
.addResponsesToPoll(poll.id, [
{
questionIndex: poll.questions[0].index,
option: selectedOptionIndex + 1,
},
])
.then(() => toast(`Your vote has been submitted for "${question.text}`))
} catch (err) {
console.log(err.message)
toast.error('Failed to submit vote. Please try again or reach out to the team.')
}
}}
>
Submit
</button>

{isPollAuthor ? (
<button
style={{
Expand All @@ -82,43 +113,12 @@ export const PollVotes = ({ poll }: { poll: HMSPoll }) => {
background: 'var(--error_default)',
display: 'block',
padding: '0.75rem',
marginTop: '18px',
}}
onClick={() => hmsActions.interactivityCenter.stopPoll(poll.id)}
>
End poll
</button>
) : (
<button
style={{
width: '100%',
textAlign: 'center',
background: 'var(--primary_default)',
color: 'white',
display: 'block',
padding: '0.75rem',
marginTop: '18px',
}}
disabled={hasVoted}
onClick={async () => {
try {
await hmsActions.interactivityCenter
.addResponsesToPoll(poll.id, [
{
questionIndex: poll.questions[0].index,
option: selectedOptionIndex + 1,
},
])
.then(() => toast(`Your vote has been submitted for "${question.text}`))
} catch (err) {
console.log(err.message)
toast.error('Failed to submit vote. Please try again or reach out to the team.')
}
}}
>
Submit
</button>
)}
) : null}
</div>
)
}

0 comments on commit 34f1af4

Please sign in to comment.