diff --git a/src/Components/Facility/BedManagement.tsx b/src/Components/Facility/BedManagement.tsx index 27100bf992b..10624675b5e 100644 --- a/src/Components/Facility/BedManagement.tsx +++ b/src/Components/Facility/BedManagement.tsx @@ -5,13 +5,14 @@ import { ReactElement } from "react"; import * as Notification from "../../Utils/Notifications.js"; import { LOCATION_BED_TYPES } from "../../Common/constants"; import BedDeleteDialog from "./BedDeleteDialog"; -import { NonReadOnlyUsers } from "../../Utils/AuthorizeFor"; +import AuthorizeFor, { NonReadOnlyUsers } from "../../Utils/AuthorizeFor"; import CareIcon from "../../CAREUI/icons/CareIcon"; import Page from "../Common/components/Page"; import request from "../../Utils/request/request"; import routes from "../../Redux/api"; import useQuery from "../../Utils/request/useQuery"; import useFilters from "../../Common/hooks/useFilters"; +import useAuthUser from "../../Common/hooks/useAuthUser"; const Loading = lazy(() => import("../Common/Loading")); interface BedManagementProps { @@ -45,7 +46,7 @@ const BedRow = (props: BedRowProps) => { show: boolean; name: string; }>({ show: false, name: "" }); - + const authUser = useAuthUser(); const handleDelete = (name: string, _id: string) => { setBedData({ show: true, @@ -53,6 +54,10 @@ const BedRow = (props: BedRowProps) => { }); }; + const allowedUser = ["DistrictAdmin", "StateAdmin"].includes( + authUser.user_type, + ); + const handleDeleteConfirm = async () => { const { res } = await request(routes.deleteFacilityBed, { pathParams: { external_id: id }, @@ -126,14 +131,19 @@ const BedRow = (props: BedRowProps) => { handleDelete(name, id)} - authorizeFor={NonReadOnlyUsers} + authorizeFor={AuthorizeFor(["DistrictAdmin", "StateAdmin"])} variant="danger" border ghost className="w-full lg:w-auto" - disabled={isOccupied} - tooltip={isOccupied ? "Bed is occupied" : undefined} - tooltipClassName="w-full lg:w-auto" + tooltip={ + !allowedUser + ? "Contact your admin to delete the bed" + : isOccupied + ? "Bed is occupied" + : undefined + } + tooltipClassName=" text-xs w-full lg:w-auto" > Delete diff --git a/src/Components/Facility/LocationManagement.tsx b/src/Components/Facility/LocationManagement.tsx index 06e0de28d62..18f3af60eb5 100644 --- a/src/Components/Facility/LocationManagement.tsx +++ b/src/Components/Facility/LocationManagement.tsx @@ -1,6 +1,6 @@ import { lazy, useState } from "react"; import ButtonV2, { Cancel } from "../Common/components/ButtonV2"; -import { NonReadOnlyUsers } from "../../Utils/AuthorizeFor"; +import AuthorizeFor, { NonReadOnlyUsers } from "../../Utils/AuthorizeFor"; import CareIcon from "../../CAREUI/icons/CareIcon"; import Page from "../Common/components/Page"; import routes from "../../Redux/api"; @@ -12,6 +12,7 @@ import * as Notification from "../../Utils/Notifications.js"; import ConfirmDialog from "../Common/ConfirmDialog"; import DialogModal from "../Common/Dialog"; import Uptime from "../Common/Uptime"; +import useAuthUser from "../../Common/hooks/useAuthUser"; const Loading = lazy(() => import("../Common/Loading")); @@ -21,10 +22,12 @@ interface Props { interface LocationProps extends LocationModel { facilityId: string; + disabled: boolean; setShowDeletePopup: (e: { open: boolean; name: string; id: string }) => void; } export default function LocationManagement({ facilityId }: Props) { + const authUser = useAuthUser(); const [showDeleteFailModal, setShowDeleteFailModal] = useState({ open: false, id: "", @@ -115,6 +118,11 @@ export default function LocationManagement({ facilityId }: Props) { setShowDeletePopup={setShowDeletePopup} facilityId={facilityId} {...item} + disabled={ + ["DistrictAdmin", "StateAdmin"].includes(authUser.user_type) + ? false + : true + } /> )} @@ -213,6 +221,7 @@ const Location = ({ created_date, modified_date, id, + disabled, setShowDeletePopup, facilityId, }: LocationProps) => ( @@ -286,14 +295,16 @@ const Location = ({
setShowDeletePopup({ open: true, name: name ?? "", id: id ?? "" }) } - authorizeFor={NonReadOnlyUsers} > Delete