From bd22057c5b599005da20ba3cc757178ac3a1bb1d Mon Sep 17 00:00:00 2001 From: aisultankassenov Date: Wed, 4 Mar 2020 12:44:09 +0600 Subject: [PATCH] feat(patients): addRealtedPerson function --- src/patients/patient-slice.ts | 32 +++++++++++-------- .../related-persons/RelatedPersonTab.tsx | 4 +-- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/patients/patient-slice.ts b/src/patients/patient-slice.ts index 91fd375202..de5df4ad26 100644 --- a/src/patients/patient-slice.ts +++ b/src/patients/patient-slice.ts @@ -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)) @@ -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 diff --git a/src/patients/related-persons/RelatedPersonTab.tsx b/src/patients/related-persons/RelatedPersonTab.tsx index ce078f424b..930165f6b5 100644 --- a/src/patients/related-persons/RelatedPersonTab.tsx +++ b/src/patients/related-persons/RelatedPersonTab.tsx @@ -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' @@ -80,7 +80,7 @@ const RelatedPersonTab = (props: Props) => { relatedPersons: newRelatedPersons, } - dispatch(updatePatient(patientToUpdate, history, true)) + dispatch(addRelatedPerson(patientToUpdate, history)) closeNewRelatedPersonModal() }