Skip to content

Commit

Permalink
added auth check to the agency details form
Browse files Browse the repository at this point in the history
  • Loading branch information
LawrenceLau2020 committed Apr 11, 2024
1 parent 1fca0c0 commit 589ee1e
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions react-app/src/components/agencies/AgencyDetails.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react';
import React, { useContext, useEffect, useState } from 'react';
import DataCard from '../display/DataCard';
import { Box, Chip, Grid, Typography } from '@mui/material';
import { dateFormatter, statusChipFormatter } from '@/utilities/formatters';
Expand All @@ -13,9 +13,11 @@ import { Agency } from '@/hooks/api/useAgencyApi';
import TextFormField from '../form/TextFormField';
import DetailViewNavigation from '../display/DetailViewNavigation';
import { useGroupedAgenciesApi } from '@/hooks/api/useGroupedAgenciesApi';
import { useParams } from 'react-router-dom';
import { useNavigate, useParams } from 'react-router-dom';
import EmailChipFormField from '@/components/form/EmailChipFormField';
import SingleSelectBoxFormField from '@/components/form/SingleSelectBoxFormField';
import { AuthContext } from '@/contexts/authContext';
import { Roles } from '@/constants/roles';

interface IAgencyDetail {
onClose: () => void;
Expand All @@ -28,8 +30,13 @@ interface AgencyStatus extends Agency {
}

const AgencyDetail = ({ onClose }: IAgencyDetail) => {
const navigate = useNavigate();
const { id } = useParams();
const api = usePimsApi();
const userContext = useContext(AuthContext);
if (!userContext.keycloak.hasRole([Roles.ADMIN, Roles.AUDITOR], { requireAllRoles: false })) {
navigate('/');
}

const [openDeleteDialog, setOpenDeleteDialog] = useState(false);
const [openStatusDialog, setOpenStatusDialog] = useState(false);
Expand Down

0 comments on commit 589ee1e

Please sign in to comment.