fix: Selected agent profile picture in agent multi select (#2949)

This commit is contained in:
Brandon Wilson 2021-09-13 04:13:19 -04:00 committed by GitHub
parent b74261205d
commit 571fefd7cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 13 deletions

View file

@ -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

View file

@ -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;
},

View file

@ -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