Skip to content

Commit

Permalink
Preheader for grant digest
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffsmohan committed Mar 14, 2024
1 parent fc23022 commit 83e9b17
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/server/src/lib/email.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ async function buildDigestBody({ name, openDate, matchedGrants }) {
}

async function sendGrantDigest({
name, matchedGrants, recipients, openDate,
name, matchedGrants, matchedGrantsTotal, recipients, openDate,
}) {
console.log(`${name} is subscribed for notifications on ${openDate}`);

Expand All @@ -337,10 +337,14 @@ async function sendGrantDigest({
}

const formattedBody = await buildDigestBody({ name, openDate, matchedGrants });
const preheader = typeof matchedGrantsTotal === 'number' && matchedGrantsTotal > 0
? `You have ${Intl.NumberFormat('en-US', { useGrouping: true }).format(matchedGrantsTotal)} new ${matchedGrantsTotal > 1 ? 'grants' : 'grant'} to review!`
: 'You have new grants to review!';

const emailHTML = module.exports.addBaseBranding(formattedBody, {
tool_name: 'Federal Grant Finder',
title: 'New Grants Digest',
preheader,
notifications_url: (process.env.ENABLE_MY_PROFILE === 'true') ? `${process.env.WEBSITE_DOMAIN}/my-profile` : `${process.env.WEBSITE_DOMAIN}/grants?manageSettings=true`,
});

Expand Down Expand Up @@ -382,6 +386,7 @@ async function getAndSendGrantForSavedSearch({
return sendGrantDigest({
name: userSavedSearch.name,
matchedGrants: response.data,
matchedGrantsTotal: response.pagination.total,
recipients: [userSavedSearch.email],
openDate,
});
Expand Down Expand Up @@ -424,6 +429,7 @@ async function buildAndSendGrantDigest() {
agencies.forEach((agency) => inputs.push({
name: agency.name,
matchedGrants: agency.matched_grants,
matchedGrantsTotal: agency.matched_grants.length,
recipients: agency.recipients,
openDate,
}));
Expand Down
1 change: 1 addition & 0 deletions packages/server/src/routes/agencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ router.get('/sendDigestEmail', requireUSDRSuperAdminUser, async (req, res) => {
await email.sendGrantDigest({
name: agency[0].name,
matchedGrants: agency[0].matched_grants,
matchedGrantsTotal: agency[0].matched_grants.length,
recipients: agency[0].recipients,
});
} catch (e) {
Expand Down

0 comments on commit 83e9b17

Please sign in to comment.