comit to switch branch
MODIFY
src/notification/email/EMailNotificationTask.ts
src/notification/email/EMailNotificationTask.ts
@@ -54,28 +54,27 @@ export default class EMailNotificationTask implements NotificationTask {
}
public async sendNewRegisteredUser(data: NewRegisteredUserNotification, user: User, tenant: Tenant, severity: NotificationSeverity): Promise<void> {
- if (FeatureToggles.isFeatureActive(Feature.NEW_EMAIL_TEMPLATES)) {
- return this.sendSmartEmail('new-registered-user', data, user, tenant, severity);
- }
+ data.buttonUrl = data.evseDashboardVerifyEmailURL;
return this.prepareAndSendEmail('new-registered-user', data, user, tenant, severity);
}
public async sendRequestPassword(data: RequestPasswordNotification, user: User, tenant: Tenant, severity: NotificationSeverity): Promise<void> {
- if (FeatureToggles.isFeatureActive(Feature.NEW_EMAIL_TEMPLATES)) {
- return this.sendSmartEmail('request-password', data, user, tenant, severity);
- }
+ data.buttonUrl = data.evseDashboardResetPassURL;
return this.prepareAndSendEmail('request-password', data, user, tenant, severity);
}
public async sendOptimalChargeReached(data: OptimalChargeReachedNotification, user: User, tenant: Tenant, severity: NotificationSeverity): Promise<void> {
+ data.buttonUrl = data.evseDashboardChargingStationURL;
return this.prepareAndSendEmail('optimal-charge-reached', data, user, tenant, severity);
}
public async sendEndOfCharge(data: EndOfChargeNotification, user: User, tenant: Tenant, severity: NotificationSeverity): Promise<void> {
+ data.buttonUrl = data.evseDashboardChargingStationURL;
return this.prepareAndSendEmail('end-of-charge', data, user, tenant, severity);
}
public async sendEndOfSession(data: EndOfSessionNotification, user: User, tenant: Tenant, severity: NotificationSeverity): Promise<void> {
+ data.buttonUrl = data.evseDashboardChargingStationURL;
return this.prepareAndSendEmail('end-of-session', data, user, tenant, severity);
}
@@ -317,18 +316,16 @@ export default class EMailNotificationTask implements NotificationTask {
message: 'User is mandatory'
});
}
- // Create the template
+ context.appUrl = context.appUrl && 'https://open-e-mobility.io/';
+ const i18nInstance = I18nManager.getInstanceForLocale(user.locale);
const template = (await mjmlBuilder.initialize())
.addToBody(await EmailComponentManager.getComponent(EmailComponent.TITLE))
.addToBody(await EmailComponentManager.getComponent(EmailComponent.TEXT1))
.addToBody(await EmailComponentManager.getComponent(EmailComponent.BUTTON))
- .addToBody(await EmailComponentManager.getComponent(EmailComponent.TEXT2))
.buildTemplate();
-
- console.log(template.getTemplate());
- // Resolve
- const i18nInstance = I18nManager.getInstanceForLocale(user.locale);
template.resolve(i18nInstance, context,prefix);
+ console.log(template.getTemplate());
+ fs.writeFileSync('./file.txt',template.getTemplate(),'utf-8');
const html = template.getHtml();
emailContent = {
to: user.email,
@@ -356,6 +353,10 @@ export default class EMailNotificationTask implements NotificationTask {
}
private async prepareAndSendEmail(templateName: string, data: any, user: User, tenant: Tenant, severity: NotificationSeverity, useSmtpClientBackup = false): Promise<void> {
+ if (FeatureToggles.isFeatureActive(Feature.NEW_EMAIL_TEMPLATES)) {
+ return await this.sendSmartEmail(templateName, data, user, tenant, severity);
+ }
+
let startTime: number;
let emailContent = {} as EmailNotificationMessage;
try {

MODIFY
src/notification/email/mjml-components/button.mjml
src/notification/email/mjml-components/button.mjml
<mj-section>
<mj-column>
- <mj-button font-size="16px" href="#">
+ <mj-button font-size="16px" href="{{buttonUrl}}">
{{i18n:buttonText}}
</mj-button>
</mj-column>

MODIFY
src/notification/email/mjml-components/footer.mjml
src/notification/email/mjml-components/footer.mjml
</mj-column>
</mj-section>
+<mj-section padding-top="20px">
+ <mj-column>
+ <mj-text font-size="12px">
+ <p>{{i18n:common.footerText}}</p>
+ </mj-text>
+ </mj-column>
+</mj-section>
+
<mj-section>
<mj-column width="65%">
- <mj-image align="left" width="50px" href="https://open-e-mobility.fr/" src="https://imgur.com/Rloddiu.png"></mj-image>
+ <mj-image align="left" width="50px" href="{{appUrl}}" src="{{evseDashboardURL}}/assets/img/info.png"></mj-image>
</mj-column>
<mj-column width="35%">
<mj-table>

MODIFY
src/notification/email/mjml-components/header.mjml
src/notification/email/mjml-components/header.mjml
<mj-section>
<mj-column>
- <mj-image width="100px" href="https://open-e-mobility.fr/" src="{{tenantLogoURL}}"></mj-image>
+ <mj-image width="100px" href="{{evseDashboardURL}}" src="{{tenantLogoURL}}"></mj-image>
</mj-column>
</mj-section>

MODIFY
src/notification/email/mjml-template/MjmlTemplate.ts
src/notification/email/mjml-template/MjmlTemplate.ts
@@ -20,6 +20,7 @@ export default class MjmlTemplate {
public resolve(i18nManager: I18nManager, context: any, prefix: string): void {
const data = {};
Utils.flatten(context,data);
+ console.log(data);
this.preparei18nSelectors(prefix);
@@ -36,10 +37,9 @@ export default class MjmlTemplate {
for (const selector of contextSelectors) {
const keys = this.splitSelector(selector);
const value = this.getValue(keys, context);
+ console.log(selector, value);
this.replace(selector,value);
}
-
- console.log(this.template);
}
private replace(selector: string, value: string): void {
@@ -47,7 +47,7 @@ export default class MjmlTemplate {
}
private getContextSelectors(): string[] {
- const regex = new RegExp(/\{\{(.*)\}\}/, 'g');
+ const regex = new RegExp(/\{\{([a-zA-Z0-9_.-]*)\}\}/, 'g');
const matches = this.template.matchAll(regex);
const selectors = [];
for (const match of matches) {

MODIFY
src/types/UserNotifications.ts
src/types/UserNotifications.ts
@@ -98,6 +98,8 @@ export interface EmailNotificationMessage {
export interface BaseNotification {
tenantLogoURL?: string;
+ buttonUrl?:string;
+ appUrl?:string;
}
export interface EndOfChargeNotification extends BaseNotification {

comit to switch branch