From 8cb815e56b68d06983b3c6636f4f8f7a68bca0e5 Mon Sep 17 00:00:00 2001 From: Ayush Seth Date: Fri, 17 Nov 2023 21:37:07 +0530 Subject: [PATCH] show delete user button only for stateAdmin --- src/Components/Facility/FacilityUsers.tsx | 48 +++++++---------------- 1 file changed, 14 insertions(+), 34 deletions(-) diff --git a/src/Components/Facility/FacilityUsers.tsx b/src/Components/Facility/FacilityUsers.tsx index caff279ad7e..6963c4006db 100644 --- a/src/Components/Facility/FacilityUsers.tsx +++ b/src/Components/Facility/FacilityUsers.tsx @@ -1,28 +1,28 @@ import { lazy, useCallback, useEffect, useState } from "react"; import { useDispatch } from "react-redux"; +import CountBlock from "../../CAREUI/display/Count"; +import CareIcon from "../../CAREUI/icons/CareIcon"; +import { RESULTS_PER_PAGE_LIMIT } from "../../Common/constants"; +import useAuthUser from "../../Common/hooks/useAuthUser"; import { statusType, useAbortableEffect } from "../../Common/utils"; import { addUserFacility, - deleteUserFacility, - getUserListFacility, deleteUser, - getFacilityUsers, + deleteUserFacility, getAnyFacility, + getFacilityUsers, + getUserListFacility, } from "../../Redux/actions"; -import Pagination from "../Common/Pagination"; -import { USER_TYPES, RESULTS_PER_PAGE_LIMIT } from "../../Common/constants"; -import { FacilityModel } from "../Facility/models"; -import LinkFacilityDialog from "../Users/LinkFacilityDialog"; -import UserDeleteDialog from "../Users/UserDeleteDialog"; import * as Notification from "../../Utils/Notifications.js"; -import UserDetails from "../Common/UserDetails"; -import UnlinkFacilityDialog from "../Users/UnlinkFacilityDialog"; import { classNames, isUserOnline, relativeTime } from "../../Utils/utils"; -import CountBlock from "../../CAREUI/display/Count"; -import CareIcon from "../../CAREUI/icons/CareIcon"; +import Pagination from "../Common/Pagination"; +import UserDetails from "../Common/UserDetails"; import ButtonV2 from "../Common/components/ButtonV2"; import Page from "../Common/components/Page"; -import useAuthUser from "../../Common/hooks/useAuthUser"; +import { FacilityModel } from "../Facility/models"; +import LinkFacilityDialog from "../Users/LinkFacilityDialog"; +import UnlinkFacilityDialog from "../Users/UnlinkFacilityDialog"; +import UserDeleteDialog from "../Users/UserDeleteDialog"; const Loading = lazy(() => import("../Common/Loading")); @@ -273,26 +273,6 @@ export default function FacilityUsers(props: any) { loadFacilities(username); }; - const showDelete = (user: any) => { - const STATE_ADMIN_LEVEL = USER_TYPES.indexOf("StateAdmin"); - const STATE_READ_ONLY_ADMIN_LEVEL = - USER_TYPES.indexOf("StateReadOnlyAdmin"); - const DISTRICT_ADMIN_LEVEL = USER_TYPES.indexOf("DistrictAdmin"); - const level = USER_TYPES.indexOf(user.user_type); - const currentUserLevel = USER_TYPES.indexOf(authUser.user_type); - if (user.is_superuser) return true; - - if (currentUserLevel >= STATE_ADMIN_LEVEL) - return user.state_object?.id === authUser.state; - if ( - currentUserLevel < STATE_READ_ONLY_ADMIN_LEVEL && - currentUserLevel >= DISTRICT_ADMIN_LEVEL && - currentUserLevel > level - ) - return facilityData?.district_object_id === authUser.district; - return false; - }; - let userList: any[] = []; users && @@ -340,7 +320,7 @@ export default function FacilityUsers(props: any) { aria-label="Online" > ) : null} - {showDelete(user) && ( + {authUser.user_type === "StateAdmin" && (