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

@@ -0,0 +1,29 @@
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
[
{
'field_type': 'standard', 'label': 'Email Id', 'name': 'emailAddress', 'type': 'email', 'required': true, 'enabled': email_enabled
},
{
'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
end