From 72b7391245772b640c4d2bb57ba847df6843a431 Mon Sep 17 00:00:00 2001 From: Pete Matsyburka Date: Sat, 18 May 2024 20:21:46 +0300 Subject: [PATCH] add documents copy email to template preferences --- .../templates_preferences_controller.rb | 5 +- app/mailers/submitter_mailer.rb | 10 +- .../documents_copy_email.html.erb | 4 +- app/views/templates_preferences/show.html.erb | 96 ++++++++++++++----- 4 files changed, 84 insertions(+), 31 deletions(-) diff --git a/app/controllers/templates_preferences_controller.rb b/app/controllers/templates_preferences_controller.rb index 48737fc1..ac3b2857 100644 --- a/app/controllers/templates_preferences_controller.rb +++ b/app/controllers/templates_preferences_controller.rb @@ -17,6 +17,9 @@ class TemplatesPreferencesController < ApplicationController private def template_params - params.require(:template).permit(preferences: %i[bcc_completed request_email_subject request_email_body]) + params.require(:template).permit( + preferences: %i[bcc_completed request_email_subject request_email_body + documents_copy_email_subject documents_copy_email_body] + ) end end diff --git a/app/mailers/submitter_mailer.rb b/app/mailers/submitter_mailer.rb index 5ad6a868..868242fc 100644 --- a/app/mailers/submitter_mailer.rb +++ b/app/mailers/submitter_mailer.rb @@ -76,9 +76,15 @@ class SubmitterMailer < ApplicationMailer submitter, with_audit_log: @email_config.nil? || @email_config.value['attach_audit_log'] != false ) + @subject = @submitter.template.preferences['documents_copy_email_subject'].presence + @subject ||= @email_config.value['subject'] if @email_config + + @body = @submitter.template.preferences['documents_copy_email_body'].presence + @body ||= @email_config.value['body'] if @email_config + subject = - if @email_config - ReplaceEmailVariables.call(@email_config.value['subject'], submitter:) + if @subject.present? + ReplaceEmailVariables.call(@subject, submitter:) else 'Your document copy' end diff --git a/app/views/submitter_mailer/documents_copy_email.html.erb b/app/views/submitter_mailer/documents_copy_email.html.erb index b0ede421..5c776c70 100644 --- a/app/views/submitter_mailer/documents_copy_email.html.erb +++ b/app/views/submitter_mailer/documents_copy_email.html.erb @@ -1,5 +1,5 @@ -<% if @email_config %> - <%= render 'custom_content', content: @email_config.value['body'], submitter: @submitter, sig: @sig %> +<% if @body.present? %> + <%= render 'custom_content', content: @body, submitter: @submitter, sig: @sig %> <% else %>

Hi there,

Please check the copy of your "<%= @submitter.submission.template.name %>" submission in the email attachments.

diff --git a/app/views/templates_preferences/show.html.erb b/app/views/templates_preferences/show.html.erb index a42ed0a2..c2aa251a 100644 --- a/app/views/templates_preferences/show.html.erb +++ b/app/views/templates_preferences/show.html.erb @@ -17,32 +17,6 @@ <% end %>
- <%= form_for @template, url: template_preferences_path(@template), method: :post, html: { autocomplete: 'off', class: 'mt-1' } do |f| %> - - <%= f.fields_for :preferences, Struct.new(:request_email_subject, :request_email_body).new(*(@template.preferences.values_at('request_email_subject', 'request_email_body').compact_blank.presence || AccountConfigs.find_or_initialize_for_key(current_account, AccountConfig::SUBMITTER_INVITATION_EMAIL_KEY).value.values_at('subject', 'body'))) do |ff| %> -
- <%= ff.label :request_email_subject, 'Email subject', class: 'label' %> - <%= ff.text_field :request_email_subject, required: true, class: 'base-input', dir: 'auto' %> -
-
-
- <%= ff.label :request_email_body, 'Email body', class: 'label' %> - - <%= svg_icon('info_circle', class: 'w-4 h-4') %> - -
- - <%= ff.text_area :request_email_body, required: true, class: 'base-input w-full py-2', dir: 'auto' %> - -
- <% end %> -
- <%= f.button button_title(title: 'Save', disabled_with: 'Saving'), class: 'base-button' %> -
- -
-
- <% end %> <%= form_for @template, url: template_preferences_path(@template), method: :post, html: { autocomplete: 'off', class: 'mt-2' } do |f| %> <%= f.fields_for :preferences, Struct.new(:bcc_completed).new(@template.preferences['bcc_completed']) do |ff| %> @@ -65,6 +39,76 @@
<% end %> <%= render 'templates_code_modal/preferences' %> +
+
+ +
+ Signature request email +
+
+ <%= form_for @template, url: template_preferences_path(@template), method: :post, html: { autocomplete: 'off', class: 'mt-1' } do |f| %> + + <%= f.fields_for :preferences, Struct.new(:request_email_subject, :request_email_body).new(*(@template.preferences.values_at('request_email_subject', 'request_email_body').compact_blank.presence || AccountConfigs.find_or_initialize_for_key(current_account, AccountConfig::SUBMITTER_INVITATION_EMAIL_KEY).value.values_at('subject', 'body'))) do |ff| %> +
+ <%= ff.label :request_email_subject, 'Email subject', class: 'label' %> + <%= ff.text_field :request_email_subject, required: true, class: 'base-input', dir: 'auto' %> +
+
+
+ <%= ff.label :request_email_body, 'Email body', class: 'label' %> + + <%= svg_icon('info_circle', class: 'w-4 h-4') %> + +
+ + <%= ff.text_area :request_email_body, required: true, class: 'base-input w-full py-2', dir: 'auto' %> + +
+ <% end %> +
+ <%= f.button button_title(title: 'Save', disabled_with: 'Saving'), class: 'base-button' %> +
+ +
+
+ <% end %> +
+
+
+ +
+ Documents copy email +
+
+ <%= form_for @template, url: template_preferences_path(@template), method: :post, html: { autocomplete: 'off', class: 'mt-1' } do |f| %> + + <%= f.fields_for :preferences, Struct.new(:documents_copy_email_subject, :documents_copy_email_body).new(*(@template.preferences.values_at('documents_copy_email_subject', 'documents_copy_email_body').compact_blank.presence || AccountConfigs.find_or_initialize_for_key(current_account, AccountConfig::SUBMITTER_DOCUMENTS_COPY_EMAIL_KEY).value.values_at('subject', 'body'))) do |ff| %> +
+ <%= ff.label :documents_copy_email_subject, 'Email subject', class: 'label' %> + <%= ff.text_field :documents_copy_email_subject, required: true, class: 'base-input', dir: 'auto' %> +
+
+
+ <%= ff.label :documents_copy_email_body, 'Email body', class: 'label' %> + + <%= svg_icon('info_circle', class: 'w-4 h-4') %> + +
+ + <%= ff.text_area :documents_copy_email_body, required: true, class: 'base-input w-full py-2', dir: 'auto' %> + +
+ <% end %> +
+ <%= f.button button_title(title: 'Save', disabled_with: 'Saving'), class: 'base-button' %> +
+ +
+
+ <% end %> +
+
+
<% if show_api %>