Skip to content

Commit a4d4b3f

Browse files
authored
Merge pull request #260 from CodeForPhilly/US257-load-error-on-edit-participant-from-queue
US257: Load error on edit participant from queue
2 parents b74c1ea + 9ab7ae4 commit a4d4b3f

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

frontend/src/api/participantEndpoints.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const removeEmptyParams = params => {
1212
export const getParticipants = api => async params => {
1313
const queryParams = queryString.stringify(removeEmptyParams(params))
1414
return await api.get(
15-
queryParams ? `participants?${queryParams}` : "participants"
15+
queryParams ? `participants/?${queryParams}` : "participants/"
1616
)
1717
}
1818

frontend/src/components/ParticipantInfo.js

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -92,28 +92,14 @@ const ParticipantInfo = observer(() => {
9292
const programList = toJS(participantStore.programs)
9393
const serviceList = toJS(participantStore.services)
9494

95-
// useEffect is a hook that gets called after every render/re-render. Empty array second argument prevents it from running again.
9695
useEffect(() => {
97-
;(async () => {
98-
// kick off api calls for insurance list from Mobx
99-
await participantStore.getInsurers()
100-
// kick off api calls for program list from Mobx
101-
await participantStore.getPrograms()
102-
})()
103-
if (
104-
existingParticipant.id &&
105-
existingVisit.id &&
106-
existingVisit.program &&
107-
existingVisit.service
108-
) {
109-
// preload chosen services based on visit programs
110-
participantStore.setServiceList(
111-
programList.find(program => program.id === existingVisit.program)
112-
.services
113-
)
114-
}
96+
// kick off api calls for insurance list from Mobx
97+
participantStore.getInsurers()
98+
// kick off api calls for program list from Mobx
99+
participantStore.getPrograms()
115100
// eslint-disable-next-line react-hooks/exhaustive-deps
116101
}, [])
102+
117103
// set store stuff here and update Mobx on submit
118104
const handleSubmit = e => {
119105
e.preventDefault()
@@ -137,9 +123,10 @@ const ParticipantInfo = observer(() => {
137123
}
138124
// set service listings based on chosen program
139125
const findAndSaveServiceListings = e => {
140-
participantStore.setServiceList(
141-
programList.find(program => program.id === e.target.value).services
126+
const serviceListing = programList.find(
127+
program => program.id === e.target.value
142128
)
129+
participantStore.setServiceList(serviceListing.services)
143130
}
144131

145132
const classes = useStyles()

frontend/src/stores/ParticipantStore.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,19 @@ export class ParticipantStore {
172172
const { ok, data } = yield api.getPrograms()
173173
if (ok && data) {
174174
this.setPrograms(data)
175+
if (
176+
this.participant.id &&
177+
this.visit.id &&
178+
this.visit.program &&
179+
this.visit.service &&
180+
this.programs.length > 0
181+
) {
182+
// preload chosen services based on visit programs
183+
const preloadedServices = this.programs.find(
184+
program => program.id === this.visit.program
185+
)
186+
this.setServiceList(preloadedServices.services)
187+
}
175188
}
176189
} catch (error) {
177190
throw "ParticipantStore: getPrograms() Failed => " + error

0 commit comments

Comments
 (0)