Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show delete user button only for stateAdmin #6663

Merged
merged 2 commits into from
Nov 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 14 additions & 34 deletions src/Components/Facility/FacilityUsers.tsx
Original file line number Diff line number Diff line change
@@ -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"));

Expand Down Expand Up @@ -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 &&
Expand Down Expand Up @@ -340,7 +320,7 @@ export default function FacilityUsers(props: any) {
aria-label="Online"
></i>
) : null}
{showDelete(user) && (
{authUser.user_type === "StateAdmin" && (
<button
type="button"
className="focus:ring-blue m-3 w-20 self-end rounded-md border border-red-500 bg-white px-3 py-2 text-center text-sm font-medium leading-4 text-red-700 transition duration-150 ease-in-out hover:text-red-500 hover:shadow focus:border-red-300 focus:outline-none active:bg-gray-50 active:text-red-800"
Expand Down
Loading