Skip to content

Commit

Permalink
WIP add footer
Browse files Browse the repository at this point in the history
  • Loading branch information
arsforza committed Aug 15, 2024
1 parent fe1a1bf commit a99b5bd
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
} from '../dto/notification-date-per-event.dto';
import { getMjmlBodyEvent } from './mjml/body-event';
import { getMjmlEventAdminAreaTable } from './mjml/event-admin-area-table';
import { getMjmlFooter } from './mjml/footer';
import { getMjmlMapImage } from './mjml/map-image';

const emailFolder = './src/api/notification/email';
Expand Down Expand Up @@ -572,6 +573,11 @@ export class EmailTemplateService {
});
}

public getMjmlFooter(countryName: string): object {
const ibfLogo = this.getLogoImageAsDataURL();
return getMjmlFooter({ ibfLogo, countryName });
}

private getCurrentDateTimeString(countryCodeISO3: string): string {
const date = new Date();
return this.dateObjectToDateTimeString(date, countryCodeISO3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ export class MjmlService {

children.push(mailBody);

children.push(
this.emailTemplateService.getMjmlFooter(emailContent.country.countryName),
);

const emailObject = {
tagName: 'mjml',
attributes: {},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TriggerStatusLabelEnum } from '../../dto/notification-date-per-event.dto';
import {
// getImageElement,
getInlineTriangleIcon,
getInlineImage,
getReturnElement,
getTextElement,
} from '../../helpers/mjml.helper';
Expand Down Expand Up @@ -43,7 +43,7 @@ export const getMjmlBodyEvent = ({
triangleIcon: string;
triggerStatusLabel: string;
}): object => {
const icon = getInlineTriangleIcon({ src: triangleIcon });
const icon = getInlineImage({ src: triangleIcon, size: 14 });

const eventNameElement = getTextElement({
attributes: { color },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import {
COLOR_WHITE,
getAdminAreaTable,
getInlineTriangleIcon,
getInlineImage,
getReturnElement,
getTextElement,
} from '../../helpers/mjml.helper';
Expand All @@ -31,7 +31,7 @@ export const getMjmlEventAdminAreaTable = ({
}) => {
const isTrigger = event.triggerStatusLabel === TriggerStatusLabelEnum.Trigger;

const icon = getInlineTriangleIcon({ src: triangleIcon });
const icon = getInlineImage({ src: triangleIcon, size: 14 });

const titleElement = getTextElement({
content: `${icon} <strong>${disasterTypeLabel} ${event.triggerStatusLabel} ${event.eventName}</strong>`,
Expand Down
47 changes: 47 additions & 0 deletions services/API-service/src/api/notification/email/mjml/footer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import {
COLOR_PRIMARY,
COLOR_WHITE,
getImageElement,
getReturnElement,
getTextElement,
} from '../../helpers/mjml.helper';

export const getMjmlFooter = ({
ibfLogo,
countryName,
}: {
ibfLogo: string;
countryName: string;
}): object => {
const logoElement = getImageElement({
src: ibfLogo,
otherAttributes: { width: '45px' },
});

const textElement = getTextElement({
content: `Impact-Based Forecasting Portal (IBF) was co-developed by Netherlands
Red Cross 510 the together with the ${countryName} Red Cross
National Society. For questions contact us at [email protected]`,
attributes: { color: COLOR_WHITE },
});

const twoColumnSectionElement = {
tagName: 'mj-section',
children: [
{
tagName: 'mj-column',
children: [logoElement],
attributes: { width: '20%' },
},
{
tagName: 'mj-column',
children: [textElement],
attributes: { width: '80%' },
},
],
};
return getReturnElement({
childrenEls: [twoColumnSectionElement],
attributes: { 'background-color': COLOR_PRIMARY },
});
};
13 changes: 8 additions & 5 deletions services/API-service/src/api/notification/helpers/mjml.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,14 @@ export const getAdminAreaTable = ({
};
};

// export const getInlineTriangleIcon = ({ src }: { src: string }): string =>
// `<img src="${src}" style="width: 14px; padding-right: 4px"></img>`;

export const getInlineTriangleIcon = ({ src }: { src: string }): string =>
`<img src="${src}" width="14" height="14" style="display: inline-block; width: 14px; height: 14px; max-width: 14px; max-height: 14px"></img>`;
export const getInlineImage = ({
src,
size,
}: {
src: string;
size: number;
}): string =>
`<img src="${src}" width="${size}" height="${size}" style="display: inline-block; width: ${size}px; height: ${size}px; max-width: ${size}px; max-height: ${size}px"></img>`;

export const getImageElement = ({
src,
Expand Down

0 comments on commit a99b5bd

Please sign in to comment.