diff --git a/app/controllers/account_configs_controller.rb b/app/controllers/account_configs_controller.rb index 1732423c..3bc36334 100644 --- a/app/controllers/account_configs_controller.rb +++ b/app/controllers/account_configs_controller.rb @@ -8,7 +8,8 @@ class AccountConfigsController < ApplicationController AccountConfig::ALLOW_TYPED_SIGNATURE, AccountConfig::FORCE_MFA, AccountConfig::ALLOW_TO_RESUBMIT, - AccountConfig::ESIGNING_PREFERENCE_KEY + AccountConfig::ESIGNING_PREFERENCE_KEY, + AccountConfig::FORM_WITH_CONFETTI_KEY ].freeze InvalidKey = Class.new(StandardError) diff --git a/app/controllers/personalization_settings_controller.rb b/app/controllers/personalization_settings_controller.rb index 1d147a5e..76716fbd 100644 --- a/app/controllers/personalization_settings_controller.rb +++ b/app/controllers/personalization_settings_controller.rb @@ -17,7 +17,11 @@ class PersonalizationSettingsController < ApplicationController end def create - @account_config.save! + if @account_config.value != false && @account_config.value.blank? + @account_config.destroy! + else + @account_config.save! + end redirect_back(fallback_location: settings_personalization_path, notice: 'Settings have been saved.') end @@ -40,6 +44,8 @@ class PersonalizationSettingsController < ApplicationController def account_config_params attrs = params.require(:account_config).permit! + return attrs if attrs[:value].is_a?(String) + attrs[:value]&.transform_values! do |value| if value.in?(%w[true false]) value == 'true' diff --git a/app/views/personalization_settings/_form_customization_settings.html.erb b/app/views/personalization_settings/_form_customization_settings.html.erb new file mode 100644 index 00000000..7faa402a --- /dev/null +++ b/app/views/personalization_settings/_form_customization_settings.html.erb @@ -0,0 +1 @@ +<%= render 'form_toggle_options' %> diff --git a/app/views/personalization_settings/_form_toggle_options.html.erb b/app/views/personalization_settings/_form_toggle_options.html.erb new file mode 100644 index 00000000..a83d4b3f --- /dev/null +++ b/app/views/personalization_settings/_form_toggle_options.html.erb @@ -0,0 +1,14 @@ +<% account_config = AccountConfig.where(account: current_account, key: AccountConfig::FORM_WITH_CONFETTI_KEY).first_or_initialize(value: true) %> +<% if can?(:manage, account_config) %> +
Company Logo
<%= render 'logo_form' %> -Submitter Form
+Submission Form
<%= render 'form_completed_button_form' %> + <%= render 'form_customization_settings' %> diff --git a/lib/submitters/form_configs.rb b/lib/submitters/form_configs.rb index 95a85378..779d09d1 100644 --- a/lib/submitters/form_configs.rb +++ b/lib/submitters/form_configs.rb @@ -2,20 +2,27 @@ module Submitters module FormConfigs + DEFAULT_KEYS = [AccountConfig::FORM_COMPLETED_BUTTON_KEY, + AccountConfig::FORM_WITH_CONFETTI_KEY, + AccountConfig::ALLOW_TYPED_SIGNATURE].freeze + module_function - def call(submitter) + def call(submitter, keys = []) configs = submitter.submission.template.account.account_configs - .where(key: [AccountConfig::FORM_COMPLETED_BUTTON_KEY, - AccountConfig::FORM_WITH_CONFETTI_KEY, - AccountConfig::ALLOW_TYPED_SIGNATURE]) + .where(key: DEFAULT_KEYS + keys) completed_button = configs.find { |e| e.key == AccountConfig::FORM_COMPLETED_BUTTON_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 - { completed_button:, with_typed_signature:, with_confetti: } + attrs = { completed_button:, with_typed_signature:, with_confetti: } + + keys.each do |key| + attrs[key.to_sym] = configs.find { |e| e.key == key.to_s }&.value + end + + attrs end end end