-
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.
Merge pull request #3325 from bcgov/NDT-305-Email-Notification-to-Dat…
…a-Team-when-new-KMZ-uploaded feat: notify analyst when coverage kmz uploaded
- Loading branch information
Showing
10 changed files
with
531 additions
and
5 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
31 changes: 31 additions & 0 deletions
31
app/backend/lib/emails/templates/rfiCoverageMapKmzUploaded.ts
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,31 @@ | ||
import { | ||
EmailTemplate, | ||
EmailTemplateProvider, | ||
} from '../handleEmailNotification'; | ||
|
||
const rfiCoverageMapKmzUploaded: EmailTemplateProvider = ( | ||
applicationId: string, | ||
url: string, | ||
initiator: any, | ||
params: any | ||
): EmailTemplate => { | ||
const { ccbcNumber, rfiFormData, rfiNumber, changes, organizationName } = | ||
params; | ||
return { | ||
emailTo: [77, 34, 72], // Temporary IDs to handle email recipients | ||
emailCC: [], | ||
tag: 'rfi-coverage-map-kmz-uploaded', | ||
subject: `Notification - A KMZ was uploaded to ${ccbcNumber}`, | ||
body: ` | ||
<h1>KMZ file uploaded for RFI ${rfiNumber}</h1> | ||
<p>${organizationName || initiator.givenName} has uploaded the following KMZ(s):</p> | ||
<ul> | ||
${changes.map((file: any) => `<li>${file.name} ${file?.fileDate ? `received on ${file?.fileDate}` : `uploaded on ${file.uploadedAt}`}</li>`).join('')} | ||
</ul> | ||
<p>This <a href='${url}/analyst/application/${applicationId}/rfi'>RFI</a> closes/closed on ${rfiFormData?.rfiDueBy}<p> | ||
<p>To unsubscribe from this notification please forward this email with your request to <a href="mailto:[email protected]">[email protected]<a/></p> | ||
`, | ||
}; | ||
}; | ||
|
||
export default rfiCoverageMapKmzUploaded; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import * as Sentry from '@sentry/nextjs'; | ||
|
||
const useRfiCoverageMapKmzUploadedEmail = () => { | ||
const notifyRfiCoverageMapKmzUploaded = async ( | ||
rfiDataByRowId, | ||
rfiFormData, | ||
applicationId, | ||
ccbcNumber, | ||
rfiNumber, | ||
organizationName = null | ||
) => { | ||
const originalGeoCoverageMap = | ||
rfiDataByRowId?.jsonData?.rfiAdditionalFiles?.geographicCoverageMap || []; | ||
const newGeoCoverageMap = | ||
rfiFormData?.rfiAdditionalFiles?.geographicCoverageMap || []; | ||
const originalSet = new Set(originalGeoCoverageMap.map((k) => k.uuid)); | ||
const changes = newGeoCoverageMap.filter((k) => !originalSet.has(k.uuid)); | ||
// only send new emails if the actual coverage map has changed | ||
// as a save can occur without modification or only modification to other fields | ||
if (changes.length > 0) { | ||
const commonEmailObject = { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
applicationId, | ||
host: window.location.origin, | ||
ccbcNumber, | ||
rfiFormData, | ||
rfiNumber, | ||
changes, | ||
organizationName, | ||
}), | ||
}; | ||
fetch( | ||
'/api/email/notifyRfiCoverageMapKmzUploaded', | ||
commonEmailObject | ||
).then((r) => { | ||
if (!r.ok) { | ||
Sentry.captureException({ | ||
name: 'Email sending Agreement Signed Data Team failed', | ||
message: r, | ||
}); | ||
} | ||
return r.json(); | ||
}); | ||
} | ||
}; | ||
return { notifyRfiCoverageMapKmzUploaded }; | ||
}; | ||
|
||
export default useRfiCoverageMapKmzUploadedEmail; |
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
Oops, something went wrong.