-
Notifications
You must be signed in to change notification settings - Fork 2
Refactor to accept multiquestion #204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
selankon
wants to merge
36
commits into
main
Choose a base branch
from
f/implement-multiprocess-questions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 13 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
5816b47
Refactor questions to accept multiple elections
selankon 20264f4
Permit change election form id
selankon 26958af
Extract getVotePackage function
selankon 4920506
Split VoteButton logic
selankon 47e25bf
Refactor name
selankon ba17720
Fix isInvalid lint error
selankon 9c1ac44
Add MultiElection files
selankon 473d2f3
Simplify validation function
selankon bd67227
Use relative imports
selankon 321b048
Added ffjavascript resolution to fix version clash issues in tests
elboletaire 8f4a830
Use null instead of empty fragment
selankon c745e91
Delete sameLengthValidator
selankon ef03ef0
Merge Multielection with the normal form
selankon 084cbb9
Deprecate multielection confirmation
selankon 4fd42c6
Use election id as form id
selankon d6e3168
Fix warn message
selankon 41fb9b5
Fix unused variable
selankon a3a9997
Export component
selankon 8691569
Fix multielection layout
selankon ec21eae
Implement MultipleElectionVoted
selankon 23d4490
Fix lintern
selankon a3038b6
Refactor variable name
selankon 2c09335
Create FormFieldValues type
selankon c9f7176
Expose isDisabled to manually disable the form
selankon 32181c9
Expose onSubmit handler
selankon 47c0eb1
Fix lint
selankon a9c1796
Fix version
selankon 8fc54f9
Delete uneeded resolution
selankon ee98753
Fix null
selankon 0c59e5e
Add chakra.form
selankon aa4958c
Use isDisabled properly
selankon 27eb8cd
Fix renderWith logout
selankon b1493f3
Implement loaded state
selankon dd00b01
Fix not renderWith elections loaded state
selankon 4d94f49
Delete global error logic
selankon 562beb1
Add missing dependency
selankon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,5 +6,6 @@ vite.config.ts.timestamp-*.mjs | |
| .vscode | ||
| .yarn | ||
| .yarnrc* | ||
| .idea | ||
|
|
||
| package.json.backup | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
packages/chakra-components/src/components/Election/Questions/MultiElectionConfirmation.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| import { Button } from '@chakra-ui/button' | ||
| import { Box, Text } from '@chakra-ui/layout' | ||
| import { ModalBody, ModalCloseButton, ModalFooter, ModalHeader } from '@chakra-ui/modal' | ||
| import { chakra, omitThemingProps, useMultiStyleConfig } from '@chakra-ui/system' | ||
| import { useClient } from '@vocdoni/react-providers' | ||
| import { ElectionResultsTypeNames } from '@vocdoni/sdk' | ||
| import { FieldValues } from 'react-hook-form' | ||
| import { useConfirm } from '../../layout' | ||
| import { ElectionStateStorage } from './Questions' | ||
|
|
||
| export type MultiElectionConfirmationProps = { | ||
| answers: Record<string, FieldValues> | ||
| elections: ElectionStateStorage | ||
| } | ||
|
|
||
| // todo(kon): refactor this to merge it with the current Confirmation modal | ||
elboletaire marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| export const MultiElectionConfirmation = ({ answers, elections, ...rest }: MultiElectionConfirmationProps) => { | ||
| const mstyles = useMultiStyleConfig('ConfirmModal') | ||
| const styles = useMultiStyleConfig('QuestionsConfirmation', rest) | ||
| const { cancel, proceed } = useConfirm() | ||
| const props = omitThemingProps(rest) | ||
| const { localize } = useClient() | ||
| return ( | ||
| <> | ||
| <ModalHeader sx={mstyles.header}>{localize('confirm.title')}</ModalHeader> | ||
| <ModalCloseButton sx={mstyles.close} /> | ||
| <ModalBody sx={mstyles.body}> | ||
| <Text sx={styles.description}>{localize('vote.confirm')}</Text> | ||
| {Object.values(elections).map(({ election, voted, isAbleToVote }) => { | ||
| // if (voted) | ||
| // return ( | ||
| // <chakra.div __css={styles.question} key={election.id}> | ||
| // <chakra.div __css={styles.title}>{election.title.default}</chakra.div> | ||
| // <chakra.div __css={styles.answer}>{localize('vote.already_voted')}</chakra.div> | ||
| // </chakra.div> | ||
| // ) | ||
elboletaire marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (!isAbleToVote) | ||
| return ( | ||
| <chakra.div __css={styles.question} key={election.id}> | ||
| <chakra.div __css={styles.title}>{election.title.default}</chakra.div> | ||
| <chakra.div __css={styles.answer}>{localize('vote.not_able_to_vote')}</chakra.div> | ||
| </chakra.div> | ||
| ) | ||
| return ( | ||
| <Box key={election.id} {...props} sx={styles.box}> | ||
| {/*todo(kon): refactor to add election title and if already voted but can overwrite*/} | ||
elboletaire marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| {election.questions.map((q, k) => { | ||
| if (election.resultsType.name === ElectionResultsTypeNames.SINGLE_CHOICE_MULTIQUESTION) { | ||
| const choice = q.choices.find((v) => v.value === parseInt(answers[election.id][k.toString()], 10)) | ||
| return ( | ||
| <chakra.div key={k} __css={styles.question}> | ||
| <chakra.div __css={styles.title}>{q.title.default}</chakra.div> | ||
| <chakra.div __css={styles.answer}>{choice?.title.default}</chakra.div> | ||
| </chakra.div> | ||
| ) | ||
| } | ||
| const choices = answers[election.id][0] | ||
| .map((a: string) => | ||
| q.choices[Number(a)] ? q.choices[Number(a)].title.default : localize('vote.abstain') | ||
| ) | ||
| .map((a: string) => ( | ||
| <span> | ||
| - {a} | ||
| <br /> | ||
| </span> | ||
| )) | ||
|
|
||
| return ( | ||
| <chakra.div key={k} __css={styles.question}> | ||
| <chakra.div __css={styles.title}>{q.title.default}</chakra.div> | ||
| <chakra.div __css={styles.answer}>{choices}</chakra.div> | ||
| </chakra.div> | ||
| ) | ||
| })} | ||
| </Box> | ||
| ) | ||
| })} | ||
| </ModalBody> | ||
| <ModalFooter sx={mstyles.footer}> | ||
| <Button onClick={cancel!} variant='ghost' sx={mstyles.cancel}> | ||
| {localize('confirm.cancel')} | ||
| </Button> | ||
| <Button onClick={proceed!} sx={mstyles.confirm}> | ||
| {localize('confirm.confirm')} | ||
| </Button> | ||
| </ModalFooter> | ||
| </> | ||
| ) | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.