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

Commit

Permalink
feat(patients): addRealtedPerson function
Browse files Browse the repository at this point in the history
  • Loading branch information
oizuldan committed Mar 4, 2020
1 parent c2c491d commit bd22057
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
32 changes: 19 additions & 13 deletions src/patients/patient-slice.ts
Expand Up @@ -71,11 +71,7 @@ export const createPatient = (patient: Patient, history: any): AppThunk => async
)
}

export const updatePatient = (
patient: Patient,
history: any,
relatedPerson?: boolean,
): AppThunk => async (dispatch) => {
export const updatePatient = (patient: Patient, history: any): AppThunk => async (dispatch) => {
dispatch(updatePatientStart())
const updatedPatient = await PatientRepository.saveOrUpdate(patient)
dispatch(updatePatientSuccess(updatedPatient))
Expand All @@ -85,14 +81,24 @@ export const updatePatient = (
il8n.t('Success!'),
`${il8n.t('patients.successfullyUpdated')} ${patient.fullName}`,
)
if (relatedPerson) {
Toast(
'success',
il8n.t('Success!'),
`${il8n.t('patients.successfullyAddedRelatedPerson')}`,
'top-left',
)
}
}

export const addRelatedPerson = (patient: Patient, history: any): AppThunk => async (dispatch) => {
dispatch(updatePatientStart())
const updatedPatient = await PatientRepository.saveOrUpdate(patient)
dispatch(updatePatientSuccess(updatedPatient))
history.push(`/patients/${updatedPatient.id}`)
Toast(
'success',
il8n.t('Success!'),
`${il8n.t('patients.successfullyUpdated')} ${patient.fullName}`,
)
Toast(
'success',
il8n.t('Success!'),
`${il8n.t('patients.successfullyAddedRelatedPerson')}`,
'top-left',
)
}

export default patientSlice.reducer
4 changes: 2 additions & 2 deletions src/patients/related-persons/RelatedPersonTab.tsx
Expand Up @@ -5,7 +5,7 @@ import RelatedPerson from 'model/RelatedPerson'
import { useTranslation } from 'react-i18next'
import { useHistory } from 'react-router'
import Patient from 'model/Patient'
import { updatePatient } from 'patients/patient-slice'
import { addRelatedPerson } from 'patients/patient-slice'
import { useDispatch, useSelector } from 'react-redux'
import { RootState } from 'store'
import Permissions from 'model/Permissions'
Expand Down Expand Up @@ -80,7 +80,7 @@ const RelatedPersonTab = (props: Props) => {
relatedPersons: newRelatedPersons,
}

dispatch(updatePatient(patientToUpdate, history, true))
dispatch(addRelatedPerson(patientToUpdate, history))
closeNewRelatedPersonModal()
}

Expand Down

0 comments on commit bd22057

Please sign in to comment.