Skip to content

Commit

Permalink
chore: add alert in summary when sow not uploaded
Browse files Browse the repository at this point in the history
  • Loading branch information
RRanath committed Oct 3, 2024
1 parent 018dc75 commit 52db2da
Show file tree
Hide file tree
Showing 5 changed files with 341 additions and 79 deletions.
14 changes: 11 additions & 3 deletions app/components/Review/Accordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Link from 'next/link';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faMinus, faPen, faPlus } from '@fortawesome/free-solid-svg-icons';
import CbcRecordLock from 'components/Analyst/CBC/CbcRecordLock';
import { Tooltip } from '@mui/material';
import AlertIcon from './AlertIcon';

export function getToggledState(
Expand Down Expand Up @@ -64,13 +65,18 @@ const StyledLink = styled(Link)`
text-decoration: none;
`;

const StyledTooltip = styled(Tooltip)`
cursor: pointer;
`;

const Accordion = ({
allowAnalystEdit,
children,
defaultToggled,
isCBC,
cbcId,
error,
sectionErrors,
name,
onToggle,
toggled,
Expand Down Expand Up @@ -131,9 +137,11 @@ const Accordion = ({
))}

{error && (
<StyledAlert>
<AlertIcon />
</StyledAlert>
<StyledTooltip title={sectionErrors.join('\n')} placement="top">
<StyledAlert data-testid="styled-alert">
<AlertIcon />
</StyledAlert>
</StyledTooltip>
)}
<button type="button" onClick={handleToggle}>
{isToggled ? (
Expand Down
2 changes: 2 additions & 0 deletions app/components/Review/ReviewSectionField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const ReviewSectionField: React.FC<FieldProps> = (props) => {
const pageName = idSchema.$id?.split('_')?.[1];
const formErrorSchema = formContext?.formErrorSchema ?? formContext.errors;
const hasFormContextError = formErrorSchema?.[pageName];
const sectionErrors = hasFormContextError?.__errors;
const hasErrors = useMemo(
() => Object.keys(errorSchema || {}).length > 0 || !!hasFormContextError,
[errorSchema, hasFormContextError]
Expand All @@ -33,6 +34,7 @@ const ReviewSectionField: React.FC<FieldProps> = (props) => {
cbcId={formContext.cbcId}
isCBC={formContext.isCBC}
error={hasErrors}
sectionErrors={sectionErrors}
title={schema.title}
allowAnalystEdit={allowAnalystEdit}
recordLocked={formContext.recordLocked}
Expand Down
175 changes: 101 additions & 74 deletions app/lib/helpers/ccbcSummaryGenerateFormData.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import review from 'formSchema/analyst/summary/review';

const findScreeningAssessment = (assessments) => {
return assessments.nodes.find(
(assessment) => assessment.assessmentDataType === 'screening'
Expand Down Expand Up @@ -128,91 +130,116 @@ const getCommunities = (communities) => {
};
};

const getSowErrors = (sowData, schema, formDataSource) => {
if (sowData?.length) return null;
const errors = {};
Object.entries(schema?.properties || {}).forEach(([parentKey, value]) => {
const sectionSchema = value['properties'];
Object.keys(sectionSchema || {}).forEach((key) => {
if (formDataSource[key] === 'SOW') {
errors[parentKey] = errors[parentKey] || {
__errors: [
'Highlighted cells are null because SOW Excel table has not been uploaded in the portal',
],
};
errors[parentKey][key] = {
__errors: ['SOW excel table has not been uploaded in the portal'],
};
}
});
});

return errors;
};

const getSowData = (sowData, baseSowData) => {
const communitiesData = getCommunities(
sowData?.nodes[0]?.sowTab8SBySowId?.nodes[0]?.jsonData?.geoNames
);
const errors = {}; // errors may get added later
const communities =
sowData?.nodes[0]?.sowTab8SBySowId?.nodes[0]?.jsonData?.communitiesNumber;
const indigenousCommunities =
sowData?.nodes[0]?.sowTab8SBySowId?.nodes[0]?.jsonData
?.indigenousCommunitiesNumber;
return {
formData: {
counts: {
communities,
benefitingCommunities: communitiesData?.benefitingCommunities,
indigenousCommunities,
nonIndigenousCommunities:
communities && indigenousCommunities
? communities - indigenousCommunities
: communities,
benefitingIndigenousCommunities:
communitiesData?.benefitingIndigenousCommunities,
totalHouseholdsImpacted:
sowData?.nodes[0]?.sowTab1SBySowId?.nodes[0]?.jsonData
?.numberOfHouseholds,
numberOfIndigenousHouseholds:
sowData?.nodes[0]?.sowTab1SBySowId?.nodes[0]?.jsonData
?.householdsImpactedIndigenous,
},
funding: {
bcFundingRequested:
sowData?.nodes[0]?.sowTab7SBySowId?.nodes[0]?.jsonData?.summaryTable
?.amountRequestedFromProvince,
federalFunding:
sowData?.nodes[0]?.sowTab7SBySowId?.nodes[0]?.jsonData?.summaryTable
?.amountRequestedFromFederalGovernment,
fundingRequestedCcbc:
sowData?.nodes[0]?.sowTab7SBySowId?.nodes[0]?.jsonData?.summaryTable
?.totalFundingRequestedCCBC,
applicantAmount:
sowData?.nodes[0]?.sowTab7SBySowId?.nodes[0]?.jsonData?.summaryTable
?.totalApplicantContribution,
cibFunding:
sowData?.nodes[0]?.sowTab7SBySowId?.nodes[0]?.jsonData?.summaryTable
?.totalInfrastructureBankFunding,
fhnaFunding:
sowData?.nodes[0]?.sowTab7SBySowId?.nodes[0]?.jsonData?.summaryTable
?.totalFNHAFunding,
otherFunding:
sowData?.nodes[0]?.sowTab7SBySowId?.nodes[0]?.jsonData?.summaryTable
?.fundingFromAllOtherSources,
totalProjectBudget:
sowData?.nodes[0]?.sowTab7SBySowId?.nodes[0]?.jsonData?.summaryTable
?.totalProjectCost,
},
eventsAndDates: {
effectiveStartDate: sowData?.nodes[0]?.jsonData?.effectiveStartDate,
proposedStartDate: sowData?.nodes[0]?.jsonData?.projectStartDate,
proposedCompletionDate:
sowData?.nodes[0]?.jsonData?.projectCompletionDate,
dateAgreementSigned:
baseSowData?.nodes[0]?.jsonData?.dateFundingAgreementSigned,
},
const formData = {
counts: {
communities,
benefitingCommunities: communitiesData?.benefitingCommunities,
indigenousCommunities,
nonIndigenousCommunities:
communities && indigenousCommunities
? communities - indigenousCommunities
: communities,
benefitingIndigenousCommunities:
communitiesData?.benefitingIndigenousCommunities,
totalHouseholdsImpacted:
sowData?.nodes[0]?.sowTab1SBySowId?.nodes[0]?.jsonData
?.numberOfHouseholds,
numberOfIndigenousHouseholds:
sowData?.nodes[0]?.sowTab1SBySowId?.nodes[0]?.jsonData
?.householdsImpactedIndigenous,
},
formDataSource: {
communities: 'SOW',
benefitingCommunities: 'SOW',
indigenousCommunities: 'SOW',
nonIndigenousCommunities: 'SOW',
benefitingIndigenousCommunities: 'SOW',
totalHouseholdsImpacted: 'SOW',
numberOfIndigenousHouseholds: 'SOW',
bcFundingRequested: 'SOW',
federalFunding: 'SOW',
fundingRequestedCcbc: 'SOW',
applicantAmount: 'SOW',
cibFunding: 'SOW',
fhnaFunding: 'SOW',
otherFunding: 'SOW',
totalProjectBudget: 'SOW',
effectiveStartDate: 'SOW',
proposedStartDate: 'SOW',
proposedCompletionDate: 'SOW',
dateAgreementSigned: 'SOW',
funding: {
bcFundingRequested:
sowData?.nodes[0]?.sowTab7SBySowId?.nodes[0]?.jsonData?.summaryTable
?.amountRequestedFromProvince,
federalFunding:
sowData?.nodes[0]?.sowTab7SBySowId?.nodes[0]?.jsonData?.summaryTable
?.amountRequestedFromFederalGovernment,
fundingRequestedCcbc:
sowData?.nodes[0]?.sowTab7SBySowId?.nodes[0]?.jsonData?.summaryTable
?.totalFundingRequestedCCBC,
applicantAmount:
sowData?.nodes[0]?.sowTab7SBySowId?.nodes[0]?.jsonData?.summaryTable
?.totalApplicantContribution,
cibFunding:
sowData?.nodes[0]?.sowTab7SBySowId?.nodes[0]?.jsonData?.summaryTable
?.totalInfrastructureBankFunding,
fhnaFunding:
sowData?.nodes[0]?.sowTab7SBySowId?.nodes[0]?.jsonData?.summaryTable
?.totalFNHAFunding,
otherFunding:
sowData?.nodes[0]?.sowTab7SBySowId?.nodes[0]?.jsonData?.summaryTable
?.fundingFromAllOtherSources,
totalProjectBudget:
sowData?.nodes[0]?.sowTab7SBySowId?.nodes[0]?.jsonData?.summaryTable
?.totalProjectCost,
},
eventsAndDates: {
effectiveStartDate: sowData?.nodes[0]?.jsonData?.effectiveStartDate,
proposedStartDate: sowData?.nodes[0]?.jsonData?.projectStartDate,
proposedCompletionDate:
sowData?.nodes[0]?.jsonData?.projectCompletionDate,
dateAgreementSigned:
baseSowData?.nodes[0]?.jsonData?.dateFundingAgreementSigned,
},
};
const formDataSource = {
communities: 'SOW',
benefitingCommunities: 'SOW',
indigenousCommunities: 'SOW',
nonIndigenousCommunities: 'SOW',
benefitingIndigenousCommunities: 'SOW',
totalHouseholdsImpacted: 'SOW',
numberOfIndigenousHouseholds: 'SOW',
bcFundingRequested: 'SOW',
federalFunding: 'SOW',
fundingRequestedCcbc: 'SOW',
applicantAmount: 'SOW',
cibFunding: 'SOW',
fhnaFunding: 'SOW',
otherFunding: 'SOW',
totalProjectBudget: 'SOW',
effectiveStartDate: 'SOW',
proposedStartDate: 'SOW',
proposedCompletionDate: 'SOW',
dateAgreementSigned: 'SOW',
};
const errors = getSowErrors(sowData?.nodes, review, formDataSource);

return {
formData,
formDataSource,
errors,
};
};
Expand Down
1 change: 0 additions & 1 deletion app/pages/analyst/application/[applicationId]/summary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ const Summary = ({
isEditable: false,
errors,
formDataSource,
showErrorHint: true,
}}
formData={formData}
handleChange={() => {}}
Expand Down
Loading

0 comments on commit 52db2da

Please sign in to comment.