Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add alert in summary when sow not uploaded #3599

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## [1.197.2](https://github.com/bcgov/CONN-CCBC-portal/compare/v1.197.1...v1.197.2) (2024-10-10)

## [1.197.1](https://github.com/bcgov/CONN-CCBC-portal/compare/v1.197.0...v1.197.1) (2024-10-10)

# [1.197.0](https://github.com/bcgov/CONN-CCBC-portal/compare/v1.195.4...v1.197.0) (2024-10-04)
Expand Down
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
179 changes: 103 additions & 76 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 getEconomicRegions = (economicRegions) => {
if (!economicRegions) {
return null;
Expand Down Expand Up @@ -150,93 +152,118 @@ 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,
indigenousCommunities,
nonIndigenousCommunities:
communities && indigenousCommunities
? communities - indigenousCommunities
: communities,
totalHouseholdsImpacted:
sowData?.nodes[0]?.sowTab1SBySowId?.nodes[0]?.jsonData
?.numberOfHouseholds,
numberOfIndigenousHouseholds:
sowData?.nodes[0]?.sowTab1SBySowId?.nodes[0]?.jsonData
?.householdsImpactedIndigenous,
},
locations: {
benefitingCommunities: communitiesData?.benefitingCommunities,
benefitingIndigenousCommunities:
communitiesData?.benefitingIndigenousCommunities,
},
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,
indigenousCommunities,
nonIndigenousCommunities:
communities && indigenousCommunities
? communities - indigenousCommunities
: communities,
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',
locations: {
benefitingCommunities: communitiesData?.benefitingCommunities,
benefitingIndigenousCommunities:
communitiesData?.benefitingIndigenousCommunities,
},
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 @@ -229,7 +229,6 @@ const Summary = ({
isEditable: false,
errors,
formDataSource,
showErrorHint: true,
}}
formData={formData}
handleChange={() => {}}
Expand Down
Loading
Loading