Skip to content

Commit

Permalink
Add Restriction to redirect to facility page if user can't Create Fac…
Browse files Browse the repository at this point in the history
…ility (#7633)
  • Loading branch information
Pranshu1902 authored Apr 17, 2024
1 parent 214e45f commit 5326da3
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/Components/Facility/FacilityCreate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
SelectFormField,
} from "../Form/FormFields/SelectFormField";
import { Popover, Transition } from "@headlessui/react";
import { Fragment, lazy, useState } from "react";
import { Fragment, lazy, useEffect, useState } from "react";
import Steps, { Step } from "../Common/Steps";
import {
getPincodeDetails,
Expand Down Expand Up @@ -57,6 +57,7 @@ import request from "../../Utils/request/request.js";
import routes from "../../Redux/api.js";
import useQuery from "../../Utils/request/useQuery.js";
import { RequestResult } from "../../Utils/request/types.js";
import useAuthUser from "../../Common/hooks/useAuthUser";

const Loading = lazy(() => import("../Common/Loading"));

Expand Down Expand Up @@ -159,6 +160,21 @@ export const FacilityCreate = (props: FacilityProps) => {
const headerText = !facilityId ? "Create Facility" : "Update Facility";
const buttonText = !facilityId ? "Save Facility" : "Update Facility";

const authUser = useAuthUser();
useEffect(() => {
if (
authUser &&
authUser.user_type !== "StateAdmin" &&
authUser.user_type !== "DistrictAdmin" &&
authUser.user_type !== "DistrictLabAdmin"
) {
navigate("/facility");
Notification.Error({
msg: "You don't have permission to perform this action. Contact the admin",
});
}
}, [authUser]);

const {
data: districtData,
refetch: districtFetch,
Expand Down

0 comments on commit 5326da3

Please sign in to comment.