Skip to content

Commit

Permalink
fix: better seedlot review rbac (#1363)
Browse files Browse the repository at this point in the history
  • Loading branch information
craigyu authored Jul 9, 2024
1 parent db0a546 commit f947cbd
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 29 deletions.
10 changes: 8 additions & 2 deletions frontend/src/views/Seedlot/SeedlotDetails/index.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 { useNavigate, useParams, useSearchParams } from 'react-router-dom';
import {
FlexGrid,
Expand Down Expand Up @@ -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';
Expand All @@ -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<SeedlotDisplayType>();
Expand Down Expand Up @@ -230,7 +232,11 @@ const SeedlotDetails = () => {
isFetching={forestClientQuery?.isFetching}
/>
{
(seedlotData?.seedlotStatus !== 'Pending' && seedlotData?.seedlotStatus !== 'Incomplete')
(
isTscAdmin
&& seedlotData?.seedlotStatus !== 'Pending'
&& seedlotData?.seedlotStatus !== 'Incomplete'
)
? <TscReviewSection seedlotNumber={seedlotNumber ?? ''} />
: null
}
Expand Down
47 changes: 26 additions & 21 deletions frontend/src/views/Seedlot/SeedlotReview/SeedlotReviewContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ const SeedlotReviewContent = () => {

const {
allStepData, genWorthVals, geoInfoVals,
areaOfUseData, isFetchingData
areaOfUseData, isFetchingData, seedlotData
} = useContext(ClassAContext);

const verifyFormData = (): boolean => {
Expand Down Expand Up @@ -536,26 +536,31 @@ const SeedlotReviewContent = () => {
<AuditInfo />
</Column>
</Row>
<Row className="action-button-row">
<Column className="action-button-col" sm={4} md={4} lg={4}>
<Button
kind="secondary"
renderIcon={Pending}
onClick={() => handleSaveAndStatus('PND')}
>
Send back to pending
</Button>
</Column>
<Column className="action-button-col" sm={4} md={4} lg={4}>
<Button
renderIcon={Checkmark}
onClick={() => handleSaveAndStatus('APP')}
>
Approve seedlot
</Button>
</Column>
</Row>

{
seedlotData?.seedlotStatus.seedlotStatusCode === 'SUB'
? (
<Row className="action-button-row">
<Column className="action-button-col" sm={4} md={4} lg={4}>
<Button
kind="secondary"
renderIcon={Pending}
onClick={() => handleSaveAndStatus('PND')}
>
Send back to pending
</Button>
</Column>
<Column className="action-button-col" sm={4} md={4} lg={4}>
<Button
renderIcon={Checkmark}
onClick={() => handleSaveAndStatus('APP')}
>
Approve seedlot
</Button>
</Column>
</Row>
)
: null
}
</FlexGrid>
);
};
Expand Down
29 changes: 23 additions & 6 deletions frontend/src/views/Seedlot/SeedlotReview/index.tsx
Original file line number Diff line number Diff line change
@@ -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 = () => (
<ContextContainerClassA>
<SeedlotReviewContent />
</ContextContainerClassA>
);
const SeedlotReview = () => {
const { isTscAdmin } = useContext(AuthContext);
const navigate = useNavigate();

useEffect(() => {
if (!isTscAdmin) {
navigate('/');
}
}, [isTscAdmin]);

if (!isTscAdmin) {
return null;
}

return (
<ContextContainerClassA>
<SeedlotReviewContent />
</ContextContainerClassA>
);
};

export default SeedlotReview;

0 comments on commit f947cbd

Please sign in to comment.