From 9187b41e66812b2d2ba561dd326934a0a58cff84 Mon Sep 17 00:00:00 2001 From: Shelly011s Date: Tue, 1 Oct 2024 03:12:37 +0530 Subject: [PATCH 1/2] Added temporary UI for location card --- .../Facility/LocationManagement.tsx | 212 +++++++++++------- 1 file changed, 125 insertions(+), 87 deletions(-) diff --git a/src/Components/Facility/LocationManagement.tsx b/src/Components/Facility/LocationManagement.tsx index abf4a056695..83124d3336a 100644 --- a/src/Components/Facility/LocationManagement.tsx +++ b/src/Components/Facility/LocationManagement.tsx @@ -13,16 +13,18 @@ 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 { facilityId: string; + // locationId: string; } interface LocationProps extends LocationModel { facilityId: string; disabled: boolean; + // locationId: string; setShowDeletePopup: (e: { open: boolean; name: string; id: string }) => void; } @@ -117,6 +119,7 @@ export default function LocationManagement({ facilityId }: Props) { ( -
-
-
-
-

- {name} -

-
-

- {location_type} + // locationId +}: LocationProps) => { + // const { loading, data, refetch } = useQuery(routes.listFacilityBeds, { + // query: { + // facility: facilityId, + // // location: locationId, + // // limit: resultsPerPage, + // // offset: (qParams.page ? qParams.page - 1 : 0) * resultsPerPage, + // }, + // }); + + 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

+
+
+

Isolation

+

8 beds

+
+
+

ICU

+

5 beds

+
+
+

Oxygen Support

+

8 beds

+
+
+

Regular

+

20 beds

+
+
+ + + Manage Beds + +
+
+ + + Edit + +
+
+ + setShowDeletePopup({ open: true, name: name ?? "", id: id ?? "" }) + } + > + + Delete + +
-
-
- - +
+ + +
-
-); + ); +}; From f695dff622f58896e8c5d1652d5e8d14eaf2b02c Mon Sep 17 00:00:00 2001 From: Shelly011s Date: Tue, 1 Oct 2024 04:34:45 +0530 Subject: [PATCH 2/2] Added query calls --- .../Facility/LocationManagement.tsx | 54 +++++++++---------- 1 file changed, 25 insertions(+), 29 deletions(-) diff --git a/src/Components/Facility/LocationManagement.tsx b/src/Components/Facility/LocationManagement.tsx index 83124d3336a..8aa299b9ca1 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,18 +14,16 @@ 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"; +import useQuery from "../../Utils/request/useQuery"; const Loading = lazy(() => import("../Common/Loading")); interface Props { facilityId: string; - // locationId: string; } interface LocationProps extends LocationModel { facilityId: string; disabled: boolean; - // locationId: string; setShowDeletePopup: (e: { open: boolean; name: string; id: string }) => void; } @@ -119,7 +118,6 @@ export default function LocationManagement({ facilityId }: Props) { { - // const { loading, data, refetch } = useQuery(routes.listFacilityBeds, { - // query: { - // facility: facilityId, - // // location: locationId, - // // limit: resultsPerPage, - // // offset: (qParams.page ? qParams.page - 1 : 0) * resultsPerPage, - // }, - // }); + 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 (
@@ -287,22 +293,12 @@ const Location = ({

Beds

-
-

Isolation

-

8 beds

-
-
-

ICU

-

5 beds

-
-
-

Oxygen Support

-

8 beds

-
-
-

Regular

-

20 beds

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

{type.name}

+

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

+
+ ))}