Skip to content

Commit

Permalink
Merge pull request #259 from dataforgoodfr/fix/D4G-260-remove-sendgri…
Browse files Browse the repository at this point in the history
…d-link-tracking

Fix/d4 g 260 remove sendgrid link tracking
  • Loading branch information
Baboo7 authored Mar 25, 2023
2 parents c6343a7 + 3f52ef3 commit 8ae49aa
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
3 changes: 2 additions & 1 deletion packages/emails/login-magic-link.mjml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
</mj-text>
<mj-button background-color="#f9c74f" font-family="Arial" font-size="16px" font-weight="bold" color="#1A3D5C" border-radius="16px" inner-padding="16px 32px" href="{{url}}"> Me Connecter </mj-button>
<mj-text align="center" font-size="14px" color="#ffffff">
<p font-family="Arial">Le bouton ne s'affiche pas ? <a style="color: #ffffff; text-decoration: underline;" href="{{url}}" font-family="Arial">Cliquez ici</a></p>
<p font-family="Arial">Le bouton ne fonctionne pas ? <br> Copiez/collez cette url dans votre navigateur pour vous connecter :</p>
<p><a style="color: #ffffff; text-decoration: underline; word-wrap: break-word;" href="" font-family="Arial">{{url}}</a></p>
</mj-text>
</mj-column>
</mj-section>
Expand Down
36 changes: 23 additions & 13 deletions packages/server/src/modules/notifications/services/mails.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import mailClient from "@sendgrid/mail";
import mailClient, { MailDataRequired } from "@sendgrid/mail";
import invariant from "tiny-invariant";
import { logger } from "../../../logger";

Expand All @@ -22,11 +22,23 @@ interface TemplateData {
};
}

interface TemplateConfig {
templateId: string;
asmGroupId?: number;
trackingSettings?: MailDataRequired["trackingSettings"];
}

const TEMPLATE_NAME_TO_CONFIG: {
[k in TemplateName]: { templateId: string; asmGroupId?: number };
[k in TemplateName]: TemplateConfig;
} = {
"login-magic-link": {
templateId: "d-a64abce41def4af0915688059ed632ac",
trackingSettings: {
clickTracking: {
enable: false,
enableText: false,
},
},
},
};

Expand All @@ -37,42 +49,39 @@ export async function sendMail<T extends TemplateName>(
templateName: T,
templateData: TemplateData[T]
) {
const config = TEMPLATE_NAME_TO_CONFIG[templateName];
const templateConfig = TEMPLATE_NAME_TO_CONFIG[templateName];

if (!config) {
if (!templateConfig) {
throw new Error(`Could not find config for email ${templateName}`);
}

await doSendEmail({
to,
templateConfig,
templateData,
templateId: config.templateId,
asmGroupId: config.asmGroupId,
});
}

async function doSendEmail({
to,
templateId,
templateConfig,
templateData,
asmGroupId,
}: {
to: string;
templateId: string;
templateConfig: TemplateConfig;
templateData: TemplateData[TemplateName];
asmGroupId?: number;
}) {
try {
await mailClient.send({
from: {
email: MAIL_SENDER,
name: MAIL_NAME,
},
templateId,
...(asmGroupId
templateId: templateConfig.templateId,
...(templateConfig.asmGroupId
? {
asm: {
groupId: asmGroupId,
groupId: templateConfig.asmGroupId,
},
}
: {}),
Expand All @@ -86,6 +95,7 @@ async function doSendEmail({
dynamicTemplateData: templateData as any,
},
],
...(templateConfig.trackingSettings || {}),
});
} catch (err) {
logger.error(err);
Expand Down

0 comments on commit 8ae49aa

Please sign in to comment.