From bfecbaebc0a0da518aab3bcc4f9d00e6c7bb7d2d Mon Sep 17 00:00:00 2001
From: Bastien DUMONT <bdumont@grandlyon.com>
Date: Thu, 19 Sep 2024 16:42:38 +0200
Subject: [PATCH] feat(newsletter): incite user to connect his compteur when no
 data

---
 src/notifications/monthlyReport.hbs           | 25 ++++++++++++++-----
 src/notifications/style.hbs                   |  8 +++---
 .../services/monthlyReportNotification.ts     | 10 +++++---
 3 files changed, 30 insertions(+), 13 deletions(-)

diff --git a/src/notifications/monthlyReport.hbs b/src/notifications/monthlyReport.hbs
index bce1313b6..b004fa309 100644
--- a/src/notifications/monthlyReport.hbs
+++ b/src/notifications/monthlyReport.hbs
@@ -24,6 +24,9 @@
     <mj-section background-color="#121212">
       <mj-column padding="0 32px" vertical-align="middle">
         <mj-image src={{consoImageUrl}} width="132px" align="center" alt="consommation"></mj-image>
+        {{#unless comparisonExist }}
+          <mj-text color="#E3B82A" font-weight="900" font-size="20px" align="center">Oups !</mj-text>
+        {{/unless}}
         <mj-text color="white" font-weight="900" font-size="24px">
           Bonjour {{username}},
         </mj-text>
@@ -42,12 +45,22 @@
             </mj-text>
           {{/if}}
         {{/if}}
-        <mj-text color="#A0A0A0" font-weight="400" font-size="18px" align="center">Retrouvez le détail de vos consommations et plus d’informations dans votre bilan Ecolyo.</mj-text>
-        <mj-social css-class="button-with-icon" icon-size="32px" mode="horizontal" font-size="20px" font-weight="700">
-          <mj-social-element src="{{baseUrl}}/assets/ecolyo-icon.png" name="ecolyo" padding="0 10px 0 0" href="{{clientUrl}}">
-            J’ouvre mon Ecolyo
-          </mj-social-element>
-        </mj-social>
+        {{#if comparisonExist }}
+          <mj-text color="#A0A0A0" font-weight="400" font-size="18px" align="center">Retrouvez le détail de vos consommations et plus d’informations dans votre bilan Ecolyo.</mj-text>
+          <mj-social css-class="button-with-icon" icon-size="32px" mode="horizontal" font-size="20px" font-weight="700">
+            <mj-social-element src="{{baseUrl}}/assets/ecolyo-icon.png" name="ecolyo" padding="0 10px 0 0" href="{{clientUrl}}">
+              J’ouvre mon Ecolyo
+            </mj-social-element>
+          </mj-social>
+        {{/if}}
+        {{#unless comparisonExist }}
+          <mj-text color="white" font-weight="400" font-size="18px">Nous avons constaté que vous n'avez aucun compteur connecté. Sans accès à vos données de consommation, Ecolyo ne peut pas établir de bilan individuel de celles-ci.</mj-text>
+          <mj-social css-class="button-with-icon" icon-size="32px" mode="horizontal" font-size="20px" font-weight="700">
+            <mj-social-element src="{{baseUrl}}/assets/ecolyo-icon.png" name="ecolyo" padding="0 10px 0 0" href="{{clientUrl}}">
+              Connecter un compteur
+            </mj-social-element>
+          </mj-social>
+        {{/unless}}
       </mj-column>
     </mj-section>
     {{#if isContent}}
diff --git a/src/notifications/style.hbs b/src/notifications/style.hbs
index b1b78eb98..542bdaceb 100644
--- a/src/notifications/style.hbs
+++ b/src/notifications/style.hbs
@@ -17,10 +17,10 @@
   .button table { background-color: #F1C017 !important; margin: 10px !important;
   } .button-with-icon td { padding-right: 1px !important; } .button-with-icon
   table { background-color: #F1C017 !important; margin-left: 10px !important;
-  margin-right: 10px !important; } .button-with-icon span { vertical-align:
-  middle !important; } .button-with-icon a { vertical-align: middle !important;
-  padding-right: 10px !important;} .button-with-icon a img { padding-top: 20px
-  !important;}
+  margin-right: 10px !important; border-radius: 2px !important; }
+  .button-with-icon span { vertical-align: middle !important; }
+  .button-with-icon a { vertical-align: middle !important; padding-right: 10px
+  !important;} .button-with-icon a img { padding-top: 20px !important;}
 </mj-style>
 <mj-style>
   .custom-link a { color: #F1C017 !important; text-decoration: none !important;
diff --git a/src/targets/services/monthlyReportNotification.ts b/src/targets/services/monthlyReportNotification.ts
index 88f342166..672132e57 100644
--- a/src/targets/services/monthlyReportNotification.ts
+++ b/src/targets/services/monthlyReportNotification.ts
@@ -246,14 +246,16 @@ const monthlyReportNotification = async ({
   const environmentService = new EnvironmentService()
   const baseUrl = environmentService.getPublicURL()
 
+  const comparisonExist =
+    monthComparisonText.length > 0 || yearComparisonText.length > 0
+
   const template = monthlyReportTemplate({
     title: 'Infos & bilan consos',
     baseUrl: baseUrl,
     username: username,
     clientUrl: analysisLink,
     unsubscribeUrl: unsubscribeUrl,
-    comparisonExist:
-      monthComparisonText.length > 0 || yearComparisonText.length > 0,
+    comparisonExist: comparisonExist,
     monthComparisonExist: monthComparisonText.length > 0,
     monthComparisonText: monthComparisonText,
     yearComparisonExist: yearComparisonText.length > 0,
@@ -281,7 +283,9 @@ const monthlyReportNotification = async ({
     previousYear: date.year - 1,
     currentYear: date.year,
     previousMonthYear: date.month === 1 ? date.year - 1 : date.year,
-    consoImageUrl: baseUrl + '/assets/multifluidConsumption.png',
+    consoImageUrl: comparisonExist
+      ? baseUrl + '/assets/multifluidConsumption.png'
+      : baseUrl + '/assets/multifluidNoConsumption.png',
     feedbackImageUrl: baseUrl + '/assets/feedback.png',
   })
 
-- 
GitLab