:sparkles: send email after email creation
        Hadrien Froger hadrien@octree.ch
        
        
        
        
        
        Fri, 10 Jul 2020 11:31:29 +0100
        
          4 files changed,
          37 insertions(+),
          5 deletions(-)
          
          
        
            
            
            
            M
            
          
          api/event/models/event.js
          
            → 
            api/event/models/event.js
          
          
            
          @@ -1,6 +1,6 @@
'use strict'; const axios = require('axios'); - +const moment = require('moment'); /** * Read the documentation (https://strapi.io/documentation/v3.x/concepts/models.html#lifecycle-hooks) * to customize this model@@ -49,6 +49,39 @@ );
} catch (error) { strapi.log.error(error); } + } + }, + + async afterCreate(event) { + let eventTime = ''; + if (event.date) { + eventTime = + ', ' + + moment(eventTime.date).locale('fr').format('dddd Do MMMM YYYY'); + } + let eventAddress = ''; + if (event.address) { + eventAddress = ', ' + event.address; + } + const {STRAPI_URL = ''} = process.env; + + try { + await strapi.plugins['sendgrid'].services.email.send({ + to: event.email, + from: 'caroster@octree.ch', + templateId: 'd-a1b5043fb186411ea4b57ea956625093', + dynamic_template_data: { + eventName: event.name, + eventTime, + eventAddress, + eventLink: `${STRAPI_URL}/e/${event.id}`, + }, + }); + } catch (error) { + strapi.log.error( + `Impossible to send email notification to ${event.email} for event#${event.id}:`, + error.message + ); } }, },
            
            
            
            M
            
          
          package-lock.json
          
            → 
            package-lock.json
          
          
            
          @@ -10348,9 +10348,7 @@ }
} }, "strapi-plugin-sendgrid": { - "version": "0.1.0", - "resolved": "https://npm-8ee.hidora.com/strapi-plugin-sendgrid/-/strapi-plugin-sendgrid-0.1.0.tgz", - "integrity": "sha512-CHJn0nKkhQC/dJ+rTo9q0V6H9hBUQCECoG7VtwAEAuf1k9OijF1/dTFL5lzA4lfu2hBDljul3Zo99Q7PvY+G8g==", + "version": "file:../strapi-plugin-sendgrid", "requires": { "axios": "^0.19.2" }
            
            
            
            M
            
          
          package.json
          
            → 
            package.json
          
          
            
          @@ -24,7 +24,7 @@ "strapi-middleware-reactapp": "^0.1.0",
"strapi-plugin-content-manager": "3.0.5", "strapi-plugin-content-type-builder": "3.0.5", "strapi-plugin-documentation": "^3.0.5", - "strapi-plugin-sendgrid": "^0.1.0", + "strapi-plugin-sendgrid": "file:../strapi-plugin-sendgrid", "strapi-plugin-upload": "^3.0.5", "strapi-plugin-users-permissions": "3.0.5", "strapi-utils": "3.0.5"