This repository has been archived by the owner on Jan 9, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(appointments): adds screen to view appointment
- Loading branch information
1 parent
a0be28b
commit f31e852
Showing
4 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters