diff --git a/src/Components/Facility/LocationManagement.tsx b/src/Components/Facility/LocationManagement.tsx index 8c10457942b..7e93eba13d9 100644 --- a/src/Components/Facility/LocationManagement.tsx +++ b/src/Components/Facility/LocationManagement.tsx @@ -1,11 +1,15 @@ import { lazy } from "react"; import { useTranslation } from "react-i18next"; +import { useDispatch } from "react-redux"; import CareIcon from "../../CAREUI/icons/CareIcon"; import PaginatedList from "../../CAREUI/misc/PaginatedList"; +import { removeFacilityAssetLocationDutyStaff } from "../../Redux/actions"; import routes from "../../Redux/api"; import { NonReadOnlyUsers } from "../../Utils/AuthorizeFor"; +import * as Notification from "../../Utils/Notifications.js"; import ButtonV2 from "../Common/components/ButtonV2"; import Page from "../Common/components/Page"; +import { UserAssignedModel } from "../Users/models"; import { LocationModel } from "./models"; const Loading = lazy(() => import("../Common/Loading")); @@ -55,7 +59,7 @@ export default function LocationManagement({ facilityId }: Props) { className="my-8 flex grow flex-col gap-3 lg:mx-8"> - {(item) => } + {(item) => }
@@ -67,17 +71,46 @@ export default function LocationManagement({ facilityId }: Props) { ); } -const Location = ({ - name, - description, - middleware_address, - id, - users, -}: LocationModel) => { +interface LocationProps extends LocationModel { + facilityId: string; +} + +const Location = (props: LocationProps) => { + const { id, name, description, middleware_address, users, facilityId } = + props; const doctors = users?.filter((u) => u.user_type === "Doctor") || []; const staffs = users?.filter((u) => u.user_type === "Staff") || []; + const dispatch: any = useDispatch(); + const { t } = useTranslation(); + + const handleDeleteStaff = async (user: UserAssignedModel) => { + if (id) { + const res = await dispatch( + removeFacilityAssetLocationDutyStaff( + { + duty_staff: [user.id], + }, + facilityId, + id + ) + ); + if (res && res.status === 204) { + Notification.Success({ + msg: "Staff removed successfully", + }); + setTimeout(() => { + window.location.reload(); + }, 1000); + } else { + Notification.Error({ + msg: "Failed to remove staff", + }); + } + } + }; + return (
@@ -87,17 +120,30 @@ const Location = ({

{middleware_address}

{doctors.map((doctor) => ( -

- -
{`${doctor.first_name} ${doctor.last_name}`}
+
+
+ +
{`${doctor.first_name} ${doctor.last_name}`}
+
+
))}

{staffs.map((s) => ( -

- -
{`${s.first_name} ${s.last_name}`}
+
+
+ +
{`${s.first_name} ${s.last_name}`}
+
+
))}

diff --git a/src/Redux/actions.tsx b/src/Redux/actions.tsx index f944929afbe..064c5e8cbe4 100644 --- a/src/Redux/actions.tsx +++ b/src/Redux/actions.tsx @@ -182,6 +182,16 @@ export const createFacilityAssetLocationDutyStaff = ( external_id, }); +export const removeFacilityAssetLocationDutyStaff = ( + params: object, + facility_external_id: string, + external_id: string +) => + fireRequest("removeFacilityAssetLocationDutyStaff", [], params, { + facility_external_id, + external_id, + }); + // asset bed export const listAssetBeds = (params: object, altKey?: string) => fireRequest("listAssetBeds", [], params, {}, altKey); diff --git a/src/Redux/api.tsx b/src/Redux/api.tsx index 7556c625e92..34ae642d896 100644 --- a/src/Redux/api.tsx +++ b/src/Redux/api.tsx @@ -313,7 +313,11 @@ const routes = { method: "PATCH", }, createFacilityAssetLocationDutyStaff: { - path: "/api/v1/facility/{facility_external_id}/asset_location/{external_id}/duty_staff/", + path: "/api/v1/facility/{facility_external_id}/asset_location/{external_id}/add_duty_staff/", + method: "POST", + }, + removeFacilityAssetLocationDutyStaff: { + path: "/api/v1/facility/{facility_external_id}/asset_location/{external_id}/remove_duty_staff/", method: "POST", },