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

Fixes: #2744
This commit is contained in:
Muhsin Keloth
2022-03-14 15:06:56 +05:30
committed by GitHub
parent 578414d788
commit e730804b48
16 changed files with 328 additions and 137 deletions

View File

@@ -0,0 +1,28 @@
class AddCustomFieldsToPreChatForm < ActiveRecord::Migration[6.1]
def change
Channel::WebWidget.find_in_batches do |channels_batch|
channels_batch.each do |channel|
pre_chat_message = channel[:pre_chat_form_options]['pre_chat_message'] || 'Share your queries or comments here.'
pre_chat_fields = pre_chat_fields?(channel)
channel[:pre_chat_form_options] = {
'pre_chat_message': pre_chat_message,
'pre_chat_fields': pre_chat_fields
}
channel.save!
end
end
end
def pre_chat_fields?(channel)
email_enabled = channel[:pre_chat_form_options]['require_email'] || false
[
{
'label': 'Email Id', 'name': 'emailAddress', 'type': 'email', 'required': true, 'enabled': email_enabled
}, {
'label': 'Full name', 'name': 'fullName', 'type': 'text', 'required': true, 'enabled': email_enabled
}, {
'label': 'Phone number', 'name': 'phoneNumber', 'type': 'number', 'required': true, 'enabled': false
}
]
end
end

View File

@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2022_02_18_120357) do
ActiveRecord::Schema.define(version: 2022_03_09_103742) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_stat_statements"