Skip to content

Commit

Permalink
Added listing of Hub Facilities in Facility Home (#8729)
Browse files Browse the repository at this point in the history
  • Loading branch information
shivankacker authored Oct 16, 2024
1 parent a8fd4c1 commit d199132
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 26 deletions.
29 changes: 21 additions & 8 deletions src/Components/Facility/FacilityBlock.tsx
Original file line number Diff line number Diff line change
@@ -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 ? (
<Link
target="_blank"
href={`/facility/${facility.id}`}
className={props.className}
>
{props.children}
</Link>
) : (
<button className={props.className}>{props.children}</button>
);

return (
<Link
className="flex items-center gap-4 text-inherit"
target="_blank"
href={`/facility/${facility.id}`}
>
<Element className="flex items-center gap-4 text-left text-inherit">
<div className="flex aspect-square h-14 shrink-0 items-center justify-center overflow-hidden rounded-lg border border-gray-400 bg-gray-200">
{facility.read_cover_image_url ? (
<img
Expand All @@ -27,6 +40,6 @@ export default function FacilityBlock(props: { facility: FacilityModel }) {
{facility.address} {facility.local_body_object?.name}
</p>
</div>
</Link>
</Element>
);
}
26 changes: 18 additions & 8 deletions src/Components/Facility/FacilityCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>();
const [notifyMessage, setNotifyMessage] = useState("");
const [notifyError, setNotifyError] = useState("");

Expand Down Expand Up @@ -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"
/>
)) || <Avatar name={facility.name} square={true} />}
)) || <Avatar name={facility.name ?? "Unknown"} square={true} />}
</Link>

<div className="mx-auto flex h-fit w-full max-w-full flex-col flex-wrap justify-between md:h-full lg:max-w-3xl">
Expand All @@ -79,7 +83,7 @@ export const FacilityCard = (props: { facility: any; userType: any }) => {
/>
)) || (
<Avatar
name={facility.name}
name={facility.name || ""}
square={true}
className="h-full w-full rounded-md object-cover"
/>
Expand Down Expand Up @@ -117,7 +121,7 @@ export const FacilityCard = (props: { facility: any; userType: any }) => {
</div>
<div className="mt-2 flex flex-wrap gap-1">
<Chip
text={facility.facility_type}
text={facility.facility_type || ""}
variant="custom"
className="bg-blue-100 text-blue-900"
hideBorder
Expand Down Expand Up @@ -173,7 +177,9 @@ export const FacilityCard = (props: { facility: any; userType: any }) => {
<div
id="occupany-badge"
className={`tooltip button-size-default ml-auto flex w-fit items-center justify-center rounded-md px-2 ${
facility.patient_count / facility.bed_count > 0.85
(facility.patient_count || 0) /
(facility.bed_count || 0) >
0.85
? "button-danger-border bg-red-500"
: "button-primary-border bg-primary-100"
}`}
Expand All @@ -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",
)}
/>{" "}
<dt
className={`text-sm font-semibold ${
facility.patient_count / facility.bed_count > 0.85
(facility.patient_count || 0) /
(facility.bed_count || 0) >
0.85
? "text-white"
: "text-secondary-700"
}`}
Expand Down
41 changes: 33 additions & 8 deletions src/Components/Facility/FacilityHome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand All @@ -93,13 +107,6 @@ export const FacilityHome = ({ facilityId }: Props) => {
});
};

const spokesQuery = useQuery(routes.getFacilitySpokes, {
pathParams: {
id: facilityId,
},
silent: true,
});

if (isLoading) {
return <Loading />;
}
Expand Down Expand Up @@ -274,7 +281,7 @@ export const FacilityHome = ({ facilityId }: Props) => {
/>
</div>
</div>
{!!spokesQuery.data?.results.length && (
{!!spokesQuery.data?.results?.length && (
<div className="mt-4 flex items-center gap-3">
<div id="spokes-view">
<h1 className="text-base font-semibold text-[#B9B9B9]">
Expand All @@ -291,6 +298,24 @@ export const FacilityHome = ({ facilityId }: Props) => {
</div>
</div>
)}

{!!hubsQuery.data?.results?.length && (
<div className="mt-4 flex items-center gap-3">
<div id="hubs-view">
<h1 className="text-base font-semibold text-[#B9B9B9]">
{t("hubs")}
</h1>
<div className="mt-4 grid grid-cols-1 gap-4 xl:grid-cols-2">
{hubsQuery.data.results.map((hub) => (
<FacilityBlock
facility={hub.hub_object}
redirect={false}
/>
))}
</div>
</div>
</div>
)}
</div>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/Components/Facility/models.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions src/Redux/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,12 @@ const routes = {
TBody: Type<Partial<FacilityModel>>(),
},

getFacilityHubs: {
path: "/api/v1/facility/{id}/hubs",
method: "GET",
TRes: Type<PaginatedResponse<FacilitySpokeModel>>(),
},

getFacilitySpokes: {
path: "/api/v1/facility/{id}/spokes/",
method: "GET",
Expand Down

0 comments on commit d199132

Please sign in to comment.