Files
docuseal/lib/submitters/form_configs.rb
T

36 lines
1.3 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
module Submitters
module FormConfigs
2024-03-09 23:29:59 +02:00
DEFAULT_KEYS = [AccountConfig::FORM_COMPLETED_BUTTON_KEY,
2024-04-05 16:16:30 +03:00
AccountConfig::FORM_COMPLETED_MESSAGE_KEY,
2024-03-09 23:29:59 +02:00
AccountConfig::FORM_WITH_CONFETTI_KEY,
2024-06-15 15:55:09 +03:00
AccountConfig::FORM_PREFILL_SIGNATURE_KEY,
2024-03-09 23:29:59 +02:00
AccountConfig::ALLOW_TYPED_SIGNATURE].freeze
module_function
2024-03-09 23:29:59 +02:00
def call(submitter, keys = [])
2024-06-15 15:55:09 +03:00
configs = submitter.submission.account.account_configs.where(key: DEFAULT_KEYS + keys)
2024-06-15 15:55:09 +03:00
completed_button = find_safe_value(configs, AccountConfig::FORM_COMPLETED_BUTTON_KEY) || {}
completed_message = find_safe_value(configs, AccountConfig::FORM_COMPLETED_MESSAGE_KEY) || {}
with_typed_signature = find_safe_value(configs, AccountConfig::ALLOW_TYPED_SIGNATURE) != false
with_confetti = find_safe_value(configs, AccountConfig::FORM_WITH_CONFETTI_KEY) != false
prefill_signature = find_safe_value(configs, AccountConfig::FORM_PREFILL_SIGNATURE_KEY) != false
2024-06-15 15:55:09 +03:00
attrs = { completed_button:, with_typed_signature:, with_confetti:, completed_message:, prefill_signature: }
2024-03-09 23:29:59 +02:00
keys.each do |key|
attrs[key.to_sym] = configs.find { |e| e.key == key.to_s }&.value
end
attrs
end
2024-06-15 15:55:09 +03:00
def find_safe_value(configs, key)
configs.find { |e| e.key == key }&.value
end
end
end