Skip to content

Commit

Permalink
feat: show Abstain option
Browse files Browse the repository at this point in the history
  • Loading branch information
elboletaire committed Feb 6, 2025
1 parent e9f21bc commit ea51cae
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@emotion/styled": "^11.10.6",
"@rainbow-me/rainbowkit": "^2.1.2",
"@tanstack/react-query": "^5.40.1",
"@vocdoni/chakra-components": "~0.9.7",
"@vocdoni/chakra-components": "~0.9.8",
"@vocdoni/sdk": "~0.9.1",
"date-fns": "^4.1.0",
"ethers": "^5.7.2",
Expand Down
9 changes: 8 additions & 1 deletion src/components/Process/Aside.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,13 @@ const ProcessAside = () => {

export const VoteButton = ({ ...props }: FlexProps) => {
const { t } = useTranslation()
const { election, connected, isAbleToVote, isInCensus } = useElection()
const {
election,
connected,
isAbleToVote,
isInCensus,
loading: { voting },
} = useElection()
const { isConnected } = useAccount()

if (!(election instanceof PublishedElection)) {
Expand Down Expand Up @@ -272,6 +278,7 @@ export const VoteButton = ({ ...props }: FlexProps) => {
opacity: '0.8',
},
}}
isLoading={voting}
/>
{isWeighted && <VoteWeight />}
</>
Expand Down
4 changes: 2 additions & 2 deletions src/components/Process/Chained.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Box, Progress } from '@chakra-ui/react'
import { ConnectButton } from '@rainbow-me/rainbowkit'
import { ElectionQuestions, ElectionResults, SpreadsheetAccess } from '@vocdoni/chakra-components'
import { ElectionProvider, useElection } from '@vocdoni/react-providers'
import { ArchivedElection, InvalidElection, IVotePackage, PublishedElection, VocdoniSDKClient } from '@vocdoni/sdk'
import { InvalidElection, IVotePackage, PublishedElection, VocdoniSDKClient } from '@vocdoni/sdk'
import { useEffect, useState } from 'react'
import { Trans } from 'react-i18next'
import { VoteButton } from './Aside'
Expand Down Expand Up @@ -68,7 +68,7 @@ const ChainedProcessesInner = ({ connected }: ChainedProcessesInnerProps) => {
}

type ChainedProcessesProps = {
root?: PublishedElection | ArchivedElection | InvalidElection
root?: PublishedElection | InvalidElection
}

export const ChainedProcesses = ({ root }: ChainedProcessesProps) => {
Expand Down
14 changes: 13 additions & 1 deletion src/components/Process/ConfirmVoteModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ export const ConfirmVoteModal = ({ election, answers }: { election: PublishedEle

const ConfirmMultiquestion = ({ question, answers }: { question: IQuestion; answers: FieldValues }) => {
const { t } = useTranslation()

// Add abstain option to choices if needed
const choices = [...question.choices]
if (answers[0].includes('-1')) {
choices[-1] = {
title: {
default: t('cc.vote.abstain'),
},
value: -1,
}
}

return (
<Text display='flex' flexDirection='column' gap={1}>
<Trans
Expand All @@ -91,7 +103,7 @@ const ConfirmMultiquestion = ({ question, answers }: { question: IQuestion; answ
answers[0].length === 0
? t('process.spreadsheet.confirm.blank_vote')
: answers[0]
.map((a: string) => question.choices[Number(a)].title.default)
.map((a: string) => choices[Number(a)].title.default)
.map((a: string) => `- ${a}`)
.join('<br />'),
}}
Expand Down
4 changes: 2 additions & 2 deletions src/elements/Home/Berga.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ const Berga = () => (
<strong>Seleccioneu</strong> una opció depenent de la teva edat
</Text>
<Flex gap={5} flexDirection={{ base: 'column', md: 'row' }}>
<ProcessLink id='6be21a5a9dc0d60812a70bb63b3693846873c371c2463472a4d3020800000006'>
<ProcessLink id='6be21a5a9dc0d60812a70bb63b3693846873c371c2463472a4d302080000000c'>
<Text fontSize='18px'>Accedeix a la votació Juvenil</Text>
<Text>12 - 15 anys</Text>
</ProcessLink>
<ProcessLink id='6be21a5a9dc0d60812a70bb63b3693846873c371c2463472a4d3020000000007'>
<ProcessLink id='6be21a5a9dc0d60812a70bb63b3693846873c371c2463472a4d302000000000d'>
<Text fontSize='18px'>Accedeix a la votació General</Text>
<Text>+16 anys</Text>
</ProcessLink>
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2766,10 +2766,10 @@
"@types/babel__core" "^7.20.5"
react-refresh "^0.14.2"

"@vocdoni/chakra-components@~0.9.7":
version "0.9.7"
resolved "https://registry.yarnpkg.com/@vocdoni/chakra-components/-/chakra-components-0.9.7.tgz#53cbcc1056c506442bb92e802079e22649fb77e4"
integrity sha512-UUOSzGfu/83n++8aL+8TdqHerw8uHHmBMIo5sf2Ps3qhIyTojAGWll4/POjE7FXyxf5jCOLZm48enxhozctpJg==
"@vocdoni/chakra-components@~0.9.8":
version "0.9.8"
resolved "https://registry.yarnpkg.com/@vocdoni/chakra-components/-/chakra-components-0.9.8.tgz#99a16a227cbde36fbb1ce255e466a1a122e329c6"
integrity sha512-jbLw60J/TWjlTFlvkTBcj6TA25ZmiWtXbRe7gqYRFRn+jYT6GFaGDvl/C0L8W8iv73tgK5BI/PRkBYJh5Duxxg==
dependencies:
"@vocdoni/react-providers" "~0.5.1"

Expand Down

1 comment on commit ea51cae

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.