From f947cbdcc4b9d307910d29a0dabbe97ab85e6d28 Mon Sep 17 00:00:00 2001 From: Craig Yu Date: Mon, 8 Jul 2024 23:20:33 -0700 Subject: [PATCH] fix: better seedlot review rbac (#1363) --- .../views/Seedlot/SeedlotDetails/index.tsx | 10 +++- .../SeedlotReview/SeedlotReviewContent.tsx | 47 ++++++++++--------- .../src/views/Seedlot/SeedlotReview/index.tsx | 29 +++++++++--- 3 files changed, 57 insertions(+), 29 deletions(-) diff --git a/frontend/src/views/Seedlot/SeedlotDetails/index.tsx b/frontend/src/views/Seedlot/SeedlotDetails/index.tsx index 11d3dfeff..ac38a4065 100644 --- a/frontend/src/views/Seedlot/SeedlotDetails/index.tsx +++ b/frontend/src/views/Seedlot/SeedlotDetails/index.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from 'react'; +import React, { useContext, useEffect, useState } from 'react'; import { useNavigate, useParams, useSearchParams } from 'react-router-dom'; import { FlexGrid, @@ -31,6 +31,7 @@ import { MEDIUM_SCREEN_WIDTH } from '../../../shared-constants/shared-constants' import Breadcrumbs from '../../../components/Breadcrumbs'; import { getMultiOptList } from '../../../utils/MultiOptionsUtils'; import { StatusOnSaveType } from '../../../api-service/tscAdminAPI'; +import AuthContext from '../../../contexts/AuthContext'; import SeedlotSummary from './SeedlotSummary'; import ApplicantInformation from './ApplicantInformation'; @@ -42,6 +43,7 @@ import './styles.scss'; const SeedlotDetails = () => { const navigate = useNavigate(); const windowSize = useWindowSize(); + const { isTscAdmin } = useContext(AuthContext); const { seedlotNumber } = useParams(); const [searchParams] = useSearchParams(); const [seedlotData, setSeedlotData] = useState(); @@ -230,7 +232,11 @@ const SeedlotDetails = () => { isFetching={forestClientQuery?.isFetching} /> { - (seedlotData?.seedlotStatus !== 'Pending' && seedlotData?.seedlotStatus !== 'Incomplete') + ( + isTscAdmin + && seedlotData?.seedlotStatus !== 'Pending' + && seedlotData?.seedlotStatus !== 'Incomplete' + ) ? : null } diff --git a/frontend/src/views/Seedlot/SeedlotReview/SeedlotReviewContent.tsx b/frontend/src/views/Seedlot/SeedlotReview/SeedlotReviewContent.tsx index e8762de93..fb39013cc 100644 --- a/frontend/src/views/Seedlot/SeedlotReview/SeedlotReviewContent.tsx +++ b/frontend/src/views/Seedlot/SeedlotReview/SeedlotReviewContent.tsx @@ -121,7 +121,7 @@ const SeedlotReviewContent = () => { const { allStepData, genWorthVals, geoInfoVals, - areaOfUseData, isFetchingData + areaOfUseData, isFetchingData, seedlotData } = useContext(ClassAContext); const verifyFormData = (): boolean => { @@ -536,26 +536,31 @@ const SeedlotReviewContent = () => { - - - - - - - - - + { + seedlotData?.seedlotStatus.seedlotStatusCode === 'SUB' + ? ( + + + + + + + + + ) + : null + } ); }; diff --git a/frontend/src/views/Seedlot/SeedlotReview/index.tsx b/frontend/src/views/Seedlot/SeedlotReview/index.tsx index b19b86be8..5b5072ca4 100644 --- a/frontend/src/views/Seedlot/SeedlotReview/index.tsx +++ b/frontend/src/views/Seedlot/SeedlotReview/index.tsx @@ -1,15 +1,32 @@ -import React from 'react'; +import React, { useContext, useEffect } from 'react'; +import { useNavigate } from 'react-router-dom'; import ContextContainerClassA from '../ContextContainerClassA'; +import AuthContext from '../../../contexts/AuthContext'; import SeedlotReviewContent from './SeedlotReviewContent'; import './styles.scss'; -const SeedlotReview = () => ( - - - -); +const SeedlotReview = () => { + const { isTscAdmin } = useContext(AuthContext); + const navigate = useNavigate(); + + useEffect(() => { + if (!isTscAdmin) { + navigate('/'); + } + }, [isTscAdmin]); + + if (!isTscAdmin) { + return null; + } + + return ( + + + + ); +}; export default SeedlotReview;