Skip to content

Commit

Permalink
added error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
divija-zemoso committed Sep 30, 2022
1 parent 18f374c commit efb9940
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/patients/search/ViewPatients.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Button } from '@hospitalrun/components'
import React, { useEffect } from 'react'
import { useDispatch } from 'react-redux'
import { useHistory } from 'react-router'
import { useHistory } from 'react-router-dom'

import useAddBreadcrumbs from '../../page-header/breadcrumbs/useAddBreadcrumbs'
import { useButtonToolbarSetter } from '../../page-header/button-toolbar/ButtonBarProvider'
Expand Down
2 changes: 2 additions & 0 deletions src/patients/visits/FilterPatientModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@ const FilterPatientModal = ({ show, onCloseButtonClick, onFieldChange }: Props)
<Label text={t('scheduling.appointment.type')} title="type" />
<Select
id="type"
defaultSelected={appointmentTypes.filter(({ value }) => value === appointmentType)}
options={appointmentTypes}
onChange={(values) => setappointmentType(values[0])}
/>
</div>
<div className="form-group">
<Label text="Status" title="Status" />
<Select
defaultSelected={appointmentStatus.filter(({ value }) => value == patientStatus)}
id="status"
options={appointmentStatus}
onChange={(values) => setPatientStatus(values[0])}
Expand Down
2 changes: 1 addition & 1 deletion src/scheduling/appointments/AppointmentDetailForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const AppointmentDetailForm = (props: Props) => {
/>
<AsyncTypeahead
id="patientTypeahead"
disabled={!isEditable}
disabled={!isEditable || patient !== undefined}
defaultInputValue={patient ? String(patient) : ''}
placeholder={t('scheduling.appointment.patient')}
onChange={(p: any) => {
Expand Down
2 changes: 2 additions & 0 deletions src/scheduling/appointments/edit/EditAppointment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ const EditAppointment = () => {
console.log('updated the values successfully')
Toast('success', t('states.success'), t('scheduling.appointment.successfullyUpdated'))
history.push(`/appointments/${id}`)
} else {
Toast('error', t('states.error'), 'Could not edit appointment')
}
}

Expand Down
24 changes: 13 additions & 11 deletions src/scheduling/appointments/new/NewAppointment.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// import { Button, Spinner, Toast } from '@hospitalrun/components'
import { Button, Spinner, Toast } from '@hospitalrun/components'
import isEmpty from 'lodash/isEmpty'
// import isEmpty from 'lodash/isEmpty'
// import addMinutes from 'date-fns/addMinutes'
// import roundToNearestMinutes from 'date-fns/roundToNearestMinutes'
// import isEmpty from 'lodash/isEmpty'
Expand Down Expand Up @@ -71,7 +71,9 @@ const NewAppointment = () => {
let { id, status } = await createAppointment(newAppointment)
console.log('id: ' + id + ' ' + 'status: ' + status)
setAptId(id)
if (status === 'success') setSaved(true)
status === 'success'
? setSaved(true)
: Toast('error', t('states.error'), t('scheduling.appointment.errors.createAppointmentError'))
setError(validateNewAppointment(newAppointment))
}

Expand All @@ -82,16 +84,16 @@ const NewAppointment = () => {
useEffect(() => {
// if save click and no error proceed, else give error message.
if (saved) {
if (isEmpty(newAppointmentMutateError) && !isErrorNewAppointment) {
newAppointmentMutate(newAppointment).then((_result) => {
Toast('success', t('states.success'), t('scheduling.appointment.successfullyCreated'))
console.log(aptId)
history.push(`/appointments/${aptId}`)
})
} else if (!isEmpty(newAppointmentMutateError)) {
newAppointmentMutateError.message = 'scheduling.appointment.errors.createAppointmentError'
}
newAppointmentMutate(newAppointment).then((_result) => {
Toast('success', t('states.success'), t('scheduling.appointment.successfullyCreated'))
console.log(aptId)
history.push(`/appointments/${aptId}`)
})
}
// else {
// Toast('error', t('states.error'), t('scheduling.appointment.errors.createAppointmentError'))
// // newAppointmentMutateError.message = 'scheduling.appointment.errors.createAppointmentError'
// }
setSaved(false)
}, [
saved,
Expand Down
11 changes: 9 additions & 2 deletions src/scheduling/appointments/service/Appointments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const createAppointment = (appointment: Appointment) => {
participant: [
{
actor: {
reference: `Patient/140919926030337`,
reference: `Patient/${appointment.patientId}`,
},
},
{
Expand Down Expand Up @@ -125,6 +125,7 @@ export const createAppointment = (appointment: Appointment) => {
})
.catch((error) => {
console.log(error)
return { id: 404, status: 'error' }
})
}

Expand All @@ -142,7 +143,11 @@ export const updateAppointment = (appointment: Appointment) => {
participant: [
{
actor: {
reference: `Patient/${appointment?.participant[0].actor.reference.substring(8)}`,
reference: `Patient/${
appointment.patientId
? appointment.patientId
: appointment?.participant[0].actor.reference.substring(8)
}`,
},
},
{
Expand Down Expand Up @@ -211,6 +216,7 @@ export const updateAppointment = (appointment: Appointment) => {
})
.catch((error) => {
console.log(error)
return { id: 404, status: 'error' }
})
}

Expand All @@ -223,5 +229,6 @@ export const deleteAppointment = (id: number) => {
})
.catch((error) => {
console.log(error)
return 'error'
})
}
2 changes: 2 additions & 0 deletions src/scheduling/appointments/view/ViewAppointment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ const ViewAppointment = () => {
if (status === 'success') {
history.push('/appointments')
Toast('success', t('states.success'), t('scheduling.appointment.successfullyDeleted'))
} else {
Toast('error', t('states.error'), 'Could not delete appointment')
}

setShowDeleteConfirmation(false)
Expand Down

0 comments on commit efb9940

Please sign in to comment.