allow to edit email templates
This commit is contained in:
@@ -18,6 +18,7 @@ class SubmitterMailer < ApplicationMailer
|
||||
end
|
||||
|
||||
mail(to: @submitter.email,
|
||||
from: from_address_for_submitter(submitter),
|
||||
subject:,
|
||||
reply_to: submitter.submission.created_by_user&.friendly_name)
|
||||
end
|
||||
@@ -27,8 +28,18 @@ class SubmitterMailer < ApplicationMailer
|
||||
@submitter = submitter
|
||||
@user = user
|
||||
|
||||
mail(to: user.email,
|
||||
subject: %(#{submitter.email} has completed the "#{submitter.submission.template.name}" form))
|
||||
@email_config = @current_account.account_configs.find_by(key: AccountConfig::SUBMITTER_COMPLETED_EMAIL_KEY)
|
||||
|
||||
subject =
|
||||
if @email_config
|
||||
ReplaceEmailVariables.call(@email_config.value['subject'], submitter:)
|
||||
else
|
||||
%(#{submitter.email} has completed the "#{submitter.submission.template.name}" form)
|
||||
end
|
||||
|
||||
mail(from: from_address_for_submitter(submitter),
|
||||
to: user.email,
|
||||
subject:)
|
||||
end
|
||||
|
||||
def documents_copy_email(submitter)
|
||||
@@ -43,6 +54,23 @@ class SubmitterMailer < ApplicationMailer
|
||||
attachments[attachment.filename.to_s] = attachment.download
|
||||
end
|
||||
|
||||
mail(to: submitter.email, subject: 'Your copy of documents')
|
||||
@email_config = @current_account.account_configs.find_by(key: AccountConfig::SUBMITTER_DOCUMENTS_COPY_EMAIL_KEY)
|
||||
|
||||
subject =
|
||||
if @email_config
|
||||
ReplaceEmailVariables.call(@email_config.value['subject'], submitter:)
|
||||
else
|
||||
'Your copy of documents'
|
||||
end
|
||||
|
||||
mail(from: from_address_for_submitter(submitter),
|
||||
to: submitter.email,
|
||||
subject:)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def from_address_for_submitter(submitter)
|
||||
submitter.submission.created_by_user&.friendly_name || submitter.submission.template.author.friendly_name
|
||||
end
|
||||
end
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
#
|
||||
class AccountConfig < ApplicationRecord
|
||||
SUBMITTER_INVITATION_EMAIL_KEY = 'submitter_invitation_email'
|
||||
SUBMITTER_COMPLETED_EMAIL_KEY = 'submitter_completed_email'
|
||||
SUBMITTER_DOCUMENTS_COPY_EMAIL_KEY = 'submitter_documents_copy_email'
|
||||
|
||||
DEFAULT_VALUES = {
|
||||
SUBMITTER_INVITATION_EMAIL_KEY => {
|
||||
@@ -32,6 +34,23 @@ class AccountConfig < ApplicationRecord
|
||||
"Please contact us by replying to this email if you didn't request this.\n\n" \
|
||||
"Thanks,\n" \
|
||||
'{{account.name}}'
|
||||
},
|
||||
SUBMITTER_COMPLETED_EMAIL_KEY => {
|
||||
'subject' => '{{submitter.email}} has completed the "{{template.name}}" form',
|
||||
'body' => "Hi,\n\n" \
|
||||
"{{submitter.email}} has completed the \"{{template.name}}\" form:\n\n" \
|
||||
"{{submission.link}}\n\n" \
|
||||
"Thanks,\n" \
|
||||
'{{account.name}}'
|
||||
},
|
||||
SUBMITTER_DOCUMENTS_COPY_EMAIL_KEY => {
|
||||
'subject' => 'Your copy of documents',
|
||||
'body' => "Hi there,\n\n" \
|
||||
"Please check the copy of your \"{{template.name}}\" submission in the email attachments.\n" \
|
||||
"Alternatively, you can download the copy using:\n\n" \
|
||||
"{{documents.links}}\n\n" \
|
||||
"Thanks,\n" \
|
||||
'{{account.name}}'
|
||||
}
|
||||
}.freeze
|
||||
|
||||
|
||||
@@ -1,25 +1,91 @@
|
||||
<div class="flex flex-wrap space-y-4 md:flex-nowrap md:space-y-0">
|
||||
<%= render 'shared/settings_nav' %>
|
||||
<div class="flex-grow max-w-xl mx-auto">
|
||||
<p class="text-4xl font-bold mb-4">Signature Request Email</p>
|
||||
<%= form_for AccountConfigs.find_or_initialize_for_key(current_account, AccountConfig::SUBMITTER_INVITATION_EMAIL_KEY), url: settings_personalization_path, method: :post, html: { autocomplete: 'off', class: 'space-y-4' } do |f| %>
|
||||
<%= f.hidden_field :key %>
|
||||
<%= f.fields_for :value, Struct.new(:subject, :body).new(*f.object.value.values_at('subject', 'body')) do |ff| %>
|
||||
<div class="form-control">
|
||||
<%= ff.label :subject, class: 'label' %>
|
||||
<%= ff.text_field :subject, required: true, class: 'base-input' %>
|
||||
<p class="text-4xl font-bold mb-4">Email Templates</p>
|
||||
<div class="collapse collapse-plus bg-base-200 px-1">
|
||||
<input type="checkbox">
|
||||
<div class="collapse-title text-xl font-medium">
|
||||
<div>
|
||||
Signature Request Email
|
||||
</div>
|
||||
<div class="form-control">
|
||||
<%= ff.label :body, class: 'label' %>
|
||||
<autoresize-textarea>
|
||||
<%= ff.text_area :body, required: true, class: 'base-input w-full py-2' %>
|
||||
</autoresize-textarea>
|
||||
</div>
|
||||
<% end %>
|
||||
<div class="form-control pt-2">
|
||||
<%= f.button button_title(title: 'Save', disabled_with: 'Saving'), class: 'base-button' %>
|
||||
</div>
|
||||
<% end %>
|
||||
<div class="collapse-content">
|
||||
<%= form_for AccountConfigs.find_or_initialize_for_key(current_account, AccountConfig::SUBMITTER_INVITATION_EMAIL_KEY), url: settings_personalization_path, method: :post, html: { autocomplete: 'off', class: 'space-y-4' } do |f| %>
|
||||
<%= f.hidden_field :key %>
|
||||
<%= f.fields_for :value, Struct.new(:subject, :body).new(*f.object.value.values_at('subject', 'body')) do |ff| %>
|
||||
<div class="form-control">
|
||||
<%= ff.label :subject, class: 'label' %>
|
||||
<%= ff.text_field :subject, required: true, class: 'base-input' %>
|
||||
</div>
|
||||
<div class="form-control">
|
||||
<%= ff.label :body, class: 'label' %>
|
||||
<autoresize-textarea>
|
||||
<%= ff.text_area :body, required: true, class: 'base-input w-full py-2' %>
|
||||
</autoresize-textarea>
|
||||
</div>
|
||||
<% end %>
|
||||
<div class="form-control pt-2">
|
||||
<%= f.button button_title(title: 'Save', disabled_with: 'Saving'), class: 'base-button' %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
<div class="collapse collapse-plus bg-base-200 px-1 mt-4">
|
||||
<input type="checkbox">
|
||||
<div class="collapse-title text-xl font-medium">
|
||||
<div>
|
||||
Form Completed Email
|
||||
</div>
|
||||
</div>
|
||||
<div class="collapse-content">
|
||||
<%= form_for AccountConfigs.find_or_initialize_for_key(current_account, AccountConfig::SUBMITTER_COMPLETED_EMAIL_KEY), url: settings_personalization_path, method: :post, html: { autocomplete: 'off', class: 'space-y-4' } do |f| %>
|
||||
<%= f.hidden_field :key %>
|
||||
<%= f.fields_for :value, Struct.new(:subject, :body).new(*f.object.value.values_at('subject', 'body')) do |ff| %>
|
||||
<div class="form-control">
|
||||
<%= ff.label :subject, class: 'label' %>
|
||||
<%= ff.text_field :subject, required: true, class: 'base-input' %>
|
||||
</div>
|
||||
<div class="form-control">
|
||||
<%= ff.label :body, class: 'label' %>
|
||||
<autoresize-textarea>
|
||||
<%= ff.text_area :body, required: true, class: 'base-input w-full py-2' %>
|
||||
</autoresize-textarea>
|
||||
</div>
|
||||
<% end %>
|
||||
<div class="form-control pt-2">
|
||||
<%= f.button button_title(title: 'Save', disabled_with: 'Saving'), class: 'base-button' %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
<div class="collapse collapse-plus bg-base-200 px-1 mt-4">
|
||||
<input type="checkbox">
|
||||
<div class="collapse-title text-xl font-medium">
|
||||
<div>
|
||||
Documents Copy Email
|
||||
</div>
|
||||
</div>
|
||||
<div class="collapse-content">
|
||||
<%= form_for AccountConfigs.find_or_initialize_for_key(current_account, AccountConfig::SUBMITTER_DOCUMENTS_COPY_EMAIL_KEY), url: settings_personalization_path, method: :post, html: { autocomplete: 'off', class: 'space-y-4' } do |f| %>
|
||||
<%= f.hidden_field :key %>
|
||||
<%= f.fields_for :value, Struct.new(:subject, :body).new(*f.object.value.values_at('subject', 'body')) do |ff| %>
|
||||
<div class="form-control">
|
||||
<%= ff.label :subject, class: 'label' %>
|
||||
<%= ff.text_field :subject, required: true, class: 'base-input' %>
|
||||
</div>
|
||||
<div class="form-control">
|
||||
<%= ff.label :body, class: 'label' %>
|
||||
<autoresize-textarea>
|
||||
<%= ff.text_area :body, required: true, class: 'base-input w-full py-2' %>
|
||||
</autoresize-textarea>
|
||||
</div>
|
||||
<% end %>
|
||||
<div class="form-control pt-2">
|
||||
<%= f.button button_title(title: 'Save', disabled_with: 'Saving'), class: 'base-button' %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
<p class="text-4xl font-bold mb-4 mt-8">Company Logo</p>
|
||||
<%= render 'logo_form' %>
|
||||
</div>
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
<p>Hi <%= @user.first_name %>,</p>
|
||||
<p><%= @submitter.email %> has completed the "<%= @submitter.submission.template.name %>" form.</p>
|
||||
<p><%= link_to 'View Submission', submission_url(@submitter.submission) %></p>
|
||||
<% if @email_config %>
|
||||
<%= auto_link(simple_format(h(ReplaceEmailVariables.call(@email_config.value['body'], submitter: @submitter)))) %>
|
||||
<% else %>
|
||||
<p>Hi <%= @user.first_name %>,</p>
|
||||
<p><%= @submitter.email %> has completed the "<%= @submitter.submission.template.name %>" form.</p>
|
||||
<p><%= link_to 'View Submission', submission_url(@submitter.submission) %></p>
|
||||
<% end %>
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
<p>Hi there,</p>
|
||||
<p>Please check the copy of your "<%= @submitter.submission.template.name %>" submission in the email attachments.</p>
|
||||
<p>Alternatively, you can download the copy using:</p>
|
||||
<% @documents.each do |document| %>
|
||||
<ul>
|
||||
<li>
|
||||
<%= link_to document.filename.to_s, rails_blob_url(document) %>
|
||||
</li>
|
||||
</ul>
|
||||
<% if @email_config %>
|
||||
<%= auto_link(simple_format(h(ReplaceEmailVariables.call(@email_config.value['body'], submitter: @submitter)))) %>
|
||||
<% else %>
|
||||
<p>Hi there,</p>
|
||||
<p>Please check the copy of your "<%= @submitter.submission.template.name %>" submission in the email attachments.</p>
|
||||
<p>Alternatively, you can download the copy using:</p>
|
||||
<% @documents.each do |document| %>
|
||||
<ul>
|
||||
<li>
|
||||
<%= link_to document.filename.to_s, rails_blob_url(document) %>
|
||||
</li>
|
||||
</ul>
|
||||
<% end %>
|
||||
<p>
|
||||
Thanks,<br><%= @current_account.name %>
|
||||
</p>
|
||||
<% end %>
|
||||
<p>
|
||||
Thanks,<br><%= @current_account.name %>
|
||||
</p>
|
||||
|
||||
@@ -4,18 +4,40 @@ module ReplaceEmailVariables
|
||||
TEMAPLTE_NAME = '{{template.name}}'
|
||||
SUBMITTER_LINK = '{{submitter.link}}'
|
||||
ACCOUNT_NAME = '{{account.name}}'
|
||||
SUBMITTER_EMAIL = '{{submitter.email}}'
|
||||
SUBMISSION_LINK = '{{submission.link}}'
|
||||
DOCUMENTS_LINKS = '{{documents.links}}'
|
||||
|
||||
module_function
|
||||
|
||||
def call(text, submitter:)
|
||||
link =
|
||||
submitter_link =
|
||||
Rails.application.routes.url_helpers.submit_form_url(
|
||||
slug: submitter.slug, **Docuseal.default_url_options
|
||||
)
|
||||
|
||||
submission_link =
|
||||
Rails.application.routes.url_helpers.submission_url(
|
||||
submitter.submission, **Docuseal.default_url_options
|
||||
)
|
||||
|
||||
text = text.gsub(TEMAPLTE_NAME, submitter.template.name)
|
||||
text = text.gsub(SUBMITTER_LINK, link)
|
||||
text = text.gsub(SUBMITTER_EMAIL, submitter.email)
|
||||
text = text.gsub(SUBMITTER_LINK, submitter_link)
|
||||
text = text.gsub(SUBMISSION_LINK, submission_link)
|
||||
text = text.gsub(DOCUMENTS_LINKS, build_documents_links_text(submitter))
|
||||
|
||||
text.gsub(ACCOUNT_NAME, submitter.template.account.name)
|
||||
end
|
||||
|
||||
def build_documents_links_text(submitter)
|
||||
submitter.documents.map do |document|
|
||||
link =
|
||||
Rails.application.routes.url_helpers.rails_blob_url(
|
||||
document, **Docuseal.default_url_options
|
||||
)
|
||||
|
||||
"#{link}\n"
|
||||
end.join
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user