Skip to content

Commit

Permalink
Merge branch 'main' into NDT-471-Add-success-toast-and-feedback-for-A…
Browse files Browse the repository at this point in the history
…ssessment-email-notification
  • Loading branch information
RRanath authored Oct 2, 2024
2 parents d647164 + 47decd7 commit 9ec0e8c
Show file tree
Hide file tree
Showing 26 changed files with 568 additions and 101 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release-process.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ jobs:
PR_URL="${{ github.event.pull_request.html_url }}"
gh pr merge --auto --merge "$PR_URL"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.RENOVATE_GITHUB_TOKEN }}
- name: Uncheck the checkbox
if: steps.checkbox.outputs.result == 'true' && steps.up_to_date.outputs.result == 'true' && steps.pr_approval.outputs.result == 'true' && !github.event.pull_request.draft
uses: actions/github-script@v7
Expand Down
30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
## [1.195.1](https://github.com/bcgov/CONN-CCBC-portal/compare/v1.195.0...v1.195.1) (2024-10-01)

# [1.195.0](https://github.com/bcgov/CONN-CCBC-portal/compare/v1.194.2...v1.195.0) (2024-10-01)

### Features

- email notification when failed template scrape ([2b3757d](https://github.com/bcgov/CONN-CCBC-portal/commit/2b3757dcc84f48f36368c87560b3223aa37670ef))

## [1.194.2](https://github.com/bcgov/CONN-CCBC-portal/compare/v1.194.1...v1.194.2) (2024-10-01)

## [1.194.1](https://github.com/bcgov/CONN-CCBC-portal/compare/v1.194.0...v1.194.1) (2024-10-01)

### Bug Fixes

- user config in auto merge ([d65c1d0](https://github.com/bcgov/CONN-CCBC-portal/commit/d65c1d0c393805eed7e830a2725269488de904d4))

# [1.194.0](https://github.com/bcgov/CONN-CCBC-portal/compare/v1.193.9...v1.194.0) (2024-10-01)

### Features

- cutover work for cbc spreadsheet ([c62db66](https://github.com/bcgov/CONN-CCBC-portal/commit/c62db6656128de79316eb50ecca1cd7f9659b8e5))

## [1.193.9](https://github.com/bcgov/CONN-CCBC-portal/compare/v1.193.8...v1.193.9) (2024-10-01)

## [1.193.8](https://github.com/bcgov/CONN-CCBC-portal/compare/v1.193.7...v1.193.8) (2024-10-01)

### Bug Fixes

- correct line number for GIS import ([f6cee13](https://github.com/bcgov/CONN-CCBC-portal/commit/f6cee1374d9b2f48fa554152de92aa16a554e1a1))

## [1.193.7](https://github.com/bcgov/CONN-CCBC-portal/compare/v1.193.5...v1.193.7) (2024-09-27)

### Bug Fixes
Expand Down
11 changes: 11 additions & 0 deletions app/backend/lib/emails/email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import householdCountUpdate from './templates/householdCountUpdate';
import rfiCoverageMapKmzUploaded from './templates/rfiCoverageMapKmzUploaded';
import notifyConditionallyApproved from './templates/notifyConditionallyApproved';
import notifyApplicationSubmission from './templates/notifyApplicationSubmission';
import notifyFailedReadOfTemplateData from './templates/notifyFailedReadOfTemplateData';

const email = Router();

Expand Down Expand Up @@ -78,4 +79,14 @@ email.post('/api/email/notifyApplicationSubmission', limiter, (req, res) => {
});
});

email.post('/api/email/notifyFailedReadOfTemplateData', limiter, (req, res) => {
const { params } = req.body;
return handleEmailNotification(
req,
res,
notifyFailedReadOfTemplateData,
params
);
});

export default email;
1 change: 0 additions & 1 deletion app/backend/lib/emails/handleEmailNotification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ const handleEmailNotification = async (
return res.status(404).end();
}
const eventInitiator = getAuthUser(req);

const { applicationId, host } = req.body;
const {
emailTo,
Expand Down
4 changes: 2 additions & 2 deletions app/backend/lib/emails/templates/assessmentAssigneeChange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ const assessmentAssigneeChange: EmailTemplateProvider = async (
};
});
return {
assignors: ccbcAssignorUserList[assignor],
assignors: ccbcAssignorUserList?.[assignor] || 'A CCBC Analyst',
alerts,
};
}
);
// Get the list of assignors for the email
const assignorList = Object.keys(assignmentsByAssignor).map(
(key) => ccbcAssignorUserList[key]
(key) => ccbcAssignorUserList?.[key] || 'A CCBC Analyst'
);

return {
Expand Down
48 changes: 48 additions & 0 deletions app/backend/lib/emails/templates/notifyFailedReadOfTemplateData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import getConfig from 'next/config';
import {
EmailTemplate,
EmailTemplateProvider,
} from '../handleEmailNotification';

interface EmailTemplateParams {
templateNumber: string;
uuid: string;
organizationName: string | undefined;
projectTitle: string | undefined;
uploadedAt: string | undefined;
}

const notifyFailedReadOfTemplateData: EmailTemplateProvider = (
applicationId: string,
url: string,
initiator,
params: EmailTemplateParams
): EmailTemplate => {
const namespace = getConfig()?.publicRuntimeConfig?.OPENSHIFT_APP_NAMESPACE;
let env = 'Dev';
if (namespace?.endsWith('-prod')) {
env = 'Prod';
} else if (namespace?.endsWith('-test')) {
env = 'Test';
}

return {
emailTo: [111, 112, 113, 114, 115],
emailCC: [],
tag: 'failed-read-of-template-data',
subject: `Template ${params.templateNumber} - Failed Response`,
body: `
<p>
The following template upload by an applicant had a failed response at ${params.uploadedAt}:
</p>
<ul>
<li>Environment: ${env}</li>
<li>File UUID: ${params.uuid}</li>
<li>Template Number: ${params.templateNumber}</li>
<li>Application ID: ${applicationId}</li>
</ul>
`,
};
};

export default notifyFailedReadOfTemplateData;
11 changes: 8 additions & 3 deletions app/backend/lib/gis-upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import formidable, { File } from 'formidable';
import Ajv, { ErrorObject } from 'ajv';
import fs from 'fs';
import RateLimit from 'express-rate-limit';
import jsonSourceMap from 'json-source-map';
import schema from './gis-schema.json';
import { performQuery } from './graphql';
import getAuthRole from '../../utils/getAuthRole';
Expand Down Expand Up @@ -35,19 +36,23 @@ const FIELD_NAME_POSITION = 2;

const formatAjv = (data: Record<string, any>, errors: ErrorObject[]) => {
const reply = [];
const sourceMap = jsonSourceMap.stringify(data, null, 2);
errors.forEach((e) => {
const parts = e.instancePath.split('/');
const ccbcNumber = data?.[parts[LINE_NUMBER_POSITION]]?.ccbc_number ?? null;
const errorPointer = sourceMap.pointers[e.instancePath];
if (parts.length > MIN_PATH_DEPTH) {
const item = {
line: parseInt(parts[LINE_NUMBER_POSITION], 10) + 1,
ccbc_number: data[parts[LINE_NUMBER_POSITION]].ccbc_number,
line: (errorPointer?.key?.line || 0) + 1,
ccbc_number: ccbcNumber,
message: `${parts[FIELD_NAME_POSITION]} ${e.message}`,
};
reply.push(item);
} else {
// errors on root level
const item = {
line: 1,
line: e.keyword === 'required' ? null : 1,
ccbc_number: ccbcNumber,
message: e.message,
};
reply.push(item);
Expand Down
4 changes: 2 additions & 2 deletions app/components/Analyst/RFI/RFIAnalystUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const RfiAnalystUpload = ({ query }) => {
useRfiCoverageMapKmzUploadedEmail();

useEffect(() => {
if (templateData?.templateNumber === 1) {
if (templateData?.templateNumber === 1 && !templateData?.error) {
setExcelImportFields([...excelImportFields, 'Template 1']);
const newFormDataWithTemplateOne = {
...newFormData,
Expand All @@ -86,7 +86,7 @@ const RfiAnalystUpload = ({ query }) => {
},
};
setNewFormData(newFormDataWithTemplateOne);
} else if (templateData?.templateNumber === 2) {
} else if (templateData?.templateNumber === 2 && !templateData?.error) {
setExcelImportFields([...excelImportFields, 'Template 2']);
const newFormDataWithTemplateTwo = {
...newFormData,
Expand Down
7 changes: 7 additions & 0 deletions app/components/AnalystDashboard/AssessmentAssignmentTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,10 @@ const AssessmentAssignmentTable: React.FC<Props> = ({ query }) => {
application.allAssessments.edges,
'screening'
),
screeningNotification: findNotification(
application.assessmentNotifications.edges,
'assignment_screening'
),
financialRiskAssessment: findAssessment(
application.allAssessments.edges,
'financialRisk'
Expand Down Expand Up @@ -509,6 +513,7 @@ const AssessmentAssignmentTable: React.FC<Props> = ({ query }) => {

const assessmentChanged =
jsonData?.assignedTo &&
jsonData.assignedTo !== 'Unassigned' &&
jsonData.assignedTo !== notification?.jsonData?.to;

if (new Date(updatedAt) >= lastNotificationSentAt && assessmentChanged) {
Expand Down Expand Up @@ -537,10 +542,12 @@ const AssessmentAssignmentTable: React.FC<Props> = ({ query }) => {
'pm',
'projectManagement'
);
const screeningAssignment = createAssignment(application, 'screening');

if (techAssignment) assignmentsList.push(techAssignment);
if (financialAssignment) assignmentsList.push(financialAssignment);
if (pmAssignment) assignmentsList.push(pmAssignment);
if (screeningAssignment) assignmentsList.push(screeningAssignment);

return assignmentsList;
}, []);
Expand Down
36 changes: 34 additions & 2 deletions app/components/Form/ApplicationForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ const ApplicationForm: React.FC<Props> = ({
}

if (templateData) {
if (templateData.templateNumber === 1) {
if (templateData.templateNumber === 1 && !templateData.error) {
newFormData = {
...newFormData,
benefits: {
Expand All @@ -571,7 +571,7 @@ const ApplicationForm: React.FC<Props> = ({
templateData.data.result.finalEligibleHouseholds,
},
};
} else if (templateData.templateNumber === 2) {
} else if (templateData.templateNumber === 2 && !templateData.error) {
newFormData = {
...newFormData,
budgetDetails: {
Expand All @@ -580,6 +580,38 @@ const ApplicationForm: React.FC<Props> = ({
totalProjectCost: templateData.data.result.totalProjectCosts,
},
};
} else if (templateData.error && templateData.templateNumber === 1) {
fetch(`/api/email/notifyFailedReadOfTemplateData`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
applicationId: rowId,
host: window.location.origin,
params: {
uuid: newFormData.templateUploads
?.eligibilityAndImpactsCalculator?.[0]?.uuid,
uploadedAt:
newFormData.templateUploads
?.eligibilityAndImpactsCalculator?.[0]?.uploadedAt,
templateNumber: templateData.templateNumber,
},
}),
});
} else if (templateData.error && templateData.templateNumber === 2) {
fetch(`/api/email/notifyFailedReadOfTemplateData`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
applicationId: rowId,
host: window.location.origin,
params: {
uuid: newFormData.templateUploads?.detailedBudget?.[0]?.uuid,
uploadedAt:
newFormData.templateUploads?.detailedBudget?.[0]?.uploadedAt,
templateNumber: templateData.templateNumber,
},
}),
});
}
}

Expand Down
9 changes: 0 additions & 9 deletions app/components/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,6 @@ const Navigation: React.FC<Props> = ({ isLoggedIn = false, title = '' }) => {
</StyledRightSideLinks>
</StyledDiv>
</StyledBaseHeader>
{isCbcPage && (
<HeaderBanner
type="custom"
message="Beta version - changes made here will not be saved nor reflected elsewhere."
environmentIndicator={false}
customBannerColor="#F9F1C7"
customFontColor="#635231"
/>
)}
{isApplicantPortal && <SubHeader />}
</StyledBaseNavigation>
);
Expand Down
36 changes: 23 additions & 13 deletions app/lib/theme/widgets/FileWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,24 +86,34 @@ const FileWidget: React.FC<FileWidgetProps> = ({
if (file) {
fileFormData.append('file', file);
if (setTemplateData) {
await fetch(
`/api/applicant/template?templateNumber=${templateNumber}`,
{
method: 'POST',
body: fileFormData,
}
).then((response) => {
try {
const response = await fetch(
`/api/applicant/template?templateNumber=${templateNumber}`,
{
method: 'POST',
body: fileFormData,
}
);
if (response.ok) {
response.json().then((data) => {
setTemplateData({
templateNumber,
data,
});
const data = await response.json();
setTemplateData({
templateNumber,
data,
});
} else {
isTemplateValid = false;
setTemplateData({
templateNumber,
error: true,
});
}
});
} catch (error) {
isTemplateValid = false;
setTemplateData({
templateNumber,
error: true,
});
}
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
"js-cookie": "^3.0.5",
"json-diff": "^1.0.6",
"json-schema": "^0.4.0",
"json-source-map": "^0.6.1",
"jsonlint": "^1.6.3",
"jsonwebtoken": "^9.0.2",
"lightship": "7.2.0",
Expand All @@ -92,7 +93,7 @@
"openid-client": "^5.6.5",
"passport": "^0.7.0",
"patch-package": "^8.0.0",
"path-to-regexp": "^6.2.1",
"path-to-regexp": "^6.3.0",
"pg": "^8.11.5",
"pluralize": "^7.0.0",
"postgraphile": "^4.13.0",
Expand Down
8 changes: 7 additions & 1 deletion app/pages/analyst/gis/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,17 @@ const GisTab = () => {
const col = err?.posiition
? `and column ${err?.posiition}`
: '';
const erroneousCcbcNumber = err?.ccbc_number
? `for ${err?.ccbc_number}`
: '';
const errorAt = err?.line
? `at line ${err?.line}`
: erroneousCcbcNumber;
return (
<div
// eslint-disable-next-line react/no-array-index-key
key={index}
>{`Parsing error: ${err?.message} at line ${err?.line} ${col}`}</div>
>{`Parsing error: ${err?.message} ${errorAt} ${col}`}</div>
);
})}{' '}
Please check your file and try again.
Expand Down
Loading

0 comments on commit 9ec0e8c

Please sign in to comment.