diff --git a/app/controllers/new_administrateur/mail_templates_controller.rb b/app/controllers/new_administrateur/mail_templates_controller.rb index 32039afa3..b747f9681 100644 --- a/app/controllers/new_administrateur/mail_templates_controller.rb +++ b/app/controllers/new_administrateur/mail_templates_controller.rb @@ -3,12 +3,14 @@ module NewAdministrateur include ActionView::Helpers::SanitizeHelper def preview - @procedure = procedure + mail_template = find_mail_template_by_slug(params[:id]) + dossier = Dossier.new(id: '1', procedure: procedure) + + @dossier = dossier @logo_url = procedure.logo.url @service = procedure.service - - mail_template = find_mail_template_by_slug(params[:id]) @rendered_template = sanitize(mail_template.body) + @actions = mail_template.actions_for_dossier(dossier) render(template: 'notification_mailer/send_notification', layout: 'mailers/notifications_layout') end @@ -16,16 +18,16 @@ module NewAdministrateur private def procedure - @procedure = current_administrateur.procedures.find(params[:procedure_id]) + @procedure ||= current_administrateur.procedures.find(params[:procedure_id]) end def mail_templates [ - @procedure.initiated_mail_template, - @procedure.received_mail_template, - @procedure.closed_mail_template, - @procedure.refused_mail_template, - @procedure.without_continuation_mail_template + procedure.initiated_mail_template, + procedure.received_mail_template, + procedure.closed_mail_template, + procedure.refused_mail_template, + procedure.without_continuation_mail_template ] end diff --git a/app/helpers/mailer_helper.rb b/app/helpers/mailer_helper.rb index 28767841d..e653e703c 100644 --- a/app/helpers/mailer_helper.rb +++ b/app/helpers/mailer_helper.rb @@ -1,5 +1,28 @@ module MailerHelper - def round_button(text, url) - render 'shared/mailer_round_button', text: text, url: url + def vertical_margin(height) + render 'shared/mailer_vertical_margin', height: height + end + + def round_button(text, url, variant) + render 'shared/mailer_round_button', text: text, url: url, theme: theme(variant) + end + + private + + def theme(variant) + case variant + when :primary + { color: white, bg_color: blue, border_color: blue } + when :secondary + { color: blue, bg_color: white, border_color: blue } + end + end + + def blue + '#0069CC' + end + + def white + '#FFFFFF' end end diff --git a/app/mailers/notification_mailer.rb b/app/mailers/notification_mailer.rb index 816ff2c7c..5ec6cc596 100644 --- a/app/mailers/notification_mailer.rb +++ b/app/mailers/notification_mailer.rb @@ -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 diff --git a/app/models/concerns/mail_template_concern.rb b/app/models/concerns/mail_template_concern.rb index 3b613eb2b..f720c8297 100644 --- a/app/models/concerns/mail_template_concern.rb +++ b/app/models/concerns/mail_template_concern.rb @@ -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 diff --git a/app/models/mails/initiated_mail.rb b/app/models/mails/initiated_mail.rb index 9653b8d8c..da087942f 100644 --- a/app/models/mails/initiated_mail.rb +++ b/app/models/mails/initiated_mail.rb @@ -7,7 +7,7 @@ module Mails SLUG = "initiated_mail" DEFAULT_TEMPLATE_NAME = "notification_mailer/default_templates/initiated_mail" DISPLAYED_NAME = 'Accusé de réception' - DEFAULT_SUBJECT = 'Votre dossier nº --numéro du dossier-- a bien été reçu (--libellé démarche--)' + DEFAULT_SUBJECT = 'Votre dossier nº --numéro du dossier-- a bien été déposé (--libellé démarche--)' DOSSIER_STATE = Dossier.states.fetch(:en_construction) end end diff --git a/app/models/mails/received_mail.rb b/app/models/mails/received_mail.rb index 8e1c73b24..603d12be8 100644 --- a/app/models/mails/received_mail.rb +++ b/app/models/mails/received_mail.rb @@ -7,7 +7,7 @@ module Mails SLUG = "received_mail" DEFAULT_TEMPLATE_NAME = "notification_mailer/default_templates/received_mail" DISPLAYED_NAME = 'Accusé de passage en instruction' - DEFAULT_SUBJECT = 'Votre dossier nº --numéro du dossier-- va être instruit (--libellé démarche--)' + DEFAULT_SUBJECT = 'Votre dossier nº --numéro du dossier-- va être examiné (--libellé démarche--)' DOSSIER_STATE = Dossier.states.fetch(:en_instruction) end end diff --git a/app/models/mails/refused_mail.rb b/app/models/mails/refused_mail.rb index ad598d859..375b94326 100644 --- a/app/models/mails/refused_mail.rb +++ b/app/models/mails/refused_mail.rb @@ -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 diff --git a/app/views/dossier_mailer/notify_new_answer.html.haml b/app/views/dossier_mailer/notify_new_answer.html.haml index 3e0195afe..4db0e9270 100644 --- a/app/views/dossier_mailer/notify_new_answer.html.haml +++ b/app/views/dossier_mailer/notify_new_answer.html.haml @@ -5,13 +5,14 @@ Bonjour, %p - L’administration en charge de votre dossier vous a - %strong envoyé un nouveau message. + Vous avez reçu un + %strong nouveau message + de la part du service en charge de votre dossier. %p - Pour le consulter et y répondre, cliquez sur le bouton ci-dessous : + Pour consulter le message et y répondre, cliquez sur le bouton ci-dessous : -= round_button('Lire le message', messagerie_dossier_url(@dossier)) += round_button('Lire le message', messagerie_dossier_url(@dossier), :primary) = render 'layouts/mailers/signature', service: @service diff --git a/app/views/dossier_mailer/notify_new_draft.html.haml b/app/views/dossier_mailer/notify_new_draft.html.haml index fc22af857..93c8afcd1 100644 --- a/app/views/dossier_mailer/notify_new_draft.html.haml +++ b/app/views/dossier_mailer/notify_new_draft.html.haml @@ -5,13 +5,16 @@ Bonjour, %p - Vous avez commencé à remplir un dossier pour la démarche « #{@dossier.procedure.libelle} ». + Vous avez commencé à remplir un dossier pour la démarche + = succeed '.' do + %strong « #{@dossier.procedure.libelle} » %p Vous pouvez %strong retrouver et compléter votre dossier - à l’adresse suivante : - = link_to dossier_url(@dossier), dossier_url(@dossier), target: '_blank', rel: 'noopener' + en cliquant sur le bouton ci-dessous: + += round_button('Afficher votre dossier', dossier_url(@dossier), :primary) = render 'layouts/mailers/signature' diff --git a/app/views/notification_mailer/_actions.html.haml b/app/views/notification_mailer/_actions.html.haml new file mode 100644 index 000000000..7bf754962 --- /dev/null +++ b/app/views/notification_mailer/_actions.html.haml @@ -0,0 +1,13 @@ += vertical_margin(12) + +- 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(5) diff --git a/app/views/notification_mailer/default_templates/closed_mail.html.haml b/app/views/notification_mailer/default_templates/closed_mail.html.haml index 8af4e8e82..f32359535 100644 --- a/app/views/notification_mailer/default_templates/closed_mail.html.haml +++ b/app/views/notification_mailer/default_templates/closed_mail.html.haml @@ -2,7 +2,9 @@ Bonjour, %p - Votre dossier nº --numéro du dossier-- a été accepté le --date de décision--. + Votre dossier nº --numéro du dossier-- + %strong a été accepté + le --date de décision--. %p À tout moment, vous pouvez consulter votre dossier et les éventuels messages de l'administration à cette adresse : --lien dossier-- diff --git a/app/views/notification_mailer/default_templates/closed_mail_with_attestation.html.haml b/app/views/notification_mailer/default_templates/closed_mail_with_attestation.html.haml index 1c95b1ca7..277f8af7b 100644 --- a/app/views/notification_mailer/default_templates/closed_mail_with_attestation.html.haml +++ b/app/views/notification_mailer/default_templates/closed_mail_with_attestation.html.haml @@ -2,12 +2,11 @@ Bonjour, %p - Votre dossier nº --numéro du dossier-- a été accepté le --date de décision--. + Votre dossier nº --numéro du dossier-- + %strong a été accepté + le --date de décision--. %p Vous pouvez télécharger votre attestation à l'adresse suivante : --lien attestation-- -%p - À tout moment, vous pouvez consulter votre dossier et les éventuels messages de l'administration à cette adresse : --lien dossier-- - = render partial: "notification_mailer/default_templates/signature" diff --git a/app/views/notification_mailer/default_templates/initiated_mail.html.haml b/app/views/notification_mailer/default_templates/initiated_mail.html.haml index de2c1c91a..ab8d4a6c7 100644 --- a/app/views/notification_mailer/default_templates/initiated_mail.html.haml +++ b/app/views/notification_mailer/default_templates/initiated_mail.html.haml @@ -2,9 +2,9 @@ Bonjour, %p - Votre administration vous confirme la bonne réception de votre dossier nº --numéro du dossier--. - -%p - À tout moment, vous pouvez consulter votre dossier et les éventuels messages de l'administration à cette adresse : --lien dossier-- + Votre dossier nº --numéro du dossier-- + = succeed '.' do + %strong a bien été déposé + Si besoin est, vous pouvez encore y apporter des modifications. = render partial: "notification_mailer/default_templates/signature" diff --git a/app/views/notification_mailer/default_templates/received_mail.html.haml b/app/views/notification_mailer/default_templates/received_mail.html.haml index 234d1b1fe..17d82f9df 100644 --- a/app/views/notification_mailer/default_templates/received_mail.html.haml +++ b/app/views/notification_mailer/default_templates/received_mail.html.haml @@ -2,6 +2,10 @@ Bonjour, %p - Votre administration vous confirme la bonne réception de votre dossier nº --numéro du dossier--. Celui-ci sera instruit dans le délai légal déclaré par votre interlocuteur. + Votre dossier nº --numéro du dossier-- + a bien été reçu et + = succeed '.' do + %strong pris en charge + Il va maintenant être examiné par le service. = render partial: "notification_mailer/default_templates/signature" diff --git a/app/views/notification_mailer/default_templates/refused_mail.html.haml b/app/views/notification_mailer/default_templates/refused_mail.html.haml index 5cf09152f..2d7ef0bb3 100644 --- a/app/views/notification_mailer/default_templates/refused_mail.html.haml +++ b/app/views/notification_mailer/default_templates/refused_mail.html.haml @@ -2,10 +2,12 @@ Bonjour, %p - Votre dossier nº --numéro du dossier-- a été refusé le --date de décision--. + Votre dossier nº --numéro du dossier-- + %strong a été refusé + le --date de décision--. %p - Le motif de refus est le suivant : --motivation--. + Le motif de refus est le suivant : « --motivation-- ». %p Pour en savoir plus sur le motif du refus, vous pouvez consulter votre dossier et les éventuels messages de l'administration à cette adresse : --lien dossier-- diff --git a/app/views/notification_mailer/default_templates/without_continuation_mail.html.haml b/app/views/notification_mailer/default_templates/without_continuation_mail.html.haml index 731d65f08..429980e6b 100644 --- a/app/views/notification_mailer/default_templates/without_continuation_mail.html.haml +++ b/app/views/notification_mailer/default_templates/without_continuation_mail.html.haml @@ -2,7 +2,9 @@ Bonjour, %p - Votre dossier nº --numéro du dossier-- a été classé sans suite le --date de décision--. + Votre dossier nº --numéro du dossier-- + %strong a été classé sans suite + le --date de décision--. %p Le motif est le suivant : --motivation--. diff --git a/app/views/notification_mailer/send_notification.html.haml b/app/views/notification_mailer/send_notification.html.haml index 875806f48..6ce7aa565 100644 --- a/app/views/notification_mailer/send_notification.html.haml +++ b/app/views/notification_mailer/send_notification.html.haml @@ -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 diff --git a/app/views/shared/_mailer_round_button.html.haml b/app/views/shared/_mailer_round_button.html.haml index 18031f176..012479f2f 100644 --- a/app/views/shared/_mailer_round_button.html.haml +++ b/app/views/shared/_mailer_round_button.html.haml @@ -1,9 +1,10 @@ /# From https://litmus.com/blog/a-guide-to-bulletproof-buttons-in-email-design -%table{ width: "100%", border: "0", cellspacing:"0", cellpadding:"0" } +%table{ width: "100%", border: "0", cellspacing:"0", cellpadding:"5" } %tr - %td - %table{ border:"0", cellspacing:"0", cellpadding:"0", style:"margin: auto" } + %td{ align: "center" } + %table{ border:"0", cellspacing:"0", cellpadding:"0" } %tr - %td{ align:"center", style:"border-radius: 5px;", bgcolor:"#0069cc" } - %a{ href: url, target:"_blank", style:"font-size: 16px; font-family: Helvetica, Arial, sans-serif; color: #ffffff; text-decoration: none; text-decoration: none; border-radius: 5px; padding: 12px 25px; border: 1px solid #0069cc; display: inline-block;" } + %td{ align:"center", style:"border-radius: 5px;", color: theme[:color], bgcolor: theme[:bg_color] } + %a{ href: url, target:"_blank", rel: "noopener", style:"font-size: 16px; font-family: Helvetica, Arial, sans-serif; color: #{theme[:color]}; text-decoration: none; text-decoration: none; border-radius: 5px; padding: 12px 25px; border: 1px solid #{theme[:border_color]}; display: inline-block; min-width: 250px" } = text + diff --git a/app/views/shared/_mailer_vertical_margin.html.haml b/app/views/shared/_mailer_vertical_margin.html.haml new file mode 100644 index 000000000..9af4339db --- /dev/null +++ b/app/views/shared/_mailer_vertical_margin.html.haml @@ -0,0 +1,4 @@ +%table{ cellspacing: "0", cellpadding: (height / 2), border: "0" } + %tr + %td + %div diff --git a/spec/controllers/new_administrateur/mail_templates_controller_spec.rb b/spec/controllers/new_administrateur/mail_templates_controller_spec.rb index 2a8673f77..365abe78b 100644 --- a/spec/controllers/new_administrateur/mail_templates_controller_spec.rb +++ b/spec/controllers/new_administrateur/mail_templates_controller_spec.rb @@ -13,9 +13,17 @@ describe NewAdministrateur::MailTemplatesController, type: :controller do it { expect(response).to have_http_status(:ok) } - it { expect(response.body).to have_css("img[src*='#{procedure.logo.filename}']") } + it 'displays the procedure logo' do + expect(response.body).to have_css("img[src*='#{procedure.logo.filename}']") + end - it { expect(response.body).to include(procedure.service.nom) } - it { expect(response.body).to include(procedure.service.telephone) } + it 'displays the action buttons' do + expect(response.body).to have_link('Consulter mon dossier') + end + + it 'displays the service in the footer' do + expect(response.body).to include(procedure.service.nom) + expect(response.body).to include(procedure.service.telephone) + end end end diff --git a/spec/mailers/notification_mailer_spec.rb b/spec/mailers/notification_mailer_spec.rb index 4d28508b9..da2c13a7f 100644 --- a/spec/mailers/notification_mailer_spec.rb +++ b/spec/mailers/notification_mailer_spec.rb @@ -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.') } diff --git a/spec/mailers/previews/notification_mailer_preview.rb b/spec/mailers/previews/notification_mailer_preview.rb index 064d5471d..dff8bbed9 100644 --- a/spec/mailers/previews/notification_mailer_preview.rb +++ b/spec/mailers/previews/notification_mailer_preview.rb @@ -1,19 +1,20 @@ class NotificationMailerPreview < ActionMailer::Preview - def send_dossier_received - NotificationMailer.send_dossier_received(Dossier.last) - end - def send_initiated_notification p = Procedure.where(id: Mails::InitiatedMail.where("body like ?", "%