feat: Add None option in automation assign agent actions (#7900)

This commit is contained in:
Muhsin Keloth
2023-09-14 09:01:58 +05:30
committed by GitHub
parent 5e6e234afe
commit 2d4ef0c328
3 changed files with 26 additions and 1 deletions

View File

@@ -120,9 +120,18 @@ export const generateConditionOptions = (options, key = 'id') => {
}); });
}; };
// Add the "None" option to the agent list
export const agentList = agents => [
{
id: 'nil',
name: 'None',
},
...(agents || []),
];
export const getActionOptions = ({ agents, teams, labels, type }) => { export const getActionOptions = ({ agents, teams, labels, type }) => {
const actionsMap = { const actionsMap = {
assign_agent: agents, assign_agent: agentList(agents),
assign_team: teams, assign_team: teams,
send_email_to_team: teams, send_email_to_team: teams,
add_label: generateConditionOptions(labels, 'title'), add_label: generateConditionOptions(labels, 'title'),

View File

@@ -32,6 +32,8 @@ class ActionService
end end
def assign_agent(agent_ids = []) def assign_agent(agent_ids = [])
return @conversation.update!(assignee_id: nil) if agent_ids[0] == 'nil'
return unless agent_belongs_to_inbox?(agent_ids) return unless agent_belongs_to_inbox?(agent_ids)
@agent = @account.users.find_by(id: agent_ids) @agent = @account.users.find_by(id: agent_ids)

View File

@@ -1,6 +1,8 @@
require 'rails_helper' require 'rails_helper'
describe ActionService do describe ActionService do
let(:account) { create(:account) }
describe '#resolve_conversation' do describe '#resolve_conversation' do
let(:conversation) { create(:conversation) } let(:conversation) { create(:conversation) }
let(:action_service) { described_class.new(conversation) } let(:action_service) { described_class.new(conversation) }
@@ -27,5 +29,17 @@ describe ActionService do
end end
end end
describe '#assign_agent' do
let(:agent) { create(:user, account: account, role: :agent) }
let(:conversation) { create(:conversation, account: account) }
let(:inbox_member) { create(:inbox_member, inbox: conversation.inbox, user: agent) }
let(:action_service) { described_class.new(conversation) }
it 'unassigns the conversation if agent id is nil' do
action_service.assign_agent(['nil'])
expect(conversation.reload.assignee).to be_nil
end
end
# TODO: Expand this test suite # TODO: Expand this test suite
end end