diff --git a/src/Components/Facility/LocationManagement.tsx b/src/Components/Facility/LocationManagement.tsx index 83bf335aff2..95a95730a27 100644 --- a/src/Components/Facility/LocationManagement.tsx +++ b/src/Components/Facility/LocationManagement.tsx @@ -3,6 +3,7 @@ import ButtonV2, { Cancel } from "../Common/components/ButtonV2"; import AuthorizeFor, { NonReadOnlyUsers } from "../../Utils/AuthorizeFor"; import CareIcon from "../../CAREUI/icons/CareIcon"; import Page from "../Common/components/Page"; +import { LOCATION_BED_TYPES } from "../../Common/constants"; import routes from "../../Redux/api"; import PaginatedList from "../../CAREUI/misc/PaginatedList"; import { LocationModel } from "./models"; @@ -13,7 +14,7 @@ import ConfirmDialog from "../Common/ConfirmDialog"; import DialogModal from "../Common/Dialog"; import Uptime from "../Common/Uptime"; import useAuthUser from "../../Common/hooks/useAuthUser"; - +import useQuery from "../../Utils/request/useQuery"; const Loading = lazy(() => import("../Common/Loading")); interface Props { @@ -224,97 +225,130 @@ const Location = ({ disabled, setShowDeletePopup, facilityId, -}: LocationProps) => ( -
-
-
-
-

- {name} -

-
-

- {location_type} +}: LocationProps) => { + const { loading, data } = useQuery(routes.listFacilityBeds, { + query: { + facility: facilityId, + location: id, + }, + }); + let bedCountsByType: Record = {}; + + if (!loading && data?.results?.length) { + bedCountsByType = data.results.reduce( + (acc: Record, bed: any) => { + acc[bed.bed_type] = (acc[bed.bed_type] ?? 0) + 1; + return acc; + }, + {}, + ); + } + + return ( +

+
+
+
+

+ {name}

+
+

+ {location_type} +

+
-
-

- {description || "-"} -

-

- Middleware Address: -

-

- {middleware_address || "-"} -

- - Middleware Uptime -

- } - centerInfoPanel - /> -
- - - - Manage Beds - -
-
- - - Edit - -
-
- - setShowDeletePopup({ open: true, name: name ?? "", id: id ?? "" }) - } + {description || "-"} +

+

+ Middleware Address: +

+

- - Delete - + {middleware_address || "-"} +

+ + Middleware Uptime +

+ } + centerInfoPanel + /> +
+

Beds

+
+ {LOCATION_BED_TYPES.map((type) => ( +
+

{type.name}

+

{bedCountsByType[type.id] || 0} beds

+
+ ))} +
+ + + Manage Beds + +
+
+ + + Edit + +
+
+ + setShowDeletePopup({ open: true, name: name ?? "", id: id ?? "" }) + } + > + + Delete + +
-
-
- - +
+ + +
-
-); + ); +};