From edb09d5a9c1b7f034c5c88369b016bc4c4055338 Mon Sep 17 00:00:00 2001 From: Pranav Raj S Date: Sun, 13 Dec 2020 22:23:56 +0530 Subject: [PATCH] chore: Improve location display in sidebar (#1509) - Log IP Address on widget load - Save country code to contact --- .../api/v1/accounts/contacts_controller.rb | 9 -------- app/controllers/widgets_controller.rb | 10 +++++++- .../dashboard/conversation/ContactPanel.vue | 23 +++++++++++++++++++ .../conversation/contact/ContactInfo.vue | 13 ++++++----- .../conversation/contact/EditContact.vue | 11 --------- app/jobs/contact_ip_lookup_job.rb | 8 +++++-- app/models/channel/web_widget.rb | 7 ++++-- app/models/contact.rb | 3 +-- package.json | 1 + yarn.lock | 5 ++++ 10 files changed, 57 insertions(+), 33 deletions(-) diff --git a/app/controllers/api/v1/accounts/contacts_controller.rb b/app/controllers/api/v1/accounts/contacts_controller.rb index 58e301d5a..2ea843f9b 100644 --- a/app/controllers/api/v1/accounts/contacts_controller.rb +++ b/app/controllers/api/v1/accounts/contacts_controller.rb @@ -35,7 +35,6 @@ class Api::V1::Accounts::ContactsController < Api::V1::Accounts::BaseController def create ActiveRecord::Base.transaction do @contact = Current.account.contacts.new(contact_params) - set_ip @contact.save! @contact_inbox = build_contact_inbox end @@ -43,7 +42,6 @@ class Api::V1::Accounts::ContactsController < Api::V1::Accounts::BaseController def update @contact.assign_attributes(contact_update_params) - set_ip @contact.save! rescue ActiveRecord::RecordInvalid => e render json: { @@ -99,11 +97,4 @@ class Api::V1::Accounts::ContactsController < Api::V1::Accounts::BaseController def fetch_contact @contact = Current.account.contacts.includes(contact_inboxes: [:inbox]).find(params[:id]) end - - def set_ip - return if @contact.account.feature_enabled?('ip_lookup') - - @contact[:additional_attributes][:created_at_ip] ||= request.remote_ip - @contact[:additional_attributes][:updated_at_ip] = request.remote_ip - end end diff --git a/app/controllers/widgets_controller.rb b/app/controllers/widgets_controller.rb index 957203f16..da634875a 100644 --- a/app/controllers/widgets_controller.rb +++ b/app/controllers/widgets_controller.rb @@ -41,13 +41,21 @@ class WidgetsController < ActionController::Base def build_contact return if @contact.present? - contact_inbox = @web_widget.create_contact_inbox + contact_inbox = @web_widget.create_contact_inbox(additional_attributes) @contact = contact_inbox.contact payload = { source_id: contact_inbox.source_id, inbox_id: @web_widget.inbox.id } @token = ::Widget::TokenService.new(payload: payload).generate_token end + def additional_attributes + if @web_widget.inbox.account.feature_enabled?('ip_lookup') + { created_at_ip: request.remote_ip } + else + {} + end + end + def permitted_params params.permit(:website_token, :cw_conversation) end diff --git a/app/javascript/dashboard/routes/dashboard/conversation/ContactPanel.vue b/app/javascript/dashboard/routes/dashboard/conversation/ContactPanel.vue index cbf6656d8..1c7572d44 100644 --- a/app/javascript/dashboard/routes/dashboard/conversation/ContactPanel.vue +++ b/app/javascript/dashboard/routes/dashboard/conversation/ContactPanel.vue @@ -5,6 +5,12 @@
+ !!item).join(', '); + + if (!cityAndCountry) { + return ''; + } + const countryFlag = countryCode ? flag(countryCode) : '🌎'; + return `${countryFlag} ${cityAndCountry}`; + }, platformName() { const { platform_name: platformName, diff --git a/app/javascript/dashboard/routes/dashboard/conversation/contact/ContactInfo.vue b/app/javascript/dashboard/routes/dashboard/conversation/contact/ContactInfo.vue index 60ce60c20..c11cd2cc6 100644 --- a/app/javascript/dashboard/routes/dashboard/conversation/contact/ContactInfo.vue +++ b/app/javascript/dashboard/routes/dashboard/conversation/contact/ContactInfo.vue @@ -13,8 +13,8 @@
{{ contact.name }}
-
- {{ additionalAttibutes.description }} +
+ {{ additionalAttributes.description }}