mailers: add CTA to templated emails
This commit is contained in:
parent
6195ee41f3
commit
8313752663
6 changed files with 37 additions and 0 deletions
|
@ -9,6 +9,7 @@ class NotificationMailer < ApplicationMailer
|
|||
include ActionView::Helpers::SanitizeHelper
|
||||
|
||||
helper ServiceHelper
|
||||
helper MailerHelper
|
||||
|
||||
layout 'mailers/notifications_layout'
|
||||
|
||||
|
@ -46,6 +47,7 @@ class NotificationMailer < ApplicationMailer
|
|||
@service = dossier.procedure.service
|
||||
@logo_url = attach_logo(dossier.procedure)
|
||||
@rendered_template = sanitize(body)
|
||||
@actions = mail_template.actions_for_dossier(dossier)
|
||||
|
||||
mail(subject: subject, to: email, template_name: 'send_notification')
|
||||
end
|
||||
|
|
|
@ -3,6 +3,12 @@ module MailTemplateConcern
|
|||
|
||||
include TagsSubstitutionConcern
|
||||
|
||||
module Actions
|
||||
SHOW = :show
|
||||
ASK_QUESTION = :ask_question
|
||||
REPLY = :reply
|
||||
end
|
||||
|
||||
def subject_for_dossier(dossier)
|
||||
replace_tags(subject, dossier)
|
||||
end
|
||||
|
@ -11,6 +17,10 @@ module MailTemplateConcern
|
|||
replace_tags(body, dossier)
|
||||
end
|
||||
|
||||
def actions_for_dossier(dossier)
|
||||
[MailTemplateConcern::Actions::SHOW, MailTemplateConcern::Actions::ASK_QUESTION]
|
||||
end
|
||||
|
||||
def update_rich_body
|
||||
self.rich_body = self.body
|
||||
end
|
||||
|
|
|
@ -9,5 +9,9 @@ module Mails
|
|||
DISPLAYED_NAME = 'Accusé de rejet du dossier'
|
||||
DEFAULT_SUBJECT = 'Votre dossier nº --numéro du dossier-- a été refusé (--libellé démarche--)'
|
||||
DOSSIER_STATE = Dossier.states.fetch(:refuse)
|
||||
|
||||
def actions_for_dossier(dossier)
|
||||
[MailTemplateConcern::Actions::REPLY, MailTemplateConcern::Actions::SHOW]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
13
app/views/notification_mailer/_actions.html.haml
Normal file
13
app/views/notification_mailer/_actions.html.haml
Normal file
|
@ -0,0 +1,13 @@
|
|||
= vertical_margin(15)
|
||||
|
||||
- actions.each_with_index do |action, index|
|
||||
- variant = (index == 0 ? :primary : :secondary)
|
||||
- case action
|
||||
- when MailTemplateConcern::Actions::SHOW
|
||||
= round_button('Consulter mon dossier', dossier_url(@dossier), variant)
|
||||
- when MailTemplateConcern::Actions::ASK_QUESTION
|
||||
= round_button('J’ai une question', messagerie_dossier_url(@dossier), variant)
|
||||
- when MailTemplateConcern::Actions::REPLY
|
||||
= round_button('Répondre à ce message', messagerie_dossier_url(@dossier), variant)
|
||||
|
||||
= vertical_margin(8)
|
|
@ -3,5 +3,8 @@
|
|||
|
||||
= @rendered_template
|
||||
|
||||
- if @actions.present?
|
||||
= render 'notification_mailer/actions', actions: @actions, dossier: @dossier
|
||||
|
||||
- content_for :footer do
|
||||
= render 'layouts/mailers/service_footer', service: @service, dossier: @dossier
|
||||
|
|
|
@ -28,6 +28,11 @@ RSpec.describe NotificationMailer, type: :mailer do
|
|||
expect(mail.body).to have_link('messagerie')
|
||||
end
|
||||
|
||||
it 'renders the actions' do
|
||||
expect(mail.body).to have_link('Consulter mon dossier', href: dossier_url(dossier))
|
||||
expect(mail.body).to have_link('J’ai une question', href: messagerie_dossier_url(dossier))
|
||||
end
|
||||
|
||||
context 'when the template body contains tags' do
|
||||
let(:email_template) { create(:received_mail, subject: 'Email subject', body: 'Hello --nom--, your dossier --lien dossier-- was processed.') }
|
||||
|
||||
|
|
Loading…
Reference in a new issue