From 05a3d83b5e919a6767314a06646e601554045b24 Mon Sep 17 00:00:00 2001 From: ankur prabhu Date: Sun, 21 Apr 2024 01:14:55 +0530 Subject: [PATCH 1/3] allow only admins to delete --- src/Components/Facility/BedManagement.tsx | 19 +++++++++++++++---- .../Facility/LocationManagement.tsx | 13 +++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/Components/Facility/BedManagement.tsx b/src/Components/Facility/BedManagement.tsx index 27100bf992b..542f6b7a9ec 100644 --- a/src/Components/Facility/BedManagement.tsx +++ b/src/Components/Facility/BedManagement.tsx @@ -12,6 +12,7 @@ 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) || + authUser.is_superuser; + const handleDeleteConfirm = async () => { const { res } = await request(routes.deleteFacilityBed, { pathParams: { external_id: id }, @@ -93,7 +98,7 @@ const BedRow = (props: BedRowProps) => { {LOCATION_BED_TYPES.find((item) => item.id === bedType) && (

{LOCATION_BED_TYPES.find( - (item) => item.id === bedType, + (item) => item.id === bedType )?.name?.slice(0, 25) + (bedType.length > 25 ? "..." : "")}

)} @@ -131,8 +136,14 @@ const BedRow = (props: BedRowProps) => { border ghost className="w-full lg:w-auto" - disabled={isOccupied} - tooltip={isOccupied ? "Bed is occupied" : undefined} + disabled={!allowedUser || isOccupied} + tooltip={ + !allowedUser + ? "Contact your admin to delete the bed" + : isOccupied + ? "Bed is occupied" + : undefined + } tooltipClassName="w-full lg:w-auto" > diff --git a/src/Components/Facility/LocationManagement.tsx b/src/Components/Facility/LocationManagement.tsx index 06e0de28d62..7151ccd41fb 100644 --- a/src/Components/Facility/LocationManagement.tsx +++ b/src/Components/Facility/LocationManagement.tsx @@ -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,13 @@ export default function LocationManagement({ facilityId }: Props) { setShowDeletePopup={setShowDeletePopup} facilityId={facilityId} {...item} + disabled={ + ["DistrictAdmin", "StateAdmin"].includes( + authUser.user_type + ) || authUser.is_superuser + ? false + : true + } /> )} @@ -213,6 +223,7 @@ const Location = ({ created_date, modified_date, id, + disabled, setShowDeletePopup, facilityId, }: LocationProps) => ( @@ -290,6 +301,8 @@ const Location = ({ variant="secondary" border className="w-full" + tooltip={disabled ? "Contact your admin to delete the location" : ""} + disabled={disabled ? true : false} onClick={() => setShowDeletePopup({ open: true, name: name ?? "", id: id ?? "" }) } From b359b4d2396019fdf56530970e34c957e02e7ca3 Mon Sep 17 00:00:00 2001 From: ankur prabhu Date: Wed, 24 Apr 2024 19:57:37 +0530 Subject: [PATCH 2/3] adding size change for tooltip --- src/Components/Facility/BedManagement.tsx | 2 +- src/Components/Facility/LocationManagement.tsx | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Components/Facility/BedManagement.tsx b/src/Components/Facility/BedManagement.tsx index 542f6b7a9ec..dbb5957fa7d 100644 --- a/src/Components/Facility/BedManagement.tsx +++ b/src/Components/Facility/BedManagement.tsx @@ -144,7 +144,7 @@ const BedRow = (props: BedRowProps) => { ? "Bed is occupied" : undefined } - tooltipClassName="w-full lg:w-auto" + tooltipClassName=" text-xs w-full lg:w-auto" > Delete diff --git a/src/Components/Facility/LocationManagement.tsx b/src/Components/Facility/LocationManagement.tsx index 7151ccd41fb..9fe76151a62 100644 --- a/src/Components/Facility/LocationManagement.tsx +++ b/src/Components/Facility/LocationManagement.tsx @@ -303,6 +303,7 @@ const Location = ({ className="w-full" tooltip={disabled ? "Contact your admin to delete the location" : ""} disabled={disabled ? true : false} + tooltipClassName=" text-xs w-full lg:w-auto" onClick={() => setShowDeletePopup({ open: true, name: name ?? "", id: id ?? "" }) } From e247a3fe24ffc78fd3349b7f5bace1920fb0d56b Mon Sep 17 00:00:00 2001 From: ankur prabhu Date: Sun, 19 May 2024 20:19:24 +0530 Subject: [PATCH 3/3] add suggested changes --- src/Components/Facility/BedManagement.tsx | 17 ++++++++--------- src/Components/Facility/LocationManagement.tsx | 9 +++------ 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/Components/Facility/BedManagement.tsx b/src/Components/Facility/BedManagement.tsx index dbb5957fa7d..10624675b5e 100644 --- a/src/Components/Facility/BedManagement.tsx +++ b/src/Components/Facility/BedManagement.tsx @@ -5,7 +5,7 @@ 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"; @@ -54,9 +54,9 @@ const BedRow = (props: BedRowProps) => { }); }; - const allowedUser = - ["DistrictAdmin", "StateAdmin"].includes(authUser.user_type) || - authUser.is_superuser; + const allowedUser = ["DistrictAdmin", "StateAdmin"].includes( + authUser.user_type, + ); const handleDeleteConfirm = async () => { const { res } = await request(routes.deleteFacilityBed, { @@ -98,7 +98,7 @@ const BedRow = (props: BedRowProps) => { {LOCATION_BED_TYPES.find((item) => item.id === bedType) && (

{LOCATION_BED_TYPES.find( - (item) => item.id === bedType + (item) => item.id === bedType, )?.name?.slice(0, 25) + (bedType.length > 25 ? "..." : "")}

)} @@ -131,18 +131,17 @@ const BedRow = (props: BedRowProps) => { handleDelete(name, id)} - authorizeFor={NonReadOnlyUsers} + authorizeFor={AuthorizeFor(["DistrictAdmin", "StateAdmin"])} variant="danger" border ghost className="w-full lg:w-auto" - disabled={!allowedUser || isOccupied} tooltip={ !allowedUser ? "Contact your admin to delete the bed" : isOccupied - ? "Bed is occupied" - : undefined + ? "Bed is occupied" + : undefined } tooltipClassName=" text-xs w-full lg:w-auto" > diff --git a/src/Components/Facility/LocationManagement.tsx b/src/Components/Facility/LocationManagement.tsx index 9fe76151a62..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"; @@ -119,9 +119,7 @@ export default function LocationManagement({ facilityId }: Props) { facilityId={facilityId} {...item} disabled={ - ["DistrictAdmin", "StateAdmin"].includes( - authUser.user_type - ) || authUser.is_superuser + ["DistrictAdmin", "StateAdmin"].includes(authUser.user_type) ? false : true } @@ -297,17 +295,16 @@ const Location = ({
setShowDeletePopup({ open: true, name: name ?? "", id: id ?? "" }) } - authorizeFor={NonReadOnlyUsers} > Delete