Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feat) O3-3836: Added a 'Add bed' button on the summary page of each location. #1433

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ interface NewBedFormProps {
mutate: () => void;
onModalChange: (showModal: boolean) => void;
showModal: boolean;
defaultLocation?: { display: string; uuid: string };
}

const NewBedForm: React.FC<NewBedFormProps> = ({ showModal, onModalChange, mutate }) => {
const NewBedForm: React.FC<NewBedFormProps> = ({ showModal, onModalChange, mutate, defaultLocation }) => {
const { t } = useTranslation();
const { admissionLocations } = useLocationsWithAdmissionTag();
const { bedTypes } = useBedType();
Expand All @@ -28,10 +29,7 @@ const NewBedForm: React.FC<NewBedFormProps> = ({ showModal, onModalChange, mutat
column: 0,
description: '',
id: 0,
location: {
display: '',
uuid: '',
},
location: defaultLocation || { display: '', uuid: '' },
row: 0,
status: null,
uuid: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const useLocationsWithAdmissionTag = () => {
export const useBedsForLocation = (locationUuid: string) => {
const apiUrl = `${restBaseUrl}/bed?locationUuid=${locationUuid}&v=full`;

const { data, isLoading, error } = useSWR<{ data: { results: Array<Bed> } }, Error>(
const { data, isLoading, error, mutate, isValidating } = useSWR<{ data: { results: Array<Bed> } }, Error>(
locationUuid ? apiUrl : null,
openmrsFetch,
);
Expand All @@ -59,8 +59,10 @@ export const useBedsForLocation = (locationUuid: string) => {
bedsData: mappedBedData,
errorLoadingBeds: error,
isLoadingBeds: isLoading,
mutate,
isValidating,
}),
[mappedBedData, isLoading, error],
[mappedBedData, isLoading, error, mutate, isValidating],
);

return results;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,25 @@ import {
TableBody,
TableCell,
Tag,
InlineLoading,
} from '@carbon/react';
import { ArrowLeft } from '@carbon/react/icons';
import { ArrowLeft, Add } from '@carbon/react/icons';
import { navigate, usePagination } from '@openmrs/esm-framework';
import { useBedsForLocation, useLocationName } from '../summary/summary.resource';
import { useBedsForLocation, useLocationName, useBedsGroupedByLocation } from '../summary/summary.resource';
UNCANNY69 marked this conversation as resolved.
Show resolved Hide resolved
import NewBedForm from '../bed-administration/new-bed-form.component';
import Header from '../header/header.component';
import styles from './ward-with-beds.scss';

type RouteParams = { location: string };

const WardWithBeds: React.FC = () => {
const { t } = useTranslation();
const { location } = useParams<RouteParams>();
const { bedsData, isLoadingBeds } = useBedsForLocation(location);
const { bedsData, isLoadingBeds, mutate, isValidating } = useBedsForLocation(location);
const { name } = useLocationName(location);

const [pageSize, setPageSize] = useState(10);
const [showAddBedModal, setShowAddBedModal] = useState(false);
const { results: paginatedData, goTo, currentPage } = usePagination(bedsData, pageSize);

if (isLoadingBeds) {
Expand Down Expand Up @@ -114,6 +118,25 @@ const WardWithBeds: React.FC = () => {
}>
<span>Return to summary</span>
</Button>
<span className={styles.backgroundDataFetchingIndicator}>
UNCANNY69 marked this conversation as resolved.
Show resolved Hide resolved
<span>{isValidating ? <InlineLoading /> : null}</span>
NethmiRodrigo marked this conversation as resolved.
Show resolved Hide resolved
</span>
<Button
kind="ghost"
renderIcon={(props) => <Add size={16} {...props} />}
onClick={() => setShowAddBedModal(true)}>
{t('addBed', 'Add bed')}
UNCANNY69 marked this conversation as resolved.
Show resolved Hide resolved
</Button>
</div>
<div className={styles.widgetCard}>
UNCANNY69 marked this conversation as resolved.
Show resolved Hide resolved
{showAddBedModal ? (
<NewBedForm
mutate={mutate}
onModalChange={setShowAddBedModal}
showModal={showAddBedModal}
defaultLocation={{ display: name, uuid: location }}
/>
) : null}
</div>
<div className={styles.container}>
<DataTable rows={tableRows} headers={tableHeaders} useZebraStyles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
.backButton {
align-items: center;
display: flex;
justify-content: flex-start;
justify-content: space-between;
margin-left: layout.$spacing-05;

button {
Expand Down
Loading