From 753cbd4d2783932a651a4e2da25cbede87b76f88 Mon Sep 17 00:00:00 2001 From: Pete Matsyburka Date: Fri, 5 Apr 2024 16:16:30 +0300 Subject: [PATCH] allow to add custom form completed message --- .../personalization_settings_controller.rb | 3 +- app/javascript/form.js | 3 +- app/javascript/submission_form/completed.vue | 21 ++++++++++++-- app/javascript/submission_form/form.vue | 6 ++++ app/models/account_config.rb | 1 + .../_form_completed_message_form.html.erb | 28 +++++++++++++++++++ .../personalization_settings/show.html.erb | 5 +++- .../submit_form/_submission_form.html.erb | 2 +- lib/submitters/form_configs.rb | 4 ++- 9 files changed, 65 insertions(+), 8 deletions(-) create mode 100644 app/views/personalization_settings/_form_completed_message_form.html.erb diff --git a/app/controllers/personalization_settings_controller.rb b/app/controllers/personalization_settings_controller.rb index 76716fbd..9b747c88 100644 --- a/app/controllers/personalization_settings_controller.rb +++ b/app/controllers/personalization_settings_controller.rb @@ -5,7 +5,8 @@ class PersonalizationSettingsController < ApplicationController AccountConfig::FORM_COMPLETED_BUTTON_KEY, AccountConfig::SUBMITTER_INVITATION_EMAIL_KEY, AccountConfig::SUBMITTER_DOCUMENTS_COPY_EMAIL_KEY, - AccountConfig::SUBMITTER_COMPLETED_EMAIL_KEY + AccountConfig::SUBMITTER_COMPLETED_EMAIL_KEY, + AccountConfig::FORM_COMPLETED_MESSAGE_KEY ].freeze InvalidKey = Class.new(StandardError) diff --git a/app/javascript/form.js b/app/javascript/form.js index ca899374..6647188e 100644 --- a/app/javascript/form.js +++ b/app/javascript/form.js @@ -19,7 +19,8 @@ window.customElements.define('submission-form', class extends HTMLElement { withTypedSignature: this.dataset.withTypedSignature !== 'false', authenticityToken: document.querySelector('meta[name="csrf-token"]')?.content, values: reactive(JSON.parse(this.dataset.values)), - completedButton: JSON.parse(this.dataset.completedButton), + completedButton: JSON.parse(this.dataset.completedButton || '{}'), + completedMessage: JSON.parse(this.dataset.completedMessage || '{}'), completedRedirectUrl: this.dataset.completedRedirectUrl, attachments: reactive(JSON.parse(this.dataset.attachments)), fields: JSON.parse(this.dataset.fields) diff --git a/app/javascript/submission_form/completed.vue b/app/javascript/submission_form/completed.vue index 4bb4ea54..c863f3e9 100644 --- a/app/javascript/submission_form/completed.vue +++ b/app/javascript/submission_form/completed.vue @@ -3,16 +3,24 @@ class="mx-auto max-w-md flex flex-col" dir="auto" > -

+

- {{ t('form_has_been_completed') }} + {{ completedMessage.title || t('form_has_been_completed') }} -

+
+
+ +
import { IconCircleCheck, IconBrandGithub, IconMail, IconDownload, IconInnerShadowTop, IconLogin } from '@tabler/icons-vue' +import MarkdownContent from './markdown_content' export default { name: 'FormCompleted', components: { + MarkdownContent, IconCircleCheck, IconInnerShadowTop, IconBrandGithub, @@ -143,6 +153,11 @@ export default { type: Object, required: false, default: () => ({}) + }, + completedMessage: { + type: Object, + required: false, + default: () => ({}) } }, data () { diff --git a/app/javascript/submission_form/form.vue b/app/javascript/submission_form/form.vue index 0ae8622a..e19aa731 100644 --- a/app/javascript/submission_form/form.vue +++ b/app/javascript/submission_form/form.vue @@ -418,6 +418,7 @@ :is-demo="isDemo" :attribution="attribution" :completed-button="completedRedirectUrl ? {} : completedButton" + :completed-message="completedRedirectUrl ? {} : completedMessage" :with-send-copy-button="withSendCopyButton && !completedRedirectUrl" :with-download-button="withDownloadButton && !completedRedirectUrl" :with-confetti="withConfetti" @@ -641,6 +642,11 @@ export default { type: Object, required: false, default: () => ({}) + }, + completedMessage: { + type: Object, + required: false, + default: () => ({}) } }, data () { diff --git a/app/models/account_config.rb b/app/models/account_config.rb index c0b3b24c..27b1058e 100644 --- a/app/models/account_config.rb +++ b/app/models/account_config.rb @@ -30,6 +30,7 @@ class AccountConfig < ApplicationRecord ALLOW_TO_RESUBMIT = 'allow_to_resubmit' SUBMITTER_REMAILERS = 'submitter_reminders' FORM_COMPLETED_BUTTON_KEY = 'form_completed_button' + FORM_COMPLETED_MESSAGE_KEY = 'form_completed_message' FORM_WITH_CONFETTI_KEY = 'form_with_confetti' ESIGNING_PREFERENCE_KEY = 'esigning_preference' diff --git a/app/views/personalization_settings/_form_completed_message_form.html.erb b/app/views/personalization_settings/_form_completed_message_form.html.erb new file mode 100644 index 00000000..b592a070 --- /dev/null +++ b/app/views/personalization_settings/_form_completed_message_form.html.erb @@ -0,0 +1,28 @@ +
+ +
+
+ Completed Form Message +
+
+
+ <%= form_for AccountConfigs.find_or_initialize_for_key(current_account, AccountConfig::FORM_COMPLETED_MESSAGE_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(:title, :body).new(*(f.object.value || {}).values_at('title', 'body')) do |ff| %> +
+ <%= ff.label :title, 'Title', class: 'label' %> + <%= ff.text_field :title, class: 'base-input', dir: 'auto' %> +
+
+ <%= ff.label :body, 'Body', class: 'label' %> + + <%= ff.text_area :body, class: 'base-input w-full py-2', dir: 'auto' %> + +
+ <% end %> +
+ <%= f.button button_title(title: 'Save', disabled_with: 'Saving'), class: 'base-button' %> +
+ <% end %> +
+
diff --git a/app/views/personalization_settings/show.html.erb b/app/views/personalization_settings/show.html.erb index 1f06f239..e0a9c224 100644 --- a/app/views/personalization_settings/show.html.erb +++ b/app/views/personalization_settings/show.html.erb @@ -10,7 +10,10 @@

Company Logo

<%= render 'logo_form' %>

Submission Form

- <%= render 'form_completed_button_form' %> +
+ <%= render 'form_completed_message_form' %> + <%= render 'form_completed_button_form' %> +
<%= render 'form_customization_settings' %>
diff --git a/app/views/submit_form/_submission_form.html.erb b/app/views/submit_form/_submission_form.html.erb index 9375b714..e998d9e0 100644 --- a/app/views/submit_form/_submission_form.html.erb +++ b/app/views/submit_form/_submission_form.html.erb @@ -1,4 +1,4 @@ <% data_attachments = attachments_index.values.select { |e| e.record_id == submitter.id }.to_json(only: %i[uuid], methods: %i[url filename content_type]) %> <% data_fields = (submitter.submission.template_fields || submitter.submission.template.fields).select { |f| f['submitter_uuid'] == submitter.uuid }.to_json %> <% configs = Submitters::FormConfigs.call(submitter) %> - + diff --git a/lib/submitters/form_configs.rb b/lib/submitters/form_configs.rb index ca054b41..42887917 100644 --- a/lib/submitters/form_configs.rb +++ b/lib/submitters/form_configs.rb @@ -3,6 +3,7 @@ module Submitters module FormConfigs DEFAULT_KEYS = [AccountConfig::FORM_COMPLETED_BUTTON_KEY, + AccountConfig::FORM_COMPLETED_MESSAGE_KEY, AccountConfig::FORM_WITH_CONFETTI_KEY, AccountConfig::ALLOW_TYPED_SIGNATURE].freeze @@ -13,10 +14,11 @@ module Submitters .where(key: DEFAULT_KEYS + keys) completed_button = configs.find { |e| e.key == AccountConfig::FORM_COMPLETED_BUTTON_KEY }&.value || {} + completed_message = configs.find { |e| e.key == AccountConfig::FORM_COMPLETED_MESSAGE_KEY }&.value || {} with_typed_signature = configs.find { |e| e.key == AccountConfig::ALLOW_TYPED_SIGNATURE }&.value != false with_confetti = configs.find { |e| e.key == AccountConfig::FORM_WITH_CONFETTI_KEY }&.value != false - attrs = { completed_button:, with_typed_signature:, with_confetti: } + attrs = { completed_button:, with_typed_signature:, with_confetti:, completed_message: } keys.each do |key| attrs[key.to_sym] = configs.find { |e| e.key == key.to_s }&.value