Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
fix(allergies): fixes allergies tab not refreshing data after allergy…
Browse files Browse the repository at this point in the history
… has been added
  • Loading branch information
jackcmeyer committed Aug 20, 2020
1 parent bc9709a commit 0e29639
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/__tests__/patients/hooks/useAddAllergy.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ describe('use add allergy', () => {
expect(PatientRepository.find).toHaveBeenCalledTimes(1)
expect(PatientRepository.saveOrUpdate).toHaveBeenCalledTimes(1)
expect(PatientRepository.saveOrUpdate).toHaveBeenCalledWith(expectedPatient)
expect(result).toEqual(expectedAllergy)
expect(result).toEqual([expectedAllergy])
})
})
8 changes: 4 additions & 4 deletions src/patients/hooks/useAddAllergy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface AddAllergyRequest {
allergy: Allergy
}

async function addAllergy(request: AddAllergyRequest): Promise<Allergy> {
async function addAllergy(request: AddAllergyRequest): Promise<Allergy[]> {
const error = validateAllergy(request.allergy)

if (isEmpty(error)) {
Expand All @@ -28,16 +28,16 @@ async function addAllergy(request: AddAllergyRequest): Promise<Allergy> {
allergies,
})

return newAllergy
return allergies
}

throw error
}

export default function useAddAllergy() {
return useMutation(addAllergy, {
onSuccess: async (_, variables) => {
await queryCache.invalidateQueries(['allergies', variables.patientId])
onSuccess: async (data, variables) => {
await queryCache.setQueryData(['allergies', variables.patientId], data)
},
throwOnError: true,
})
Expand Down

0 comments on commit 0e29639

Please sign in to comment.