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

Commit

Permalink
feat(breadcrumb): display the breadcrumb in the appointment components
Browse files Browse the repository at this point in the history
fix #1770
  • Loading branch information
oliv37 committed Feb 12, 2020
1 parent a4c1cfb commit a6eaf2a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/scheduling/appointments/Appointments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useSelector, useDispatch } from 'react-redux'
import { RootState } from 'store'
import { useHistory } from 'react-router'
import PatientRepository from 'clients/db/PatientRepository'
import useSetBreadcrumbs from 'breadcrumbs/useSetBreadcrumbs'
import { fetchAppointments } from './appointments-slice'

interface Event {
Expand All @@ -16,10 +17,13 @@ interface Event {
allDay: boolean
}

const breadcrumbs = [{ i18nKey: 'scheduling.appointments.label', location: '/patients' }]

const Appointments = () => {
const { t } = useTranslation()
const history = useHistory()
useTitle(t('scheduling.appointments.label'))
useSetBreadcrumbs(breadcrumbs)
const dispatch = useDispatch()
const { appointments } = useSelector((state: RootState) => state.appointments)
const [events, setEvents] = useState<Event[]>([])
Expand Down
8 changes: 7 additions & 1 deletion src/scheduling/appointments/new/NewAppointment.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
import React, { useState } from 'react'
import useTitle from 'page-header/useTitle'
import { useTranslation } from 'react-i18next'

import roundToNearestMinutes from 'date-fns/roundToNearestMinutes'
import { useHistory } from 'react-router'
import { useDispatch } from 'react-redux'
import Appointment from 'model/Appointment'
import addMinutes from 'date-fns/addMinutes'
import { isBefore } from 'date-fns'
import { Button, Alert } from '@hospitalrun/components'
import useSetBreadcrumbs from '../../../breadcrumbs/useSetBreadcrumbs'
import { createAppointment } from '../appointments-slice'
import AppointmentDetailForm from '../AppointmentDetailForm'

const breadcrumbs = [
{ i18nKey: 'scheduling.appointments.label', location: '/appointments' },
{ i18nKey: 'scheduling.appointments.new', location: '/appointments/new' },
]

const NewAppointment = () => {
const { t } = useTranslation()
const history = useHistory()
const dispatch = useDispatch()
useTitle(t('scheduling.appointments.new'))
useSetBreadcrumbs(breadcrumbs)
const startDateTime = roundToNearestMinutes(new Date(), { nearestTo: 15 })
const endDateTime = addMinutes(startDateTime, 60)

Expand Down
21 changes: 20 additions & 1 deletion src/scheduling/appointments/view/ViewAppointment.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
import React, { useEffect } from 'react'
import React, { useEffect, useMemo } from 'react'
import useTitle from 'page-header/useTitle'
import { useSelector, useDispatch } from 'react-redux'
import { RootState } from 'store'
import { useParams } from 'react-router'
import { Spinner } from '@hospitalrun/components'
import { useTranslation } from 'react-i18next'
import Appointment from 'model/Appointment'
import { fetchAppointment } from '../appointment-slice'
import AppointmentDetailForm from '../AppointmentDetailForm'
import useSetBreadcrumbs from '../../../breadcrumbs/useSetBreadcrumbs'

function getAppointmentLabel(appointment: Appointment) {
const { id, startDateTime, endDateTime } = appointment

return startDateTime && endDateTime
? `${new Date(startDateTime).toLocaleString()} - ${new Date(endDateTime).toLocaleString()}`
: id
}

const ViewAppointment = () => {
const { t } = useTranslation()
Expand All @@ -15,6 +25,15 @@ const ViewAppointment = () => {
const { id } = useParams()
const { appointment, patient, isLoading } = useSelector((state: RootState) => state.appointment)

const breadcrumbs = useMemo(
() => [
{ i18nKey: 'scheduling.appointments.label', location: '/appointments' },
{ text: getAppointmentLabel(appointment), location: `/patients/${appointment.id}` },
],
[appointment],
)
useSetBreadcrumbs(breadcrumbs)

useEffect(() => {
if (id) {
dispatch(fetchAppointment(id))
Expand Down

0 comments on commit a6eaf2a

Please sign in to comment.