diff --git a/app/mailers/submitter_mailer.rb b/app/mailers/submitter_mailer.rb index d6d47abd..40d582b5 100644 --- a/app/mailers/submitter_mailer.rb +++ b/app/mailers/submitter_mailer.rb @@ -4,8 +4,6 @@ class SubmitterMailer < ApplicationMailer MAX_ATTACHMENTS_SIZE = 10.megabytes SIGN_TTL = 1.hour + 20.minutes - DEFAULT_INVITATION_SUBJECT = 'You are invited to submit a form' - NO_REPLY_REGEXP = /no-?reply@/i def invitation_email(submitter) @@ -21,17 +19,19 @@ class SubmitterMailer < ApplicationMailer @email_config = AccountConfigs.find_for_account(@current_account, AccountConfig::SUBMITTER_INVITATION_EMAIL_KEY) + assign_message_metadata('submitter_invitation', @submitter) + + reply_to = build_submitter_reply_to(@submitter) + subject = if @email_config || @subject ReplaceEmailVariables.call(@subject || @email_config.value['subject'], submitter:) + elsif @submitter.with_signature_fields? + I18n.t(:you_are_invited_to_sign_a_document) else - DEFAULT_INVITATION_SUBJECT + I18n.t(:you_are_invited_to_submit_a_form) end - assign_message_metadata('submitter_invitation', @submitter) - - reply_to = build_submitter_reply_to(@submitter) - mail( to: @submitter.friendly_name, from: from_address_for_submitter(submitter), @@ -64,15 +64,12 @@ class SubmitterMailer < ApplicationMailer @body = @submitter.template.preferences['completed_notification_email_body'].presence @body ||= @email_config.value['body'] if @email_config - subject = - if @subject.present? - ReplaceEmailVariables.call(@subject, submitter:) - else - build_completed_subject(submitter) - end - assign_message_metadata('submitter_completed', @submitter) + subject = + ReplaceEmailVariables.call(@subject.presence || I18n.t(:template_name_has_been_completed_by_submitters), + submitter:) + mail(from: from_address_for_submitter(submitter), to: to || (user.role == 'integration' ? user.friendly_name.sub(/\+\w+@/, '@') : user.friendly_name), subject:) @@ -116,17 +113,16 @@ class SubmitterMailer < ApplicationMailer @body = @submitter.template.preferences['documents_copy_email_body'].presence @body ||= @email_config.value['body'] if @email_config + assign_message_metadata('submitter_documents_copy', @submitter) + reply_to = build_submitter_reply_to(submitter) + subject = if @subject.present? ReplaceEmailVariables.call(@subject, submitter:) else - 'Your document copy' + I18n.t(:your_document_copy) end - assign_message_metadata('submitter_documents_copy', @submitter) - - reply_to = build_submitter_reply_to(submitter) - mail(from: from_address_for_submitter(submitter), to: to || @submitter.friendly_name, reply_to:, @@ -145,12 +141,6 @@ class SubmitterMailer < ApplicationMailer reply_to end - def build_completed_subject(submitter) - submitters = submitter.submission.submitters.order(:completed_at) - .map { |e| e.name || e.email || e.phone }.join(', ') - %(#{submitter.submission.template.name} has been completed by #{submitters}) - end - def add_completed_email_attachments!(submitter, with_audit_log: true, with_documents: true) documents = with_documents ? Submitters.select_attachments_for_download(submitter) : [] diff --git a/app/models/account_config.rb b/app/models/account_config.rb index 303f61c4..ce980f86 100644 --- a/app/models/account_config.rb +++ b/app/models/account_config.rb @@ -43,29 +43,23 @@ class AccountConfig < ApplicationRecord COMBINE_PDF_RESULT_KEY = 'combine_pdf_result_key' DEFAULT_VALUES = { - SUBMITTER_INVITATION_EMAIL_KEY => { - 'subject' => 'You are invited to submit a form', - 'body' => "Hi there,\n\n" \ - "You have been invited to submit the \"{{template.name}}\" form.\n\n" \ - "{{submitter.link}}\n\n" \ - "Please contact us by replying to this email if you didn't request this.\n\n" \ - "Thanks,\n" \ - '{{account.name}}' + SUBMITTER_INVITATION_EMAIL_KEY => lambda { + { + 'subject' => I18n.t(:you_are_invited_to_sign_a_document), + 'body' => I18n.t(:submitter_invitation_email_sign_body) + } }, - SUBMITTER_COMPLETED_EMAIL_KEY => { - 'subject' => '{{template.name}} has been completed by {{submission.submitters}}', - 'body' => "Hi,\n\n" \ - "\"{{template.name}}\" form has been completed by {{submission.submitters}}\n\n" \ - '{{submission.link}}' + SUBMITTER_COMPLETED_EMAIL_KEY => lambda { + { + 'subject' => I18n.t(:template_name_has_been_completed_by_submitters), + 'body' => I18n.t(:submitter_completed_email_body) + } }, - SUBMITTER_DOCUMENTS_COPY_EMAIL_KEY => { - 'subject' => 'Your document copy', - 'body' => "Hi there,\n\n" \ - "Please check the copy of your \"{{template.name}}\" submission in the email attachments.\n" \ - "Alternatively, you can download your copy using:\n\n" \ - "{{documents.link}}\n\n" \ - "Thanks,\n" \ - '{{account.name}}' + SUBMITTER_DOCUMENTS_COPY_EMAIL_KEY => lambda { + { + 'subject' => I18n.t(:your_document_copy), + 'body' => I18n.t(:submitter_documents_copy_email_body) + } } }.freeze diff --git a/app/views/personalization_settings/_documents_copy_email_form.html.erb b/app/views/personalization_settings/_documents_copy_email_form.html.erb index 582743d0..03310057 100644 --- a/app/views/personalization_settings/_documents_copy_email_form.html.erb +++ b/app/views/personalization_settings/_documents_copy_email_form.html.erb @@ -16,7 +16,7 @@
<%= ff.label :body, t('body'), class: 'label' %> - + <%= svg_icon('info_circle', class: 'w-4 h-4') %>
diff --git a/app/views/personalization_settings/_signature_request_email_form.html.erb b/app/views/personalization_settings/_signature_request_email_form.html.erb index 7adde933..ea529dfe 100644 --- a/app/views/personalization_settings/_signature_request_email_form.html.erb +++ b/app/views/personalization_settings/_signature_request_email_form.html.erb @@ -16,7 +16,7 @@
<%= ff.label :body, t('body'), class: 'label' %> - + <%= svg_icon('info_circle', class: 'w-4 h-4') %>
diff --git a/app/views/personalization_settings/_submitter_completed_email_form.html.erb b/app/views/personalization_settings/_submitter_completed_email_form.html.erb index 79e118a1..119c701e 100644 --- a/app/views/personalization_settings/_submitter_completed_email_form.html.erb +++ b/app/views/personalization_settings/_submitter_completed_email_form.html.erb @@ -12,7 +12,7 @@
<%= ff.label :subject, t('subject'), class: 'label' %> - + <%= svg_icon('info_circle', class: 'w-4 h-4') %>
@@ -21,7 +21,7 @@
<%= ff.label :body, t('body'), class: 'label' %> - + <%= svg_icon('info_circle', class: 'w-4 h-4') %>
diff --git a/app/views/submissions/_send_email.html.erb b/app/views/submissions/_send_email.html.erb index cd159201..4e37f149 100644 --- a/app/views/submissions/_send_email.html.erb +++ b/app/views/submissions/_send_email.html.erb @@ -42,7 +42,7 @@
<%= f.label :message, t('body'), class: 'label' %> - + <%= svg_icon('info_circle', class: 'w-4 h-4') %>
diff --git a/app/views/submitter_mailer/completed_email.html.erb b/app/views/submitter_mailer/completed_email.html.erb index aa4d0085..70792c86 100644 --- a/app/views/submitter_mailer/completed_email.html.erb +++ b/app/views/submitter_mailer/completed_email.html.erb @@ -1,7 +1,7 @@ <% if @body.present? %> <%= render 'custom_content', content: @body, submitter: @submitter %> <% else %> -

Hi there,

-

"<%= @submitter.submission.template.name %>" form has been completed by <%= @submitter.submission.submitters.order(:completed_at).map { |e| e.name || e.email || e.phone }.join(', ') %>.

-

<%= link_to 'View Submission', submission_url(@submitter.submission) %>

+

<%= t('hi_there') %>,

+

<%= I18n.t(:name_has_been_completed_by_submitters, name: @submitter.submission.template.name, submitters: @submitter.submission.submitters.order(:completed_at).map { |e| e.name || e.email || e.phone }.join(', ')) %>

+

<%= link_to submission_url(@submitter.submission), submission_url(@submitter.submission) %>

<% end %> diff --git a/app/views/submitter_mailer/declined_email.html.erb b/app/views/submitter_mailer/declined_email.html.erb index 24d6f919..0e6ce535 100644 --- a/app/views/submitter_mailer/declined_email.html.erb +++ b/app/views/submitter_mailer/declined_email.html.erb @@ -1,4 +1,4 @@

<%= t('hi_there') %>,

<%= t('name_declined_by_submitter_with_the_following_reason', name: @submitter.submission.template.name, submitter: @submitter.name || @submitter.email || @submitter.phone) %>

<%= simple_format(h(@submitter.submission_events.find_by(event_type: :decline_form).data['reason'])) %> -

<%= link_to t('view'), submission_url(@submitter.submission) %>

+

<%= link_to submission_url(@submitter.submission), submission_url(@submitter.submission) %>

diff --git a/app/views/submitter_mailer/documents_copy_email.html.erb b/app/views/submitter_mailer/documents_copy_email.html.erb index 5c776c70..0312a0bc 100644 --- a/app/views/submitter_mailer/documents_copy_email.html.erb +++ b/app/views/submitter_mailer/documents_copy_email.html.erb @@ -1,13 +1,13 @@ <% 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.

-

Alternatively, you can review and download your copy using:

+

<%= t('hi_there') %>,

+

<%= t('please_check_the_copy_of_your_name_in_the_email_attachments', name: @submitter.submission.template.name) %> +

<%= t('alternatively_you_can_review_and_download_your_copy_using_the_link_below') %>

<%= link_to @submitter.template.name, submissions_preview_url(@submitter.submission.slug, { sig: @sig }.compact) %>

- Thanks,
<%= @current_account.name %> + <%= t('thanks') %>,
<%= @current_account.name %>

<% end %> diff --git a/app/views/submitter_mailer/invitation_email.html.erb b/app/views/submitter_mailer/invitation_email.html.erb index 5dfaad26..d5987306 100644 --- a/app/views/submitter_mailer/invitation_email.html.erb +++ b/app/views/submitter_mailer/invitation_email.html.erb @@ -5,11 +5,11 @@

<%= link_to nil, submit_form_url(slug: @submitter.slug, t: SubmissionEvents.build_tracking_param(@submitter, 'click_email')) %>

<% end %> <% else %> -

Hi there,

-

You have been invited to submit the "<%= @submitter.submission.template.name %>" form.

-

<%= link_to 'Submit Form', submit_form_url(slug: @submitter.slug, t: SubmissionEvents.build_tracking_param(@submitter, 'click_email')) %>

-

Please contact us by replying to this email if you didn't request this.

+

<%= t('hi_there') %>,

+

<%= I18n.t(@submitter.with_signature_fields? ? :you_have_been_invited_to_sign_the_name : :you_have_been_invited_to_submit_the_name_form, name: @submitter.submission.template.name) %>

+

<%= link_to I18n.t(@submitter.with_signature_fields? ? :review_and_sign : :review_and_submit), submit_form_url(slug: @submitter.slug, t: SubmissionEvents.build_tracking_param(@submitter, 'click_email')) %>

+

<%= t('please_contact_us_by_replying_to_this_email_if_you_didn_t_request_this') %>

- Thanks,
<%= @current_account.name %> + <%= t('thanks') %>,
<%= @current_account.name %>

<% end %> diff --git a/app/views/templates_preferences/show.html.erb b/app/views/templates_preferences/show.html.erb index 4d2f7453..55fb51fe 100644 --- a/app/views/templates_preferences/show.html.erb +++ b/app/views/templates_preferences/show.html.erb @@ -90,7 +90,7 @@
<%= ff.label :request_email_body, t('email_body'), class: 'label' %> - + <%= svg_icon('info_circle', class: 'w-4 h-4') %>
@@ -125,7 +125,7 @@
<%= ff.label :documents_copy_email_body, t('email_body'), class: 'label' %> - + <%= svg_icon('info_circle', class: 'w-4 h-4') %>
@@ -172,7 +172,7 @@
<%= ff.label :completed_notification_email_body, t('email_body'), class: 'label' %> - + <%= svg_icon('info_circle', class: 'w-4 h-4') %>
diff --git a/config/locales/en.yml b/config/locales/en.yml index 6c657fe6..51dce550 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -18,6 +18,50 @@ en: &en language_nl: Nederlands language_ar: العربية language_ko: 한국어 + hi_there: Hi there + thanks: Thanks + you_have_been_invited_to_submit_the_name_form: 'You have been invited to submit the "%{name}" form.' + you_have_been_invited_to_sign_the_name: 'You have been invited to sign the "%{name}".' + alternatively_you_can_review_and_download_your_copy_using_the_link_below: "Alternatively, you can review and download your copy using the link below:" + please_check_the_copy_of_your_name_in_the_email_attachments: 'Please check the copy of your "%{name}" in the email attachments.' + review_and_sign: Review and Sign + review_and_submit: Review and Submit + please_contact_us_by_replying_to_this_email_if_you_didn_t_request_this: "Please contact us by replying to this email if you didn't request this." + submitter_invitation_sms_body_sign: '{account.name} has invited you to sign a document: {submitter.link}' + verification_code_sms_body: 'Verification code: {code}' + you_are_invited_to_submit_a_form: 'You are invited to submit a form' + you_are_invited_to_sign_a_document: 'You are invited to sign a document' + you_are_invited_to_sign_documents: 'You are invited to sign documents' + your_document_copy: 'Your document copy' + name_has_been_completed_by_submitters: '%{name} has been completed by %{submitters}.' + template_name_has_been_completed_by_submitters: '{template.name} has been completed by {submission.submitters}' + submitter_invitation_email_sign_body: | + Hi there, + + You have been invited to sign the "{template.name}". + + [Review and Sign]({submitter.link}) + + Please contact us by replying to this email if you didn't request this. + + Thanks, + {account.name} + submitter_completed_email_body: | + Hi, + + "{template.name}" has been completed by {submission.submitters} + + {submission.link} + submitter_documents_copy_email_body: | + Hi there, + + Please check the copy of your "{template.name}" in the email attachments. + Alternatively, you can review and download your copy using the link below: + + [{template.name}]({documents.link}) + + Thanks, + {account.name} view: View hi_there: Hi there email: Email @@ -323,7 +367,7 @@ en: &en draw_signature: Draw Signature clear: Clear signature_uploaded: Signature Uploaded - submission_deletion_is_irreversible_and_will_permanently_remove_all_associated_signed_documents_with_it_are_you_sure_: + submission_deletion_is_irreversible_and_will_permanently_remove_all_associated_signed_documents_with_it_are_you_sure_: 'Submission deletion is irreversible and will permanently remove all associated signed documents with it. Are you sure?' return_back_to_your_desktop_device_to_complete_the_form_or_continue_on_mobile_html: 'Return back to your desktop device to complete the form or continue on mobile' template_deletion_is_irreversible_and_will_permanently_remove_all_associated_signed_documents_with_it_are_you_sure_: Template deletion is irreversible and will permanently remove all associated signed documents with it. Are you sure? rename_folder: Rename Folder diff --git a/lib/account_configs.rb b/lib/account_configs.rb index af153926..5f884657 100644 --- a/lib/account_configs.rb +++ b/lib/account_configs.rb @@ -18,7 +18,7 @@ module AccountConfigs def find_or_initialize_for_key(account, key) find_for_account(account, key) || - account.account_configs.new(key:, value: AccountConfig::DEFAULT_VALUES[key]) + account.account_configs.new(key:, value: AccountConfig::DEFAULT_VALUES[key]&.call) end def find_for_account(account, key)