Skip to content

Commit

Permalink
feat(location): added remove duty_staff feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhiuday committed Nov 27, 2023
1 parent c1d6bd6 commit 6638abf
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 15 deletions.
74 changes: 60 additions & 14 deletions src/Components/Facility/LocationManagement.tsx
Original file line number Diff line number Diff line change
@@ -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"));
Expand Down Expand Up @@ -55,7 +59,7 @@ export default function LocationManagement({ facilityId }: Props) {
</PaginatedList.WhenLoading>

<PaginatedList.Items<LocationModel> className="my-8 flex grow flex-col gap-3 lg:mx-8">
{(item) => <Location {...item} />}
{(item) => <Location {...item} facilityId={facilityId} />}
</PaginatedList.Items>

<div className="flex w-full items-center justify-center">
Expand All @@ -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 (
<div className="w-full items-center justify-between rounded border border-gray-300 bg-white p-6 shadow-sm transition-all duration-200 ease-in-out hover:border-primary-400 lg:flex">
<div className="lg:w-3/4">
Expand All @@ -87,17 +120,30 @@ const Location = ({
<p className="break-all text-sm lg:w-1/2">{middleware_address}</p>
<p className="flex flex-col gap-y-2 text-sm lg:w-1/6">
{doctors.map((doctor) => (
<div className="flex w-full rounded-lg border border-primary-600 bg-primary-100 px-3 py-1 text-primary-900">
<CareIcon className="care-l-user-md" />
<div className="ml-3">{`${doctor.first_name} ${doctor.last_name}`}</div>
<div className="flex flex-col items-center rounded-lg border border-primary-600 bg-primary-100 text-primary-900 xl:flex-row xl:items-start">
<div className="flex w-full px-3 py-1">
<CareIcon className="care-l-user-md" />
<div className="ml-3">{`${doctor.first_name} ${doctor.last_name}`}</div>
</div>
<button
className="p-2"
onClick={() => handleDeleteStaff(doctor)}
>
<CareIcon className="care-l-trash text-danger-600" />
</button>
</div>
))}
</p>
<p className="flex flex-col gap-y-2 text-sm lg:w-1/6">
{staffs.map((s) => (
<div className="flex w-full rounded-lg border border-primary-600 bg-primary-100 px-3 py-1 text-primary-900">
<CareIcon className="care-l-user-nurse" />
<div className="ml-3">{`${s.first_name} ${s.last_name}`}</div>
<div className="flex flex-col items-center rounded-lg border border-primary-600 bg-primary-100 text-primary-900 xl:flex-row xl:items-start">
<div className="flex w-full px-3 py-1">
<CareIcon className="care-l-user-md" />
<div className="ml-3">{`${s.first_name} ${s.last_name}`}</div>
</div>
<button className="p-2" onClick={() => handleDeleteStaff(s)}>
<CareIcon className="care-l-trash text-danger-600" />
</button>
</div>
))}
</p>
Expand Down
10 changes: 10 additions & 0 deletions src/Redux/actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion src/Redux/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},

Expand Down

0 comments on commit 6638abf

Please sign in to comment.