Skip to content

Commit

Permalink
Hide delete facility option for users who dont have access (#6953)
Browse files Browse the repository at this point in the history
* Hide delete facility option for users who dont have access

* refactor

Co-authored-by: Rithvik Nishad <[email protected]>

* fix lint and cypress tests

---------

Co-authored-by: Rithvik Nishad <[email protected]>
Co-authored-by: Mohammed Nihal <[email protected]>
  • Loading branch information
3 people authored Jan 4, 2024
1 parent d366f64 commit ff271f8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion cypress/e2e/patient_spec/patient_crud.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
emergency_phone_number,
phone_number,
} from "../../pageobject/constants";
const yearOfBirth = "2023";
const yearOfBirth = "2001";

const calculateAge = () => {
const currentYear = new Date().getFullYear();
Expand Down
27 changes: 16 additions & 11 deletions src/Components/Facility/FacilityHome.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Notification from "../../Utils/Notifications.js";

import AuthorizeFor, { NonReadOnlyUsers } from "../../Utils/AuthorizeFor";
import { NonReadOnlyUsers } from "../../Utils/AuthorizeFor";
import { FacilityModel } from "./models";
import { FACILITY_FEATURE_TYPES, USER_TYPES } from "../../Common/constants";
import DropdownMenu, { DropdownItem } from "../Common/components/Menu";
Expand Down Expand Up @@ -99,6 +99,10 @@ export const FacilityHome = (props: any) => {
USER_TYPES.findIndex((type) => type == authUser.user_type) >=
StaffUserTypeIndex;

const hasPermissionToDeleteFacility =
authUser.user_type === "DistrictAdmin" ||
authUser.user_type === "StateAdmin";

const editCoverImageTooltip = hasPermissionToEditCoverImage && (
<div className="absolute right-0 top-0 z-10 flex h-full w-full flex-col items-center justify-center bg-black text-sm text-gray-300 opacity-0 transition-[opacity] hover:opacity-60 md:h-[88px]">
<i className="fa-solid fa-pen" />
Expand Down Expand Up @@ -372,16 +376,17 @@ export const FacilityHome = (props: any) => {
>
View Users
</DropdownItem>
<DropdownItem
id="delete-facility"
variant="danger"
onClick={() => setOpenDeleteDialog(true)}
className="flex items-center gap-3"
icon={<CareIcon className="care-l-trash-alt text-lg" />}
authorizeFor={AuthorizeFor(["DistrictAdmin", "StateAdmin"])}
>
Delete Facility
</DropdownItem>
{hasPermissionToDeleteFacility && (
<DropdownItem
id="delete-facility"
variant="danger"
onClick={() => setOpenDeleteDialog(true)}
className="flex items-center gap-3"
icon={<CareIcon className="care-l-trash-alt text-lg" />}
>
Delete Facility
</DropdownItem>
)}
</DropdownMenu>
</div>
<div className="flex flex-col justify-end">
Expand Down

0 comments on commit ff271f8

Please sign in to comment.