chore: Sync pre-chat fields after custom attribute destroy (#4456)
This commit is contained in:
11
app/jobs/inboxes/sync_widget_pre_chat_custom_fields_job.rb
Normal file
11
app/jobs/inboxes/sync_widget_pre_chat_custom_fields_job.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
class Inboxes::SyncWidgetPreChatCustomFieldsJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
def perform(account, field_name)
|
||||
account.web_widgets.all.find_each do |web_widget|
|
||||
pre_chat_fields = web_widget.pre_chat_form_options['pre_chat_fields']
|
||||
web_widget.pre_chat_form_options['pre_chat_fields'] = pre_chat_fields.reject { |field| field['name'] == field_name }
|
||||
web_widget.save!
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -34,4 +34,11 @@ class CustomAttributeDefinition < ApplicationRecord
|
||||
enum attribute_display_type: { text: 0, number: 1, currency: 2, percent: 3, link: 4, date: 5, list: 6, checkbox: 7 }
|
||||
|
||||
belongs_to :account
|
||||
after_destroy :sync_widget_pre_chat_custom_fields
|
||||
|
||||
private
|
||||
|
||||
def sync_widget_pre_chat_custom_fields
|
||||
::Inboxes::SyncWidgetPreChatCustomFieldsJob.perform_later(attribute_key)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user