From 571fefd7cd00e3f382ffacbbd853d44e594a42f8 Mon Sep 17 00:00:00 2001 From: Brandon Wilson Date: Mon, 13 Sep 2021 04:13:19 -0400 Subject: [PATCH] fix: Selected agent profile picture in agent multi select (#2949) --- .../conversations/assignments_controller.rb | 34 +++++++++++++------ .../dashboard/conversation/ContactPanel.vue | 4 +-- app/models/user.rb | 3 +- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/app/controllers/api/v1/accounts/conversations/assignments_controller.rb b/app/controllers/api/v1/accounts/conversations/assignments_controller.rb index 670abf37a..68ff2e67d 100644 --- a/app/controllers/api/v1/accounts/conversations/assignments_controller.rb +++ b/app/controllers/api/v1/accounts/conversations/assignments_controller.rb @@ -1,20 +1,34 @@ class Api::V1::Accounts::Conversations::AssignmentsController < Api::V1::Accounts::Conversations::BaseController # assigns agent/team to a conversation def create - set_assignee - render json: @assignee + if params.key?(:assignee_id) + set_agent + elsif params.key?(:team_id) + set_team + else + render json: nil + end end private - def set_assignee - # if params[:assignee_id] is not a valid id, it will set to nil, hence unassigning the conversation - if params.key?(:assignee_id) - @assignee = Current.account.users.find_by(id: params[:assignee_id]) - @conversation.update_assignee(@assignee) - elsif params.key?(:team_id) - @assignee = Current.account.teams.find_by(id: params[:team_id]) - @conversation.update!(team: @assignee) + def set_agent + @agent = Current.account.users.find_by(id: params[:assignee_id]) + @conversation.update_assignee(@agent) + render_agent + end + + def render_agent + if @agent.nil? + render json: nil + else + render partial: 'api/v1/models/agent', formats: [:json], locals: { resource: @agent } end end + + def set_team + @team = Current.account.teams.find_by(id: params[:team_id]) + @conversation.update!(team: @team) + render json: @team + end end diff --git a/app/javascript/dashboard/routes/dashboard/conversation/ContactPanel.vue b/app/javascript/dashboard/routes/dashboard/conversation/ContactPanel.vue index a7b440387..1155d0ea3 100644 --- a/app/javascript/dashboard/routes/dashboard/conversation/ContactPanel.vue +++ b/app/javascript/dashboard/routes/dashboard/conversation/ContactPanel.vue @@ -365,7 +365,7 @@ export default { id, name, role, - thumbnail, + avatar_url, } = this.currentUser; const selfAssign = { account_id, @@ -375,7 +375,7 @@ export default { id, name, role, - thumbnail, + thumbnail: avatar_url, }; this.assignedAgent = selfAssign; }, diff --git a/app/models/user.rb b/app/models/user.rb index bc0a2d20f..89ed7be84 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -156,7 +156,8 @@ class User < ApplicationRecord available_name: available_name, avatar_url: avatar_url, type: 'user', - availability_status: availability_status + availability_status: availability_status, + thumbnail: avatar_url } end