Skip to content
This repository was archived by the owner on Mar 11, 2024. It is now read-only.

Commit 9b244f5

Browse files
committed
refactor(client): Adds type fixes
1 parent 72dc8f6 commit 9b244f5

File tree

11 files changed

+238
-166
lines changed

11 files changed

+238
-166
lines changed

src/components/inscribete/FindVoterCenter/FindYourCenter.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ import { useTranslation } from "react-i18next"
55

66
import Button from "../../button"
77
import Typography from "../../typography"
8-
import { findYourCenterMachine } from "./findYourCenterMachine"
8+
import { FindYourCenterMachine } from "./findYourCenterMachine"
99
import Link from "../../link"
1010

1111
const EMBED_LINK_BASE =
1212
"https://maps.google.com/maps?t=&z=13&ie=UTF8&iwloc=&output=embed&q="
1313

1414
export const FindYourCenter = () => {
1515
const { t } = useTranslation()
16-
const [current, send] = useMachine(findYourCenterMachine)
16+
const [current, send] = useMachine(FindYourCenterMachine)
1717

1818
const inputRef = useRef<HTMLInputElement>(null)
1919

src/components/inscribete/FindVoterCenter/findYourCenterMachine.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const getVoterDetails = (voterId?: string) => {
99
return VoterInformationResource.getVoterInfo(voterId)
1010
}
1111

12-
export const findYourCenterMachine = createMachine<
12+
export const FindYourCenterMachine = createMachine<
1313
FindYourCenterContext,
1414
FindYourCenterEvent
1515
>(

src/components/inscribete/SpecialVoters/SpecialVoterCards.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ import SpecialVoterCard from "./SpecialVoterCard"
1010
import SpecialVoterReasons from "./SpecialVoterReasons"
1111
import { useTranslation } from "react-i18next"
1212

13+
interface SpecialVotersContext {
14+
previous: string
15+
}
16+
17+
type SpecialVotersEvent =
18+
| { type: "ABSENTEE_VOTER_TOGGLED" }
19+
| { type: "EARLY_VOTER_TOGGLED" }
20+
| { type: "CLOSED" }
21+
1322
const config = {
1423
id: "special-voters",
1524
initial: "idle",
@@ -40,7 +49,7 @@ const config = {
4049
}
4150

4251
const actions = {
43-
handlePrevUpdate: assign({
52+
handlePrevUpdate: assign<SpecialVotersContext, SpecialVotersEvent>({
4453
previous: (context) => {
4554
if (context.previous === "idle") {
4655
return "reasons"
@@ -51,7 +60,10 @@ const actions = {
5160
}),
5261
}
5362

54-
const SpecialVoterMachine = createMachine(config, {
63+
const SpecialVoterMachine = createMachine<
64+
SpecialVotersContext,
65+
SpecialVotersEvent
66+
>(config, {
5567
actions,
5668
})
5769

src/components/switch.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
11
import { ReactComponentElement } from "react"
2-
32
import { State } from "xstate"
43

54
import Case from "./case"
65
import Default from "./default"
76

8-
type Props = {
7+
interface Props {
98
children: Array<ReactComponentElement<any, { value?: string }>>
109
className?: string
11-
state: State<any>
10+
state: State<any, any, any, any, any>
1211
}
1312

1413
export default function Switch({ children, state }: Props) {
15-
const match = children.find(child => {
14+
const match = children.find((child) => {
1615
return (
1716
state.matches(child.props.value) &&
1817
child.type.componentName === Case.componentName
1918
)
2019
})
2120

2221
if (!match) {
23-
const defaultCase = children.find(child => {
22+
const defaultCase = children.find((child) => {
2423
return child.type.componentName === Default.componentName
2524
})
2625

src/packages/generate-ballot/components/ballot.tsx

Lines changed: 114 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type BallotProps = {
4141
type: BallotType
4242
structure: BallotStructure
4343
votes: Vote[]
44-
toggleVote: (
44+
toggleVote?: (
4545
candidate: ElectiveField,
4646
{ row, column }: VotesCoordinates
4747
) => void
@@ -52,8 +52,8 @@ export default function BaseBallot(props: BallotProps) {
5252
props.type === BallotType.state
5353
? "bg-ballots-governmental"
5454
: props.type === BallotType.municipality
55-
? "bg-ballots-municipal"
56-
: "bg-ballots-legislative"
55+
? "bg-ballots-municipal"
56+
: "bg-ballots-legislative"
5757
const { highlightedColumn } = useColumnHighlight()
5858
const isLegislativeBallot = props.type === BallotType.legislative
5959
const ballotWidth =
@@ -72,129 +72,133 @@ export default function BaseBallot(props: BallotProps) {
7272
rowIndex !== 0 ? ballotBg : ""
7373
}`}
7474
>
75-
{row.map(
76-
(col: Party | Rule | Candidate | Header, colIndex: number) => {
77-
const vote = props.votes.find(vote => {
78-
return (
79-
vote.position.row === rowIndex &&
80-
vote.position.column === colIndex
81-
)
82-
})
83-
const hasVote = !!vote
84-
const isExplicitVote = hasVote
85-
? (vote as Vote).wasSelectedExplictly()
86-
: false
87-
const isImplicitVote = hasVote
88-
? (vote as Vote).wasSelectedImplicitly()
89-
: false
90-
const isHighlighted = colIndex === highlightedColumn
91-
const voteType = isExplicitVote
92-
? "explicit-vote"
93-
: isImplicitVote
75+
{row.map((col, colIndex) => {
76+
const vote = props.votes.find((vote) => {
77+
return (
78+
vote.position.row === rowIndex &&
79+
vote.position.column === colIndex
80+
)
81+
})
82+
const hasVote = !!vote
83+
const isExplicitVote = hasVote
84+
? (vote as Vote).wasSelectedExplictly()
85+
: false
86+
const isImplicitVote = hasVote
87+
? (vote as Vote).wasSelectedImplicitly()
88+
: false
89+
const isHighlighted = colIndex === highlightedColumn
90+
const voteType = isExplicitVote
91+
? "explicit-vote"
92+
: isImplicitVote
9493
? "implicit-vote"
9594
: "no-vote"
96-
const voteOpacity = isExplicitVote
97-
? "opacity-100"
98-
: isImplicitVote
95+
const voteOpacity = isExplicitVote
96+
? "opacity-100"
97+
: isImplicitVote
9998
? "opacity-25"
10099
: ""
101100

102-
if (col instanceof Party) {
103-
return (
104-
<Ballot.PoliticalParty
105-
key={col.id}
106-
voteType={voteType}
107-
logo={col.insignia}
108-
ocrResult={col.name}
109-
hasVote={hasVote}
110-
voteOpacity={voteOpacity}
111-
position={colIndex}
112-
isHighlighted={isHighlighted}
113-
toggleVote={() =>
114-
props.toggleVote(col, {
115-
row: rowIndex,
116-
column: colIndex,
117-
})
118-
}
119-
/>
120-
)
121-
}
101+
if (col instanceof Party) {
102+
return (
103+
<Ballot.PoliticalParty
104+
key={col.id}
105+
voteType={voteType}
106+
logo={col.insignia}
107+
ocrResult={col.name}
108+
hasVote={hasVote}
109+
voteOpacity={voteOpacity}
110+
position={colIndex}
111+
isHighlighted={isHighlighted}
112+
toggleVote={() => {
113+
if (props.toggleVote == null) return
122114

123-
if (col instanceof WriteInRules) {
124-
return (
125-
<Ballot.WriteInRules
126-
key={col.id}
127-
esTitle={col.esTitle}
128-
esRules={col.esRules}
129-
enTitle={col.enTitle}
130-
enRules={col.enRules}
131-
/>
132-
)
133-
}
115+
props.toggleVote(col, {
116+
row: rowIndex,
117+
column: colIndex,
118+
})
119+
}}
120+
/>
121+
)
122+
}
134123

135-
if (col instanceof Rule) {
136-
return <Ballot.Rule key={col.id} ocrResult={col.rule} />
137-
}
124+
if (col instanceof WriteInRules) {
125+
return (
126+
<Ballot.WriteInRules
127+
key={col.id}
128+
esTitle={col.esTitle}
129+
esRules={col.esRules}
130+
enTitle={col.enTitle}
131+
enRules={col.enRules}
132+
/>
133+
)
134+
}
138135

139-
if (col instanceof Candidate) {
140-
return (
141-
<Ballot.Candidate
142-
key={col.id}
143-
img={col.img}
144-
name={col.name}
145-
hasVote={hasVote}
146-
voteType={voteType}
147-
voteOpacity={voteOpacity}
148-
accumulationNumber={col.accumulationNumber}
149-
isHighlighted={isHighlighted}
150-
isPartyHighlighted={
151-
isLegislativeBallot
152-
? col.receivesImpicitVote && isHighlighted
153-
: isHighlighted
154-
}
155-
toggleVote={() =>
156-
props.toggleVote(col, {
157-
row: rowIndex,
158-
column: colIndex,
159-
})
160-
}
161-
/>
162-
)
163-
}
136+
if (col instanceof Rule) {
137+
return <Ballot.Rule key={col.id} ocrResult={col.rule} />
138+
}
164139

165-
if (col instanceof WriteInCandidate) {
166-
return (
167-
<Ballot.WriteIn
168-
key={col.id}
169-
accumulationNumber={col.accumulationNumber}
170-
hasVote={hasVote}
171-
voteOpacity={voteOpacity}
172-
voteType={voteType}
173-
toggleVote={() =>
174-
props.toggleVote(col, {
175-
row: rowIndex,
176-
column: colIndex,
177-
})
178-
}
179-
initialTextValue={col.name || vote?.candidate?.name}
180-
updateName={(name: string) => col.setName(name)}
181-
/>
182-
)
183-
}
140+
if (col instanceof Candidate) {
141+
return (
142+
<Ballot.Candidate
143+
key={col.id}
144+
img={col.img}
145+
name={col.name}
146+
hasVote={hasVote}
147+
voteType={voteType}
148+
voteOpacity={voteOpacity}
149+
accumulationNumber={col.accumulationNumber}
150+
isHighlighted={isHighlighted}
151+
isPartyHighlighted={
152+
isLegislativeBallot
153+
? col.receivesImpicitVote && isHighlighted
154+
: isHighlighted
155+
}
156+
toggleVote={() => {
157+
if (props.toggleVote == null) return
184158

185-
if (col instanceof EmptyCandidacy) {
186-
return <Ballot.EmptyCandidacy key={col.id} />
187-
}
159+
props.toggleVote(col, {
160+
row: rowIndex,
161+
column: colIndex,
162+
})
163+
}}
164+
/>
165+
)
166+
}
188167

168+
if (col instanceof WriteInCandidate) {
189169
return (
190-
<Ballot.SectionHeader
170+
<Ballot.WriteIn
191171
key={col.id}
192-
ocrResult={col.info}
193-
slug={col.slug}
172+
accumulationNumber={col.accumulationNumber}
173+
hasVote={hasVote}
174+
voteOpacity={voteOpacity}
175+
voteType={voteType}
176+
toggleVote={() => {
177+
if (props.toggleVote == null) return
178+
179+
props.toggleVote(col, {
180+
row: rowIndex,
181+
column: colIndex,
182+
})
183+
}}
184+
initialTextValue={col.name || vote?.candidate?.name}
185+
updateName={(name: string) => col.setName(name)}
194186
/>
195187
)
196188
}
197-
)}
189+
190+
if (col instanceof EmptyCandidacy) {
191+
return <Ballot.EmptyCandidacy key={col.id} />
192+
}
193+
194+
return (
195+
<Ballot.SectionHeader
196+
key={col.id}
197+
ocrResult={col.info}
198+
slug={col.slug}
199+
/>
200+
)
201+
})}
198202
</div>
199203
)
200204
}

0 commit comments

Comments
 (0)