Skip to content

Commit

Permalink
Disable some actions while voting
Browse files Browse the repository at this point in the history
  • Loading branch information
elboletaire committed Dec 1, 2023
1 parent 93919ca commit dd799a1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
14 changes: 8 additions & 6 deletions packages/chakra-components/src/components/Election/Questions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,16 @@ type QuestionFieldProps = ChakraProps & {

const QuestionField = ({ question, index }: QuestionFieldProps) => {
const styles = useMultiStyleConfig('ElectionQuestions')
const { election, isAbleToVote, localize } = useElection()
const {
election,
isAbleToVote,
localize,
loading: { voting },
} = useElection()
const {
formState: { errors },
} = useFormContext()
const disabled = election?.status !== ElectionStatus.ONGOING || !isAbleToVote || voting

return (
<chakra.div __css={styles.question}>
Expand All @@ -190,11 +196,7 @@ const QuestionField = ({ question, index }: QuestionFieldProps) => {
rules={{ required: localize('validation.required') }}
name={index}
render={({ field }) => (
<RadioGroup
sx={styles.radioGroup}
{...field}
isDisabled={election?.status !== ElectionStatus.ONGOING || !isAbleToVote}
>
<RadioGroup sx={styles.radioGroup} {...field} isDisabled={disabled}>
<Stack direction='column' sx={styles.stack}>
{question.choices.map((choice, ck) => (
<Radio key={ck} sx={styles.radio} value={choice.value.toString()}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@ export const SpreadsheetAccess = (rest: ChakraProps) => {
const [loading, setLoading] = useState<boolean>(false)
const toast = useToast()
const { env, client: cl } = useClient()
const { election, setClient, localize, fetchCensus, sikPassword, sikSignature } = useElection()
const {
election,
setClient,
localize,
fetchCensus,
sikPassword,
sikSignature,
loading: { voting },
} = useElection()
const fields: string[] = dotobject(election, 'meta.census.fields')
const {
register,
Expand Down Expand Up @@ -111,7 +119,7 @@ export const SpreadsheetAccess = (rest: ChakraProps) => {

if (connected) {
return (
<Button onClick={clearClient} sx={styles.disconnect}>
<Button onClick={clearClient} sx={styles.disconnect} isDisabled={voting}>
{localize('spreadsheet.logout')}
</Button>
)
Expand Down

0 comments on commit dd799a1

Please sign in to comment.