Skip to content

Commit

Permalink
removed badges and added hub facilities list in facility details
Browse files Browse the repository at this point in the history
  • Loading branch information
shivankacker committed Oct 9, 2024
1 parent 199ffec commit 0f19519
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 70 deletions.
2 changes: 1 addition & 1 deletion src/Components/Facility/FacilityBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default function FacilityBlock(props: {
facility: FacilityModel;
redirect?: boolean;
}) {
const { facility, redirect } = props;
const { facility, redirect = true } = props;

const Element = (props: { children: ReactNode; className?: string }) =>
redirect ? (
Expand Down
63 changes: 1 addition & 62 deletions src/Components/Facility/FacilityCard.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { useState } from "react";
import { Link } from "raviger";
import { useTranslation } from "react-i18next";
import {
FACILITY_FEATURE_TYPES,
SPOKE_RELATION_TYPES,
} from "../../Common/constants";
import { FACILITY_FEATURE_TYPES } from "../../Common/constants";
import ButtonV2, { Cancel, Submit } from "../Common/components/ButtonV2";
import * as Notification from "../../Utils/Notifications.js";
import Chip from "../../CAREUI/display/Chip";
Expand Down Expand Up @@ -135,64 +132,6 @@ export const FacilityCard = (props: {
hideBorder
size="small"
/>
{SPOKE_RELATION_TYPES.map((srt) => ({
...srt,
spokes: facility.hubs?.filter(
(hub) => hub.relationship === srt.value,
),
}))
.filter((srt) => srt.spokes?.length)
.map((srt) => (
<div className="tooltip">
<Chip
hideBorder
text={
(srt.text !== "Regular" ? srt.text + " " : "") +
"Spoke"
}
size="small"
className="bg-sky-100 text-sky-900"
/>
<span className="tooltip-text tooltip-bottom -translate-x-1/2 text-xs font-normal">
Linked with{" "}
{srt.spokes
?.map(
(relationship) =>
relationship.hub_object.name,
)
.join(", ")}
</span>
</div>
))}
{SPOKE_RELATION_TYPES.map((srt) => ({
...srt,
spokes: facility.spokes?.filter(
(hub) => hub.relationship === srt.value,
),
}))
.filter((srt) => srt.spokes?.length)
.map((srt) => (
<div className="tooltip">
<Chip
hideBorder
text={
(srt.text !== "Regular" ? srt.text + " " : "") +
"Hub"
}
size="small"
className="bg-purple-100 text-indigo-900"
/>
<span className="tooltip-text tooltip-bottom -translate-x-1/2 text-xs font-normal">
Linked with{" "}
{srt.spokes
?.map(
(relationship) =>
relationship.spoke_object.name,
)
.join(", ")}
</span>
</div>
))}
{facility.features?.map(
(feature: number) =>
FACILITY_FEATURE_TYPES.some(
Expand Down
27 changes: 22 additions & 5 deletions src/Components/Facility/FacilityHome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,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 Down Expand Up @@ -276,30 +290,33 @@ export const FacilityHome = ({ facilityId }: Props) => {
/>
</div>
</div>
{!!facilityData?.spokes?.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]">
{t("spokes")}
</h1>
<div className="mt-4 grid grid-cols-1 gap-4 xl:grid-cols-2">
{facilityData.spokes.map((spoke) => (
{spokesQuery.data.results.map((spoke) => (
<FacilityBlock facility={spoke.spoke_object} />
))}
</div>
</div>
</div>
)}

{!!facilityData?.hubs?.length && (
{!!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">
{facilityData.hubs.map((hub) => (
<FacilityBlock facility={hub.hub_object} />
{hubsQuery.data.results.map((hub) => (
<FacilityBlock
facility={hub.hub_object}
redirect={false}
/>
))}
</div>
</div>
Expand Down
2 changes: 0 additions & 2 deletions src/Components/Facility/models.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ export interface FacilityModel {
kasp_empanelled?: boolean;
patient_count?: number;
bed_count?: number;
hubs?: FacilitySpokeModel[];
spokes?: FacilitySpokeModel[];
}

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 0f19519

Please sign in to comment.