Skip to content

Commit

Permalink
Restrict edit icon in compliance report
Browse files Browse the repository at this point in the history
  • Loading branch information
areyeslo committed Jan 9, 2025
1 parent 473ce03 commit ac23f7a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ export const EditViewComplianceReport = ({ reportData, isError, error }) => {
hasRoles
} = useCurrentUser()
const isGovernmentUser = currentUser?.isGovernmentUser
const isAnalystRole =
currentUser?.roles?.some((role) => role.name === roles.analyst) || false
const userRoles = currentUser?.roles

const currentStatus = reportData?.report.currentStatus?.status
const { data: orgData, isLoading } = useOrganization(
Expand Down Expand Up @@ -228,7 +227,7 @@ export const EditViewComplianceReport = ({ reportData, isError, error }) => {
<>
<ReportDetails
currentStatus={currentStatus}
isAnalystRole={isAnalystRole}
userRoles={userRoles}
/>
<ComplianceReportSummary
reportID={complianceReportId}
Expand Down
29 changes: 25 additions & 4 deletions frontend/src/views/ComplianceReports/components/ReportDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,41 @@ import DocumentUploadDialog from '@/components/Documents/DocumentUploadDialog'
import { useComplianceReportDocuments } from '@/hooks/useComplianceReports'
import { COMPLIANCE_REPORT_STATUSES } from '@/constants/statuses'

const ReportDetails = ({ currentStatus = 'Draft', isAnalystRole }) => {
const ReportDetails = ({ currentStatus = 'Draft', userRoles }) => {
const { t } = useTranslation()
const { compliancePeriod, complianceReportId } = useParams()
const navigate = useNavigate()

const [isFileDialogOpen, setFileDialogOpen] = useState(false)
const isAnalystRole = userRoles.some(role => role.name === roles.analyst) || false;
const isSupplierRole = userRoles.some(role => role.name === roles.supplier) || false;

const editSupportingDocs = useMemo(() => {
return isAnalystRole && (
currentStatus === COMPLIANCE_REPORT_STATUSES.SUBMITTED ||
currentStatus === COMPLIANCE_REPORT_STATUSES.ASSESSED
) || currentStatus === COMPLIANCE_REPORT_STATUSES.DRAFT;
)
}, [isAnalystRole, currentStatus]);

const editAnalyst = useMemo(() => {
return isAnalystRole && (
currentStatus === COMPLIANCE_REPORT_STATUSES.REASSESSED
)
}, [isAnalystRole, currentStatus]);

const editSupplier = useMemo(() => {
return isSupplierRole && (
currentStatus === COMPLIANCE_REPORT_STATUSES.DRAFT
)
}, [isSupplierRole, currentStatus]);

const shouldShowEditIcon = (activityName) => {
if (activityName === t('report:supportingDocs')) {
return editSupportingDocs;
}
return editAnalyst || editSupplier;
};

const isArrayEmpty = useCallback((data) => {
if (Array.isArray(data)) {
return data.length === 0
Expand Down Expand Up @@ -260,13 +282,12 @@ const ReportDetails = ({ currentStatus = 'Draft', isAnalystRole }) => {
component="div"
>
{activity.name}&nbsp;&nbsp;
{editSupportingDocs && (
{shouldShowEditIcon(activity.name) && (
<>
<Role
roles={[
roles.supplier,
roles.compliance_reporting,
roles.compliance_reporting,
roles.analyst
]}
>
Expand Down

0 comments on commit ac23f7a

Please sign in to comment.