|
| 1 | +import { useEffect } from 'react'; |
1 | 2 | import { Card } from 'components/Card'; |
2 | 3 | import { Box, Heading } from '@chakra-ui/react'; |
3 | 4 | import { Text } from '@chakra-ui/react'; |
| 5 | +import BasicVoteExample from './BasicVoteExample'; |
4 | 6 | import ChoiceOptionCreator from './ChoiceOptionCreator'; |
5 | 7 | import RankedVoteExample from './RankedVoteExample'; |
6 | 8 | import SingleVoteExample from './SingleVoteExample'; |
7 | 9 |
|
| 10 | +const getDescription = (voteType) => { |
| 11 | + switch (voteType) { |
| 12 | + case 'single-choice': |
| 13 | + return ( |
| 14 | + <Text color={'grey.500'} mb={4}> |
| 15 | + Provide the specific options you’d like to cast votes for. Use |
| 16 | + Text-based presentation for choices that are described in words. Use |
| 17 | + Visual for side-by-side visual options represented by images. |
| 18 | + </Text> |
| 19 | + ); |
| 20 | + case 'ranked-choice': |
| 21 | + return ( |
| 22 | + <> |
| 23 | + <Text color={'grey.500'} mb={4}> |
| 24 | + Provide the specific options you’d like to cast votes for. Ranked |
| 25 | + Choice Voting currently only supports Text-based presentation for |
| 26 | + choices that are described in words. |
| 27 | + </Text> |
| 28 | + <Text color={'grey.500'} mb={4} fontWeight="bold" fontSize="sm"> |
| 29 | + All choices will be randomized for voters |
| 30 | + </Text> |
| 31 | + </> |
| 32 | + ); |
| 33 | + default: |
| 34 | + return ( |
| 35 | + <Text color={'grey.500'} mb={4}> |
| 36 | + No choices required. Voters will be presented with For, Against or |
| 37 | + Abstain. |
| 38 | + </Text> |
| 39 | + ); |
| 40 | + } |
| 41 | +}; |
| 42 | + |
8 | 43 | export default function VotingSelector({ |
9 | 44 | voteType, |
10 | 45 | setValue, |
@@ -72,6 +107,37 @@ export default function VotingSelector({ |
72 | 107 | <SingleVoteExample /> |
73 | 108 | </div> |
74 | 109 | </Card> |
| 110 | + <Card |
| 111 | + variant="votingType" |
| 112 | + mb={4} |
| 113 | + onClick={() => |
| 114 | + setValue('voteType', 'basic', { shouldValidate: true }) |
| 115 | + } |
| 116 | + className={voteType === 'basic' ? 'border-grey' : ''} |
| 117 | + > |
| 118 | + <div className="p-4"> |
| 119 | + <div className="is-flex is-align-items-center mr-2"> |
| 120 | + <label className="radio is-flex"> |
| 121 | + <input |
| 122 | + {...register('voteType')} |
| 123 | + type="radio" |
| 124 | + value="basic" |
| 125 | + className="green-radio" |
| 126 | + /> |
| 127 | + </label> |
| 128 | + </div> |
| 129 | + </div> |
| 130 | + <div className="py-5 pr-5"> |
| 131 | + <h5 className="title is-6 mb-2">Basic Voting</h5> |
| 132 | + <p> |
| 133 | + Voters vote on one option and are given three options to vote |
| 134 | + on. (For, Against or Abstain) |
| 135 | + </p> |
| 136 | + </div> |
| 137 | + <div className="has-background-light-grey p-4 is-hidden-mobile rounded-sm-br rounded-sm-tr is-flex is-flex-direction-column is-align-self-stretch is-justify-content-center"> |
| 138 | + <BasicVoteExample /> |
| 139 | + </div> |
| 140 | + </Card> |
75 | 141 | <Card |
76 | 142 | variant="votingType" |
77 | 143 | mb={4} |
@@ -107,35 +173,23 @@ export default function VotingSelector({ |
107 | 173 | </div> |
108 | 174 | <div className="border-light-tablet rounded-lg columns is-flex-direction-column is-mobile m-0 p-6 p-0-mobile mb-6"> |
109 | 175 | <Heading as="h4" fontSize="2xl" mb={2}> |
110 | | - Choices <span className="has-text-danger">*</span> |
| 176 | + Choices{' '} |
| 177 | + {voteType !== 'basic' ? ( |
| 178 | + <span className="has-text-danger">*</span> |
| 179 | + ) : null} |
111 | 180 | </Heading> |
112 | | - {voteType === 'single-choice' ? ( |
113 | | - <Text color={'grey.500'} mb={4}> |
114 | | - Provide the specific options you’d like to cast votes for. Use |
115 | | - Text-based presentation for choices that are described in words. Use |
116 | | - Visual for side-by-side visual options represented by images. |
117 | | - </Text> |
118 | | - ) : ( |
119 | | - <> |
120 | | - <Text color={'grey.500'} mb={4}> |
121 | | - Provide the specific options you’d like to cast votes for. Ranked |
122 | | - Choice Voting currently only supports Text-based presentation for |
123 | | - choices that are described in words. |
124 | | - </Text> |
125 | | - <Text color={'grey.500'} mb={4} fontWeight="bold" fontSize="sm"> |
126 | | - All choices will be randomized for voters |
127 | | - </Text> |
128 | | - </> |
129 | | - )} |
130 | | - <ChoiceOptionCreator |
131 | | - setValue={setValue} |
132 | | - error={errors['choices']} |
133 | | - fieldName="choices" |
134 | | - register={register} |
135 | | - control={control} |
136 | | - clearErrors={clearErrors} |
137 | | - voteType={voteType} |
138 | | - /> |
| 181 | + {getDescription(voteType)} |
| 182 | + {voteType !== 'basic' ? ( |
| 183 | + <ChoiceOptionCreator |
| 184 | + setValue={setValue} |
| 185 | + error={errors['choices']} |
| 186 | + fieldName="choices" |
| 187 | + register={register} |
| 188 | + control={control} |
| 189 | + clearErrors={clearErrors} |
| 190 | + voteType={voteType} |
| 191 | + /> |
| 192 | + ) : null} |
139 | 193 | </div> |
140 | 194 | </> |
141 | 195 | ); |
|
0 commit comments