-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat(patients): add no patients exist #2235
Changes from 5 commits
9ada8f0
0b5701c
86ca0f9
a65f44c
09a9066
69e689b
3aff81e
fbd94b4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ import useTranslator from '../../shared/hooks/useTranslator' | |
import useUpdateEffect from '../../shared/hooks/useUpdateEffect' | ||
import { RootState } from '../../shared/store' | ||
import { searchPatients } from '../patients-slice' | ||
import AddNewPatient from '../view/AddNewPatient' | ||
|
||
const breadcrumbs = [{ i18nKey: 'patients.label', location: '/patients' }] | ||
|
||
|
@@ -22,7 +23,7 @@ const ViewPatients = () => { | |
useTitle(t('patients.label')) | ||
useAddBreadcrumbs(breadcrumbs, true) | ||
const dispatch = useDispatch() | ||
const { patients, isLoading } = useSelector((state: RootState) => state.patients) | ||
const { patients, isLoading, count } = useSelector((state: RootState) => state.patients) | ||
|
||
const setButtonToolBar = useButtonToolbarSetter() | ||
|
||
|
@@ -48,22 +49,23 @@ const ViewPatients = () => { | |
}, [dispatch, debouncedSearchText]) | ||
|
||
useEffect(() => { | ||
setButtonToolBar([ | ||
<Button | ||
key="newPatientButton" | ||
outlined | ||
color="success" | ||
icon="patient-add" | ||
onClick={() => history.push('/patients/new')} | ||
> | ||
{t('patients.newPatient')} | ||
</Button>, | ||
]) | ||
|
||
if (patients && patients.length > 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this This could be the default page of patients or a search result. When searching for patients and my search results return 0, I would not expect the new icon to appear. I think that we should implement a new function called Then here, we use that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i get it, what i don't get is why do we need to implement it seems like
but it seems that implementing a |
||
setButtonToolBar([ | ||
<Button | ||
key="newPatientButton" | ||
outlined | ||
color="success" | ||
icon="patient-add" | ||
onClick={() => history.push('/patients/new')} | ||
> | ||
{t('patients.newPatient')} | ||
</Button>, | ||
]) | ||
} | ||
return () => { | ||
setButtonToolBar([]) | ||
} | ||
}, [dispatch, setButtonToolBar, t, history]) | ||
}, [dispatch, setButtonToolBar, t, history, patients]) | ||
|
||
const loadingIndicator = <Spinner color="blue" loading size={[10, 25]} type="ScaleLoader" /> | ||
const table = ( | ||
|
@@ -91,6 +93,10 @@ const ViewPatients = () => { | |
setSearchText(event.target.value) | ||
} | ||
|
||
if (count === 0) { | ||
return <AddNewPatient /> | ||
} | ||
|
||
return ( | ||
<div> | ||
<Container> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Button, Icon, Typography } from '@hospitalrun/components' | ||
import React from 'react' | ||
import { useHistory } from 'react-router-dom' | ||
|
||
import useTranslator from '../../shared/hooks/useTranslator' | ||
|
||
const AddNewPatient = () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thoughts on |
||
const history = useHistory() | ||
const { t } = useTranslator() | ||
|
||
return ( | ||
<div style={{ display: 'flex', justifyContent: 'center' }}> | ||
<div style={{ display: 'flex', flexDirection: 'column' }}> | ||
<div style={{ display: 'flex', justifyContent: 'center' }}> | ||
<Icon icon="patients" outline={false} size="6x" /> | ||
</div> | ||
<div style={{ display: 'flex', justifyContent: 'center' }}> | ||
<div style={{ textAlign: 'center', width: '60%', margin: 16 }}> | ||
<Typography variant="h5">{t('patients.noPatients')}</Typography> | ||
</div> | ||
</div> | ||
<div style={{ display: 'flex', justifyContent: 'center' }}> | ||
<Button | ||
key="newPatientButton" | ||
outlined | ||
color="primary" | ||
icon="patient-add" | ||
onClick={() => history.push('/patients/new')} | ||
> | ||
{t('patients.newPatient')} | ||
</Button> | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default AddNewPatient |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is testing behavior inside the
AddNewPatient
component. I think instead, this test should test that theAddNewPatient
component gets rendered and then this current test should be moved to anAddNewPatient
test.