Skip to content

Commit 1ae1d16

Browse files
authored
Merge pull request #198 from CodeForPhilly/US-participant-info-refactoring
US bug fix for participant info page
2 parents 2aecf9d + e2246ba commit 1ae1d16

File tree

1 file changed

+93
-22
lines changed

1 file changed

+93
-22
lines changed

frontend/src/components/ParticipantInfo.js

Lines changed: 93 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,24 @@ const useStyles = makeStyles(theme => ({
7373
const ParticipantInfo = observer(() => {
7474
const rootStore = useContext(rootStoreContext)
7575
const participantStore = rootStore.ParticipantStore
76-
const [participant, setParticipant] = React.useState({})
76+
const [participant, setParticipant] = React.useState({
77+
id: 0,
78+
firstName: "",
79+
lastName: "",
80+
lastFourSSN: 0,
81+
dateOfBirth: "",
82+
startDate: "",
83+
ppId: "",
84+
race: "",
85+
gender: "",
86+
hasInsurance: false,
87+
insuranceType: "",
88+
insurer: "",
89+
program: "",
90+
service: "",
91+
priority: "",
92+
note: "",
93+
})
7794
const [open, setOpen] = React.useState("")
7895
const history = useHistory()
7996

@@ -110,12 +127,6 @@ const ParticipantInfo = observer(() => {
110127
const createStartDate = () => {
111128
return format(new Date(), "yyyy-MM-dd")
112129
}
113-
const changeParticipant = (e, args) => {
114-
setParticipant(prevState => ({
115-
...prevState,
116-
[args]: e.target.value,
117-
}))
118-
}
119130
// set store stuff here and update Mobx on submit
120131
function handleClose() {
121132
setOpen(false)
@@ -125,7 +136,6 @@ const ParticipantInfo = observer(() => {
125136
}
126137
function handleSubmit(e) {
127138
e.preventDefault()
128-
// match participant ID
129139
participantStore.setParticipant({
130140
id: participantIndex > -1 ? participant.id : null,
131141
first_name: participant.firstName,
@@ -178,7 +188,12 @@ const ParticipantInfo = observer(() => {
178188
id="user_first-name"
179189
name="user_first-name"
180190
value={participant.firstName}
181-
onChange={e => changeParticipant(e, "firstName")}
191+
onChange={e =>
192+
setParticipant({
193+
...participant,
194+
firstName: e.target.value,
195+
})
196+
}
182197
required
183198
/>
184199
</FormControl>
@@ -190,7 +205,12 @@ const ParticipantInfo = observer(() => {
190205
id="user_last-name"
191206
name="user_last-name"
192207
value={participant.lastName}
193-
onChange={e => changeParticipant(e, "lastName")}
208+
onChange={e =>
209+
setParticipant({
210+
...participant,
211+
lastName: e.target.value,
212+
})
213+
}
194214
required
195215
/>
196216
</FormControl>
@@ -206,7 +226,12 @@ const ParticipantInfo = observer(() => {
206226
id="user_birth-date"
207227
name="user_birth-date"
208228
value={participant.dateOfBirth}
209-
onChange={e => changeParticipant(e, "dateOfBirth")}
229+
onChange={e =>
230+
setParticipant({
231+
...participant,
232+
dateOfBirth: e.target.value,
233+
})
234+
}
210235
required
211236
style={{ marginTop: 40 }}
212237
type="date"
@@ -224,7 +249,13 @@ const ParticipantInfo = observer(() => {
224249
id="uuid"
225250
name="uuid"
226251
value={participant.ppId}
227-
onChange={e => changeParticipant(e, "ppId")}
252+
onChange={e =>
253+
setParticipant({
254+
...participant,
255+
ppId: e.target.value,
256+
lastFourSSN: +e.target.value.substr(2),
257+
})
258+
}
228259
required
229260
/>
230261
</FormControl>
@@ -246,7 +277,12 @@ const ParticipantInfo = observer(() => {
246277
onOpen={handleOpen.race}
247278
required
248279
value={participant.race}
249-
onChange={e => changeParticipant(e, "race")}
280+
onChange={e =>
281+
setParticipant({
282+
...participant,
283+
race: e.target.value,
284+
})
285+
}
250286
inputProps={{
251287
name: "race",
252288
id: "demo-controlled-open-select",
@@ -282,7 +318,12 @@ const ParticipantInfo = observer(() => {
282318
onOpen={handleOpen.gender}
283319
required
284320
value={participant.gender}
285-
onChange={e => changeParticipant(e, "gender")}
321+
onChange={e =>
322+
setParticipant({
323+
...participant,
324+
gender: e.target.value,
325+
})
326+
}
286327
inputProps={{
287328
name: "gender",
288329
id: "demo-controlled-open-select",
@@ -316,16 +357,21 @@ const ParticipantInfo = observer(() => {
316357
name="hasInsurance"
317358
className={classes.group}
318359
value={participant.hasInsurance}
319-
onChange={e => changeParticipant(e, "hasInsurance")}
360+
onChange={e =>
361+
setParticipant({
362+
...participant,
363+
hasInsurance: e.target.value,
364+
})
365+
}
320366
style={{ display: "inline" }}
321367
>
322368
<FormControlLabel
323-
value="yes"
369+
value={true}
324370
control={<Radio />}
325371
label="Yes"
326372
/>
327373
<FormControlLabel
328-
value="no"
374+
value={false}
329375
control={<Radio />}
330376
label="No"
331377
/>
@@ -343,7 +389,12 @@ const ParticipantInfo = observer(() => {
343389
onClose={handleClose.insuranceType}
344390
onOpen={handleOpen.insuranceType}
345391
value={participant.insuranceType}
346-
onChange={e => changeParticipant(e, "insuranceType")}
392+
onChange={e =>
393+
setParticipant({
394+
...participant,
395+
insuranceType: e.target.value,
396+
})
397+
}
347398
inputProps={{
348399
name: "insuranceType",
349400
id: "demo-controlled-open-select",
@@ -393,7 +444,12 @@ const ParticipantInfo = observer(() => {
393444
onOpen={handleOpen.program}
394445
required
395446
value={participant.program}
396-
onChange={e => changeParticipant(e, "program")}
447+
onChange={e =>
448+
setParticipant({
449+
...participant,
450+
program: e.target.value,
451+
})
452+
}
397453
inputProps={{
398454
name: "program",
399455
id: "demo-controlled-open-select",
@@ -416,7 +472,12 @@ const ParticipantInfo = observer(() => {
416472
onOpen={handleOpen.service}
417473
required
418474
value={participant.service}
419-
onChange={e => changeParticipant(e, "service")}
475+
onChange={e =>
476+
setParticipant({
477+
...participant,
478+
service: e.target.value,
479+
})
480+
}
420481
inputProps={{
421482
name: "service",
422483
id: "demo-controlled-open-select",
@@ -439,7 +500,12 @@ const ParticipantInfo = observer(() => {
439500
onClose={handleClose.priorityLevel}
440501
onOpen={handleOpen.priorityLevel}
441502
value={participant.priority}
442-
onChange={e => changeParticipant(e, "priority")}
503+
onChange={e =>
504+
setParticipant({
505+
...participant,
506+
priority: e.target.value,
507+
})
508+
}
443509
inputProps={{
444510
name: "priorityLevel",
445511
id: "demo-controlled-open-select",
@@ -458,7 +524,12 @@ const ParticipantInfo = observer(() => {
458524
id="standard-full-width"
459525
style={{ margin: 8, marginTop: 40 }}
460526
placeholder="Add a note"
461-
onChange={e => changeParticipant(e, "note")}
527+
onChange={e =>
528+
setParticipant({
529+
...participant,
530+
note: e.target.value,
531+
})
532+
}
462533
value={participant.note}
463534
fullWidth
464535
margin="normal"

0 commit comments

Comments
 (0)