mirror of https://github.com/docusealco/docuseal
				
				
				
			
			You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							36 lines
						
					
					
						
							1.3 KiB
						
					
					
				
			
		
		
	
	
							36 lines
						
					
					
						
							1.3 KiB
						
					
					
				| # frozen_string_literal: true
 | |
| 
 | |
| module Submitters
 | |
|   module FormConfigs
 | |
|     DEFAULT_KEYS = [AccountConfig::FORM_COMPLETED_BUTTON_KEY,
 | |
|                     AccountConfig::FORM_COMPLETED_MESSAGE_KEY,
 | |
|                     AccountConfig::FORM_WITH_CONFETTI_KEY,
 | |
|                     AccountConfig::FORM_PREFILL_SIGNATURE_KEY,
 | |
|                     AccountConfig::ALLOW_TYPED_SIGNATURE].freeze
 | |
| 
 | |
|     module_function
 | |
| 
 | |
|     def call(submitter, keys = [])
 | |
|       configs = submitter.submission.account.account_configs.where(key: DEFAULT_KEYS + keys)
 | |
| 
 | |
|       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
 | |
| 
 | |
|       attrs = { completed_button:, with_typed_signature:, with_confetti:, completed_message:, prefill_signature: }
 | |
| 
 | |
|       keys.each do |key|
 | |
|         attrs[key.to_sym] = configs.find { |e| e.key == key.to_s }&.value
 | |
|       end
 | |
| 
 | |
|       attrs
 | |
|     end
 | |
| 
 | |
|     def find_safe_value(configs, key)
 | |
|       configs.find { |e| e.key == key }&.value
 | |
|     end
 | |
|   end
 | |
| end
 |