Skip to content

Commit 5658399

Browse files
author
Chris Medykiewicz
committed
US-adding insurers, services and programs
1 parent 1ae1d16 commit 5658399

File tree

4 files changed

+25
-13
lines changed

4 files changed

+25
-13
lines changed

frontend/src/api/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
createVisits,
1616
patchVisit,
1717
} from "./visitEndpoints"
18+
import { getInsurers } from "./insurersEndpoints"
1819

1920
const create = () => {
2021
const api = apisauce.create({
@@ -44,6 +45,7 @@ const create = () => {
4445
updateVisits: updateVisits(api),
4546
createVisits: createVisits(api),
4647
patchVisit: patchVisit(api),
48+
getInsurers: getInsurers(api),
4749
}
4850
}
4951

frontend/src/api/insurersEndpoints.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const getInsurers = api => async () => await api.get("insurers/")

frontend/src/components/ParticipantInfo.js

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ const ParticipantInfo = observer(() => {
9999
let participantIndex = data.findIndex(
100100
val => val.pp_id === currentParticipant.pp_id
101101
)
102+
participantStore.getInsurers()
102103
// useEffect is a hook that gets called after every render/re-render. Empty array second argument prevents it from running again.
103104
useEffect(() => {
104105
if (participantIndex > -1) {
@@ -122,7 +123,7 @@ const ParticipantInfo = observer(() => {
122123
note: data[participantIndex].note,
123124
})
124125
}
125-
}, [])
126+
}, [data, participantIndex])
126127

127128
const createStartDate = () => {
128129
return format(new Date(), "yyyy-MM-dd")
@@ -400,18 +401,9 @@ const ParticipantInfo = observer(() => {
400401
id: "demo-controlled-open-select",
401402
}}
402403
>
403-
<MenuItem value="">
404-
<em>None</em>
405-
</MenuItem>
406-
<MenuItem value={"Insurance Plan 1"}>
407-
Insurance Plan 1
408-
</MenuItem>
409-
<MenuItem value={"Insurance Plan 2"}>
410-
Insurance Plan 2
411-
</MenuItem>
412-
<MenuItem value={"Insurance Plan 3"}>
413-
Insurance Plan 3
414-
</MenuItem>
404+
{participantStore.insurers.map((insurer, index) => (
405+
<MenuItem key={index}>{insurer.name}</MenuItem>
406+
))}
415407
</Select>
416408
</FormControl>
417409
</Grid>

frontend/src/stores/ParticipantStore.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ export class ParticipantStore {
1010
// Store Params
1111
participants = []
1212
participant = {}
13+
programs = {}
14+
insurers = {}
1315
params = {}
1416

1517
// Setters
@@ -28,6 +30,9 @@ export class ParticipantStore {
2830
setParticipant = data => {
2931
this.participant = data
3032
}
33+
setInsurers = data => {
34+
this.insurers = data
35+
}
3136

3237
// Getters
3338
getParticipantsList = () => {
@@ -39,6 +44,9 @@ export class ParticipantStore {
3944
getParticipant = () => {
4045
return toJS(this.participant)
4146
}
47+
getInsuranceList = () => {
48+
return toJS(this.insurers)
49+
}
4250

4351
// API Calls
4452
getParticipants = flow(function*() {
@@ -60,6 +68,15 @@ export class ParticipantStore {
6068
}
6169
})
6270

71+
getInsurers = flow(function*() {
72+
const { ok, data } = yield api.getInsurers()
73+
if (ok) {
74+
this.setInsurers(data)
75+
} else {
76+
// TODO: Handle errors
77+
}
78+
})
79+
6380
updateParticipant = flow(function*() {
6481
const { ok, data } = yield api.updateParticipant(
6582
toJS(this.participant.id),

0 commit comments

Comments
 (0)