From d199132c34e2a2fcffdc428ab257679043d77fa0 Mon Sep 17 00:00:00 2001 From: Shivank Kacker Date: Wed, 16 Oct 2024 18:35:14 +0530 Subject: [PATCH] Added listing of Hub Facilities in Facility Home (#8729) --- src/Components/Facility/FacilityBlock.tsx | 29 +++++++++++----- src/Components/Facility/FacilityCard.tsx | 26 +++++++++----- src/Components/Facility/FacilityHome.tsx | 41 ++++++++++++++++++----- src/Components/Facility/models.tsx | 4 +-- src/Redux/api.tsx | 6 ++++ 5 files changed, 80 insertions(+), 26 deletions(-) diff --git a/src/Components/Facility/FacilityBlock.tsx b/src/Components/Facility/FacilityBlock.tsx index 891bb4d4e59..3232321637f 100644 --- a/src/Components/Facility/FacilityBlock.tsx +++ b/src/Components/Facility/FacilityBlock.tsx @@ -1,16 +1,29 @@ import { Link } from "raviger"; import { FacilityModel } from "./models"; +import { ReactNode } from "react"; import { Avatar } from "@/Components/Common/Avatar"; -export default function FacilityBlock(props: { facility: FacilityModel }) { - const { facility } = props; +export default function FacilityBlock(props: { + facility: FacilityModel; + redirect?: boolean; +}) { + const { facility, redirect = true } = props; + + const Element = (props: { children: ReactNode; className?: string }) => + redirect ? ( + + {props.children} + + ) : ( + + ); return ( - +
{facility.read_cover_image_url ? (
- +
); } diff --git a/src/Components/Facility/FacilityCard.tsx b/src/Components/Facility/FacilityCard.tsx index f3614d2685a..69b5b9d421e 100644 --- a/src/Components/Facility/FacilityCard.tsx +++ b/src/Components/Facility/FacilityCard.tsx @@ -13,13 +13,17 @@ import { classNames } from "../../Utils/utils"; import request from "../../Utils/request/request"; import routes from "../../Redux/api"; import careConfig from "@careConfig"; +import { FacilityModel } from "./models"; import { Avatar } from "../Common/Avatar"; -export const FacilityCard = (props: { facility: any; userType: any }) => { +export const FacilityCard = (props: { + facility: FacilityModel; + userType: string; +}) => { const { facility, userType } = props; const { t } = useTranslation(); - const [notifyModalFor, setNotifyModalFor] = useState(undefined); + const [notifyModalFor, setNotifyModalFor] = useState(); const [notifyMessage, setNotifyMessage] = useState(""); const [notifyError, setNotifyError] = useState(""); @@ -61,7 +65,7 @@ export const FacilityCard = (props: { facility: any; userType: any }) => { alt={facility.name} className="h-full max-h-32 w-full object-cover" /> - )) || } + )) || }
@@ -79,7 +83,7 @@ export const FacilityCard = (props: { facility: any; userType: any }) => { /> )) || ( @@ -117,7 +121,7 @@ export const FacilityCard = (props: { facility: any; userType: any }) => {
{
0.85 + (facility.patient_count || 0) / + (facility.bed_count || 0) > + 0.85 ? "button-danger-border bg-red-500" : "button-primary-border bg-primary-100" }`} @@ -185,14 +191,18 @@ export const FacilityCard = (props: { facility: any; userType: any }) => { icon="l-bed" className={classNames( "mr-2", - facility.patient_count / facility.bed_count > 0.85 + (facility.patient_count || 0) / + (facility.bed_count || 0) > + 0.85 ? "text-white" : "text-primary-600", )} />{" "}
0.85 + (facility.patient_count || 0) / + (facility.bed_count || 0) > + 0.85 ? "text-white" : "text-secondary-700" }`} diff --git a/src/Components/Facility/FacilityHome.tsx b/src/Components/Facility/FacilityHome.tsx index 6f73fee4a54..a50b1e09390 100644 --- a/src/Components/Facility/FacilityHome.tsx +++ b/src/Components/Facility/FacilityHome.tsx @@ -75,6 +75,20 @@ export const FacilityHome = ({ facilityId }: Props) => { }, }); + const spokesQuery = useQuery(routes.getFacilitySpokes, { + pathParams: { + id: facilityId, + }, + silent: true, + }); + + const hubsQuery = useQuery(routes.getFacilityHubs, { + pathParams: { + id: facilityId, + }, + silent: true, + }); + const handleDeleteClose = () => { setOpenDeleteDialog(false); }; @@ -93,13 +107,6 @@ export const FacilityHome = ({ facilityId }: Props) => { }); }; - const spokesQuery = useQuery(routes.getFacilitySpokes, { - pathParams: { - id: facilityId, - }, - silent: true, - }); - if (isLoading) { return ; } @@ -274,7 +281,7 @@ export const FacilityHome = ({ facilityId }: Props) => { />
- {!!spokesQuery.data?.results.length && ( + {!!spokesQuery.data?.results?.length && (

@@ -291,6 +298,24 @@ export const FacilityHome = ({ facilityId }: Props) => {

)} + + {!!hubsQuery.data?.results?.length && ( +
+
+

+ {t("hubs")} +

+
+ {hubsQuery.data.results.map((hub) => ( + + ))} +
+
+
+ )} diff --git a/src/Components/Facility/models.tsx b/src/Components/Facility/models.tsx index 8103ebb6729..1be0472c1c3 100644 --- a/src/Components/Facility/models.tsx +++ b/src/Components/Facility/models.tsx @@ -87,8 +87,8 @@ export interface FacilityModel { latitude?: string; longitude?: string; kasp_empanelled?: boolean; - patient_count?: string; - bed_count?: string; + patient_count?: number; + bed_count?: number; } export enum SpokeRelationship { diff --git a/src/Redux/api.tsx b/src/Redux/api.tsx index f1130345f46..ea728d7f53c 100644 --- a/src/Redux/api.tsx +++ b/src/Redux/api.tsx @@ -387,6 +387,12 @@ const routes = { TBody: Type>(), }, + getFacilityHubs: { + path: "/api/v1/facility/{id}/hubs", + method: "GET", + TRes: Type>(), + }, + getFacilitySpokes: { path: "/api/v1/facility/{id}/spokes/", method: "GET",