Skip to content

Commit

Permalink
Insurer field bug (#483)
Browse files Browse the repository at this point in the history
* Validation works, but backend is barfing a 400 error

* insurer field only goes through if set to notRequired. Validates properly when an insurer is present but does not validate if no is selected. Because we're setting the value in the frontend to empty string and then converting to null on the backend I think this is ok.
  • Loading branch information
JackRyan1989 authored Jan 18, 2021
1 parent 173a9b8 commit 0ea1eb3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
8 changes: 7 additions & 1 deletion frontend/src/stores/ParticipantStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ export class ParticipantStore {
case "pp_id":
this.setPPId(value)
break
case "insurer":
this.setInsurer(value)
break
default:
this.participant[name] = value
}
Expand All @@ -131,6 +134,10 @@ export class ParticipantStore {
this.setServiceList(serviceListing.services)
}

@action setInsurer = data => {
this.participant.insurer = data.toString()
}

@action handleVisitChange = ({ name, value }) => {
switch (name) {
case "program":
Expand Down Expand Up @@ -353,7 +360,6 @@ export class ParticipantStore {
// called on => ParticipantInfo.js
// only update basic facts about the participant
updateParticipant = flow(function*() {
this.rootStore.UtilityStore.setLoadingState(true)
try {
const { ok, data, status } = yield api.updateParticipant(
toJS(this.participant.id),
Expand Down
14 changes: 8 additions & 6 deletions frontend/src/validation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,19 @@ const participantSchema = Yup.object().shape({
.notRequired()
.max(100),
is_insured: Yup.boolean().required(),
insurer: Yup.string().when("is_insured", {
is: false,
then: Yup.string().notRequired(),
otherwise: Yup.number().required(),
}),
insurer: Yup.string()
.notRequired()
.when("is_insured", {
is: false,
then: Yup.string().matches(/^\d+$/, { excludeEmptyString: true }),
otherwise: Yup.string().matches(/^\d+$/),
}),
})

const validateForm = (data, inputSchema) => {
let errors = []
let schema
if (inputSchema === "VISIT_SCHEMA") {
if (inputSchema === VISIT_SCHEMA) {
schema = visitSchema
} else {
schema = participantSchema
Expand Down

0 comments on commit 0ea1eb3

Please sign in to comment.