feat: Custom fields in pre-chat form (#4189)

This commit is contained in:
Muhsin Keloth
2022-04-19 12:47:29 +05:30
committed by GitHub
parent 1ccd29140d
commit 26f23a6e21
25 changed files with 824 additions and 160 deletions

View File

@@ -32,9 +32,13 @@ class Channel::WebWidget < ApplicationRecord
self.table_name = 'channel_web_widgets'
EDITABLE_ATTRS = [:website_url, :widget_color, :welcome_title, :welcome_tagline, :reply_time, :pre_chat_form_enabled,
:continuity_via_email, :hmac_mandatory,
{ pre_chat_form_options: [:pre_chat_message, :require_email] },
{ pre_chat_form_options: [:pre_chat_message, :require_email,
{ pre_chat_fields:
[:field_type, :label, :placeholder, :name, :enabled, :type, :enabled, :required,
:locale, { values: [] }] }] },
{ selected_feature_flags: [] }].freeze
before_validation :validate_pre_chat_options
validates :website_url, presence: true
validates :widget_color, presence: true
@@ -74,6 +78,25 @@ class Channel::WebWidget < ApplicationRecord
"
end
def validate_pre_chat_options
return if pre_chat_form_options.with_indifferent_access['pre_chat_fields'].present?
self.pre_chat_form_options = {
pre_chat_message: 'Share your queries or comments here.',
pre_chat_fields: [
{
'field_type': 'standard', 'label': 'Email Id', 'name': 'emailAddress', 'type': 'email', 'required': true, 'enabled': false
},
{
'field_type': 'standard', 'label': 'Full name', 'name': 'fullName', 'type': 'text', 'required': false, 'enabled': false
},
{
'field_type': 'standard', 'label': 'Phone number', 'name': 'phoneNumber', 'type': 'text', 'required': false, 'enabled': false
}
]
}
end
def create_contact_inbox(additional_attributes = {})
ActiveRecord::Base.transaction do
contact = inbox.account.contacts.create!(

View File

@@ -39,6 +39,6 @@ class CustomAttributeDefinition < ApplicationRecord
private
def sync_widget_pre_chat_custom_fields
::Inboxes::SyncWidgetPreChatCustomFieldsJob.perform_later(attribute_key)
::Inboxes::SyncWidgetPreChatCustomFieldsJob.perform_now(account, attribute_key)
end
end