forked from HospitalRun/hospitalrun-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(appointmentslist): add an appointments tab to the patient view
add an appointments tab to the patient view which shows appointments list for corresponding patient. Uses same layout as patient list view and also implements fuzzy search HospitalRun#1769
- Loading branch information
Ignacio Gea
committed
Feb 13, 2020
1 parent
d5dacd6
commit 99f2b91
Showing
6 changed files
with
135 additions
and
4 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
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,75 @@ | ||
import React, { useEffect, useState } from 'react' | ||
import { useSelector, useDispatch } from 'react-redux' | ||
import { useHistory } from 'react-router' | ||
import { useTranslation } from 'react-i18next' | ||
import { TextInput, Button, List, ListItem, Container, Row } from '@hospitalrun/components' | ||
import { RootState } from '../../store' | ||
import { fetchPatientAppointments } from '../../scheduling/appointments/appointments-slice' | ||
|
||
interface Props { | ||
patientId: string | ||
} | ||
|
||
const AppointmentsList = (props: Props) => { | ||
const dispatch = useDispatch() | ||
const history = useHistory() | ||
const { t } = useTranslation() | ||
|
||
const patientId = props.patientId | ||
const { appointments } = useSelector((state: RootState) => state.appointments) | ||
const [searchText, setSearchText] = useState<string>('') | ||
|
||
useEffect(() => { | ||
dispatch(fetchPatientAppointments(patientId)) | ||
}, [dispatch, patientId]) | ||
|
||
const list = ( | ||
// inline style added to pick up on newlines for string literal | ||
<ul style={{whiteSpace: 'pre-line'}}> | ||
{appointments.map((a) => ( | ||
<ListItem action key={a.id} onClick={() => history.push(`/appointments/${a.id}`)}> | ||
{`${t('scheduling.appointment.location')}: ${a.location} | ||
${t('scheduling.appointment.reason')}: ${a.reason} | ||
${t('scheduling.appointment.type')}: ${a.type} | ||
${t('scheduling.appointment.startDate')}: ${new Date(a.startDateTime).toLocaleString()} | ||
${t('scheduling.appointment.endDate')}: ${new Date(a.endDateTime).toLocaleString()}`} | ||
</ListItem> | ||
))} | ||
</ul> | ||
) | ||
|
||
const onSearchBoxChange = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
setSearchText(event.target.value) | ||
} | ||
|
||
const onSearchFormSubmit = (event: React.FormEvent | React.MouseEvent) => { | ||
event.preventDefault() | ||
dispatch(fetchPatientAppointments(patientId, searchText)) | ||
} | ||
|
||
return ( | ||
<Container> | ||
<form className="form-inline" onSubmit={onSearchFormSubmit}> | ||
<div className="input-group" style={{ width: '100%' }}> | ||
<TextInput | ||
size="lg" | ||
value={searchText} | ||
placeholder={t('actions.search')} | ||
onChange={onSearchBoxChange} | ||
/> | ||
<div className="input-group-append"> | ||
<Button onClick={onSearchFormSubmit}>{t('actions.search')}</Button> | ||
</div> | ||
</div> | ||
</form> | ||
|
||
<Row> | ||
<List layout="flush" style={{ width: '100%', marginTop: '10px', marginLeft: '-25px' }}> | ||
{list} | ||
</List> | ||
</Row> | ||
</Container> | ||
) | ||
} | ||
|
||
export default AppointmentsList |
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