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

Commit

Permalink
feat(appointments): adds screen to view appointment
Browse files Browse the repository at this point in the history
  • Loading branch information
jackcmeyer committed Feb 4, 2020
1 parent a0be28b commit f31e852
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/HospitalRun.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useSelector } from 'react-redux'
import { Toaster } from '@hospitalrun/components'
import Appointments from 'scheduling/appointments/Appointments'
import NewAppointment from 'scheduling/appointments/new/NewAppointment'
import ViewAppointment from 'scheduling/appointments/view/ViewAppointment'
import Sidebar from './components/Sidebar'
import Permissions from './model/Permissions'
import Dashboard from './dashboard/Dashboard'
Expand Down Expand Up @@ -59,6 +60,12 @@ const HospitalRun = () => {
path="/appointments/new"
component={NewAppointment}
/>
<PrivateRoute
isAuthenticated={permissions.includes(Permissions.ReadAppointments)}
exact
path="/appointments/:id"
component={ViewAppointment}
/>
</Switch>
</div>
<Toaster autoClose={5000} hideProgressBar draggable />
Expand Down
38 changes: 38 additions & 0 deletions src/scheduling/appointments/appointment-slice.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { createSlice, PayloadAction } from '@reduxjs/toolkit'
import Appointment from 'model/Appointment'
import { AppThunk } from 'store'
import AppointmentRepository from 'clients/db/AppointmentsRepository'

interface AppointmentState {
appointment: Appointment
isLoading: boolean
}

const initialAppointmentState = {
appointment: {} as Appointment,
isLoading: false,
}

const appointmentSlice = createSlice({
name: 'appointment',
initialState: initialAppointmentState,
reducers: {
getAppointmentStart: (state: AppointmentState) => {
state.isLoading = true
},
getAppointmentSuccess: (state, { payload }: PayloadAction<Appointment>) => {
state.isLoading = false
state.appointment = payload
},
},
})

export const { getAppointmentStart, getAppointmentSuccess } = appointmentSlice.actions

export const fetchAppointment = (id: string): AppThunk => async (dispatch) => {
dispatch(getAppointmentStart())
const appointments = await AppointmentRepository.find(id)
dispatch(getAppointmentSuccess(appointments))
}

export default appointmentSlice.reducer
33 changes: 33 additions & 0 deletions src/scheduling/appointments/view/ViewAppointment.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React, { useEffect } from 'react'
import useTitle from 'page-header/useTitle'
import { useSelector, useDispatch } from 'react-redux'
import { RootState } from 'store'
import { fetchAppointment } from '../appointment-slice'
import { useParams } from 'react-router'
import AppointmentDetailForm from '../AppointmentDetailForm'
import { Spinner } from '@hospitalrun/components'

const ViewAppointment = () => {
useTitle('View Appointment')
const dispatch = useDispatch()
const { id } = useParams()
const { appointment, isLoading } = useSelector((state: RootState) => state.appointment)

useEffect(() => {
if (id) {
dispatch(fetchAppointment(id))
}
}, [dispatch])

if (!appointment.id || isLoading) {
return <Spinner type="BarLoader" loading />
}

return (
<div>
<AppointmentDetailForm appointment={appointment} onAppointmentChange={() => {}} />
</div>
)
}

export default ViewAppointment
2 changes: 2 additions & 0 deletions src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { configureStore, combineReducers, Action } from '@reduxjs/toolkit'
import ReduxThunk, { ThunkAction } from 'redux-thunk'
import patient from '../patients/patient-slice'
import patients from '../patients/patients-slice'
import appointment from '../scheduling/appointments/appointment-slice'
import appointments from '../scheduling/appointments/appointments-slice'
import title from '../page-header/title-slice'
import user from '../user/user-slice'
Expand All @@ -11,6 +12,7 @@ const reducer = combineReducers({
patients,
title,
user,
appointment,
appointments,
})

Expand Down

0 comments on commit f31e852

Please sign in to comment.