-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add new brancher to control legacy vs non-legacy view * Split HistoryCard to its own component for re-usability and add tests * Update legacy view with legacy assessment card * Sent legacy_id to the front end
- Loading branch information
Showing
18 changed files
with
1,103 additions
and
246 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
frontend/src/views/ComplianceReports/ViewComplianceReportBrancher.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { useGetComplianceReport } from '@/hooks/useComplianceReports.js' | ||
import { useCurrentUser } from '@/hooks/useCurrentUser.js' | ||
import Loading from '@/components/Loading.jsx' | ||
import { ViewLegacyComplianceReport } from '@/views/ComplianceReports/ViewLegacyComplianceReport.jsx' | ||
import { useParams } from 'react-router-dom' | ||
import { EditViewComplianceReport } from '@/views/ComplianceReports/EditViewComplianceReport.jsx' | ||
|
||
export const ViewComplianceReportBrancher = () => { | ||
const { complianceReportId } = useParams() | ||
const { data: currentUser, isLoading: isCurrentUserLoading } = | ||
useCurrentUser() | ||
|
||
const { | ||
data: reportData, | ||
isLoading: isReportLoading, | ||
isError, | ||
error | ||
} = useGetComplianceReport( | ||
currentUser?.organization?.organizationId, | ||
complianceReportId | ||
) | ||
|
||
if (isReportLoading || isCurrentUserLoading) { | ||
return <Loading /> | ||
} | ||
|
||
return reportData.report.legacyId ? ( | ||
<ViewLegacyComplianceReport | ||
reportData={reportData} | ||
error={error} | ||
isError={isError} | ||
/> | ||
) : ( | ||
<EditViewComplianceReport | ||
reportData={reportData} | ||
error={error} | ||
isError={isError} | ||
/> | ||
) | ||
} |
143 changes: 143 additions & 0 deletions
143
frontend/src/views/ComplianceReports/ViewLegacyComplianceReport.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
import { useCallback, useEffect, useRef, useState } from 'react' | ||
import { FloatingAlert } from '@/components/BCAlert' | ||
import BCBox from '@/components/BCBox' | ||
import BCModal from '@/components/BCModal' | ||
import Loading from '@/components/Loading' | ||
import { Fab, Stack, Tooltip } from '@mui/material' | ||
import BCTypography from '@/components/BCTypography' | ||
import KeyboardArrowUpIcon from '@mui/icons-material/KeyboardArrowUp' | ||
import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown' | ||
import colors from '@/themes/base/colors.js' | ||
import { useTranslation } from 'react-i18next' | ||
import { useCurrentUser } from '@/hooks/useCurrentUser' | ||
import { useOrganization } from '@/hooks/useOrganization' | ||
import { LegacyAssessmentCard } from '@/views/ComplianceReports/components/LegacyAssessmentCard.jsx' | ||
|
||
const iconStyle = { | ||
width: '2rem', | ||
height: '2rem', | ||
color: colors.white.main | ||
} | ||
export const ViewLegacyComplianceReport = ({ reportData, error, isError }) => { | ||
const { t } = useTranslation(['common', 'report']) | ||
const [modalData, setModalData] = useState(null) | ||
const alertRef = useRef() | ||
|
||
const [isScrollingUp, setIsScrollingUp] = useState(false) | ||
const [lastScrollTop, setLastScrollTop] = useState(0) | ||
|
||
const scrollToTopOrBottom = () => { | ||
if (isScrollingUp) { | ||
window.scrollTo({ | ||
top: 0, | ||
behavior: 'smooth' | ||
}) | ||
} else { | ||
window.scrollTo({ | ||
top: document.documentElement.scrollHeight, | ||
behavior: 'smooth' | ||
}) | ||
} | ||
} | ||
|
||
const handleScroll = useCallback(() => { | ||
const scrollTop = window.pageYOffset || document.documentElement.scrollTop | ||
setIsScrollingUp(scrollTop < lastScrollTop || scrollTop === 0) | ||
setLastScrollTop(scrollTop) | ||
}, [lastScrollTop]) | ||
|
||
useEffect(() => { | ||
window.addEventListener('scroll', handleScroll) | ||
return () => window.removeEventListener('scroll', handleScroll) | ||
}, [handleScroll]) | ||
|
||
const { data: currentUser, isLoading: isCurrentUserLoading } = | ||
useCurrentUser() | ||
const isGovernmentUser = currentUser?.isGovernmentUser | ||
|
||
const currentStatus = reportData.report.currentStatus?.status | ||
const { data: orgData, isLoading } = useOrganization( | ||
reportData.report.organizationId | ||
) | ||
|
||
if (isLoading || isCurrentUserLoading) { | ||
return <Loading /> | ||
} | ||
|
||
if (isError) { | ||
return ( | ||
<> | ||
<FloatingAlert ref={alertRef} data-test="alert-box" delay={10000} /> | ||
<BCTypography color="error">{t('report:errorRetrieving')}</BCTypography> | ||
</> | ||
) | ||
} | ||
|
||
return ( | ||
<> | ||
<FloatingAlert ref={alertRef} data-test="alert-box" delay={10000} /> | ||
<BCBox pl={2} pr={2}> | ||
<BCModal | ||
open={!!modalData} | ||
onClose={() => setModalData(null)} | ||
data={modalData} | ||
/> | ||
<BCBox pb={2}> | ||
<BCTypography | ||
data-test="compliance-report-header" | ||
variant="h5" | ||
color="primary" | ||
> | ||
{reportData?.report.compliancePeriod.description} | ||
{t('report:complianceReport')} -  | ||
{reportData?.report.nickname} | ||
</BCTypography> | ||
<BCTypography | ||
variant="h6" | ||
color="primary" | ||
style={{ marginLeft: '0.25rem' }} | ||
data-test="compliance-report-status" | ||
> | ||
Status: {currentStatus} | ||
</BCTypography> | ||
</BCBox> | ||
<Stack direction="column" mt={2}> | ||
<LegacyAssessmentCard | ||
orgData={orgData} | ||
history={reportData?.report.history} | ||
isGovernmentUser={isGovernmentUser} | ||
currentStatus={currentStatus} | ||
legacyReportId={reportData?.report.legacyId} | ||
hasSupplemental={reportData?.report.hasSupplemental} | ||
chain={reportData.chain} | ||
/> | ||
</Stack> | ||
<Tooltip | ||
title={ | ||
isScrollingUp ? t('common:scrollToTop') : t('common:scrollToBottom') | ||
} | ||
placement="left" | ||
arrow | ||
> | ||
<Fab | ||
color="secondary" | ||
size="large" | ||
aria-label={isScrollingUp ? 'scroll to top' : 'scroll to bottom'} | ||
onClick={scrollToTopOrBottom} | ||
sx={{ | ||
position: 'fixed', | ||
bottom: 75, | ||
right: 24 | ||
}} | ||
> | ||
{isScrollingUp ? ( | ||
<KeyboardArrowUpIcon sx={iconStyle} /> | ||
) : ( | ||
<KeyboardArrowDownIcon sx={iconStyle} /> | ||
)} | ||
</Fab> | ||
</Tooltip> | ||
</BCBox> | ||
</> | ||
) | ||
} |
Oops, something went wrong.