Skip to content

Commit

Permalink
Split VoteButton logic
Browse files Browse the repository at this point in the history
  • Loading branch information
selankon committed Oct 10, 2024
1 parent 091d095 commit 78df412
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ export const QuestionField = ({ question, index }: QuestionFieldProps) => {
formState: { errors },
} = useFormContext()

const [key, i] = index.split('.')

const [election, questionI] = index.split('.')
return (
<chakra.div __css={styles.question}>
<FormControl isInvalid={!!errors[key]?.[Number(i)]}>
<FormControl isInvalid={!!errors[election]?.[Number(questionI)]}>
<chakra.div __css={styles.header}>
<chakra.label __css={styles.title}>{question.title.default}</chakra.label>
</chakra.div>
Expand Down
17 changes: 13 additions & 4 deletions packages/chakra-components/src/components/Election/VoteButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,24 @@ import { ButtonProps } from '@chakra-ui/button'
import { Text } from '@chakra-ui/layout'
import { chakra, useMultiStyleConfig } from '@chakra-ui/system'
import { Signer } from '@ethersproject/abstract-signer'
import { useClient, useElection } from '@vocdoni/react-providers'
import { ElectionState, useClient, useElection } from '@vocdoni/react-providers'
import { ElectionStatus, InvalidElection, PublishedElection } from '@vocdoni/sdk'
import { useContext, useEffect, useState } from 'react'
import { useEffect, useState } from 'react'
import { Button } from '../layout/Button'
import { results } from './Results'
import { MultiElectionsContext } from './Questions/MultiElectionContext'
import { DefaultElectionFormId } from './Questions'

export const VoteButton = (props: ButtonProps) => {
const election = useElection()
return <VoteButtonLogic {...props} electionState={election} />
}

export const VoteButtonLogic = ({
electionState,
...props
}: {
electionState: ElectionState
} & ButtonProps) => {
const { connected } = useClient()
const {
client,
Expand All @@ -23,7 +32,7 @@ export const VoteButton = (props: ButtonProps) => {
localize,
sik: { signature },
sikSignature,
} = useElection()
} = electionState
const [loading, setLoading] = useState<boolean>(false)

if (!election || election instanceof InvalidElection) {
Expand Down

0 comments on commit 78df412

Please sign in to comment.