Skip to content

Commit

Permalink
changes made according to backend
Browse files Browse the repository at this point in the history
  • Loading branch information
shivankacker committed May 10, 2024
1 parent c9f46e3 commit eab99fd
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 18 deletions.
30 changes: 19 additions & 11 deletions src/Components/Facility/FacilityCreate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -251,25 +251,38 @@ export const FacilityCreate = (props: FacilityProps) => {
},
prefetch: !!facilityId,
onResponse: (res) => {
setHubFacilities(res.data?.results.map((d) => d.hub.id) as string[]);
setHubFacilities(
res.data?.results.map((d) => d.hub_object.id) as string[],
);
},
});
const createHub = async (hubFacilityId: string) =>
await request(routes.createFacilityHub, {
body: {
hub_id: hubFacilityId,
hub: hubFacilityId,
},
pathParams: {
id: facilityId || "",
},
onResponse: ({ res }) => {
if (res?.ok) {
hubsQuery.refetch();
}
},
});
const deleteHub = async (hubFacilityId: string) =>
await request(routes.deleteFacilityHub, {
pathParams: {
id: facilityId || "",
hub_id: hubFacilityId,
},
onResponse: ({ res }) => {
if (res?.ok) {
hubsQuery.refetch();
}
},
});

const { data: facilities } = facilitiesQuery;

useQuery(routes.getPermittedFacility, {
Expand Down Expand Up @@ -889,21 +902,16 @@ export const FacilityCreate = (props: FacilityProps) => {
value={hubFacilities}
onChange={async (event) => {
if (event.value.length > hubFacilities.length) {
await createHub(
event.value[event.value.length - 1] || "",
);
createHub(event.value[event.value.length - 1] || "");
} else if (event.value.length < hubFacilities.length) {
console.log(
hubFacilities.find((x) => !event.value.includes(x)),
);
await deleteHub(
deleteHub(
hubsQuery.data?.results.find(
(r) =>
r.hub.id ===
r.hub_object.id ===
(hubFacilities.find(
(x) => !event.value.includes(x),
) || ""),
)?.external_id || "",
)?.id || "",
);
}
setHubFacilities(event.value as string[]);
Expand Down
13 changes: 9 additions & 4 deletions src/Components/Facility/models.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,16 @@ export interface FacilityModel {
pincode?: string;
}

export enum HubRelationship {
TELE_ICU_HUB = 1,
}

export interface FacilityHubModel {
external_id: string;
hub: FacilityNameModel;
spoke: FacilityNameModel;
relationship: unknown;
id: string;
hub?: string;
hub_object: FacilityNameModel;
spoke_object: FacilityNameModel;
relationship: HubRelationship;
}
export interface CapacityModal {
id?: number;
Expand Down
4 changes: 1 addition & 3 deletions src/Redux/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,7 @@ const routes = {
path: "/api/v1/facility/{id}/hubs/",
method: "POST",
TRes: Type<FacilityHubModel>(),
TBody: Type<
Partial<Omit<FacilityHubModel, "hub" | "spoke">> & { hub_id: string }
>(),
TBody: Type<Partial<FacilityHubModel>>(),
},

deleteFacilityHub: {
Expand Down

0 comments on commit eab99fd

Please sign in to comment.