Feature: Add ability to disable auto assignment of conversations (#513)

This commit is contained in:
Tim Lange
2020-02-19 10:10:03 +01:00
committed by GitHub
parent e0afb84502
commit 30e5edf6dc
15 changed files with 377 additions and 230 deletions

View File

@@ -1,6 +1,6 @@
class Api::V1::InboxesController < Api::BaseController
before_action :check_authorization
before_action :fetch_inbox, only: [:destroy]
before_action :fetch_inbox, only: [:destroy, :update]
def index
@inboxes = policy_scope(current_account.inboxes)
@@ -11,6 +11,10 @@ class Api::V1::InboxesController < Api::BaseController
head :ok
end
def update
@inbox.update(inbox_update_params)
end
private
def fetch_inbox
@@ -20,4 +24,8 @@ class Api::V1::InboxesController < Api::BaseController
def check_authorization
authorize(Inbox)
end
def inbox_update_params
params.require(:inbox).permit(:enable_auto_assignment)
end
end

View File

@@ -74,7 +74,12 @@
"EDIT": {
"API": {
"SUCCESS_MESSAGE": "Widget color updated successfully",
"AUTO_ASSIGNMENT_SUCCESS_MESSAGE": "Auto assignment updated successfully",
"ERROR_MESSAGE": "Could not update widget color. Please try again later."
},
"AUTO_ASSIGNMENT": {
"ENABLED": "Enabled",
"DISABLED": "Disabled"
}
},
"DELETE": {
@@ -96,7 +101,9 @@
"MESSENGER_SUB_HEAD": "Place this button inside your body tag",
"INBOX_AGENTS": "Agents",
"INBOX_AGENTS_SUB_TEXT": "Add or remove agents from this inbox",
"UPDATE": "Update"
"UPDATE": "Update",
"AUTO_ASSIGNMENT": "Enable auto assignment",
"AUTO_ASSIGNMENT_SUB_TEXT": "Enable or disable the automatic assignment of available agents on new conversations"
}
}
}

View File

@@ -60,6 +60,20 @@
@select="$v.selectedAgents.$touch"
/>
</div>
<div class="settings--content">
<settings-form-header
:title="$t('INBOX_MGMT.SETTINGS_POPUP.AUTO_ASSIGNMENT')"
:sub-title="$t('INBOX_MGMT.SETTINGS_POPUP.AUTO_ASSIGNMENT_SUB_TEXT')"
:button-text="$t('INBOX_MGMT.SETTINGS_POPUP.UPDATE')"
:is-updating="uiFlags.isUpdatingAutoAssignment"
@update="updateAutoAssignment"
>
</settings-form-header>
<select v-model="autoAssignment">
<option value="true">{{ $t('INBOX_MGMT.EDIT.AUTO_ASSIGNMENT.ENABLED') }}</option>
<option value="false">{{ $t('INBOX_MGMT.EDIT.AUTO_ASSIGNMENT.DISABLED') }}</option>
</select>
</div>
</div>
</template>
@@ -82,6 +96,7 @@ export default {
data() {
return {
selectedAgents: [],
autoAssignment: false,
isUpdating: false,
isAgentListUpdating: false,
};
@@ -123,6 +138,7 @@ export default {
this.$store.dispatch('agents/get');
this.$store.dispatch('inboxes/get').then(() => {
this.fetchAttachedAgents();
this.autoAssignment = this.inbox.enable_auto_assignment;
});
},
async fetchAttachedAgents() {
@@ -172,6 +188,19 @@ export default {
this.showAlert(this.$t('INBOX_MGMT.EDIT.API.SUCCESS_MESSAGE'));
}
},
async updateAutoAssignment() {
try {
await this.$store.dispatch('inboxes/updateAutoAssignment', {
id: this.currentInboxId,
inbox: {
enable_auto_assignment: this.autoAssignment,
},
});
this.showAlert(this.$t('INBOX_MGMT.EDIT.API.AUTO_ASSIGNMENT_SUCCESS_MESSAGE'));
} catch (error) {
this.showAlert(this.$t('INBOX_MGMT.EDIT.API.AUTO_ASSIGNMENT_SUCCESS_MESSAGE'));
}
},
getWidgetColor() {
return typeof this.inbox.widget_color !== 'object'
? this.inbox.widget_color

View File

@@ -11,6 +11,7 @@ export const state = {
isFetchingItem: false,
isCreating: false,
isUpdating: false,
isUpdatingAutoAssignment: false,
isDeleting: false,
},
};
@@ -76,6 +77,17 @@ export const actions = {
throw new Error(error);
}
},
updateAutoAssignment: async ({ commit }, { id, ...inboxParams }) => {
commit(types.default.SET_INBOXES_UI_FLAG, { isUpdatingAutoAssignment: true });
try {
const response = await InboxesAPI.update(id, inboxParams);
commit(types.default.EDIT_INBOXES, response.data);
commit(types.default.SET_INBOXES_UI_FLAG, { isUpdatingAutoAssignment: false });
} catch (error) {
commit(types.default.SET_INBOXES_UI_FLAG, { isUpdatingAutoAssignment: false });
throw new Error(error);
}
},
delete: async ({ commit }, inboxId) => {
commit(types.default.SET_INBOXES_UI_FLAG, { isDeleting: true });
try {

View File

@@ -91,6 +91,31 @@ describe('#actions', () => {
]);
});
});
describe('#updateAutoAssignment', () => {
it('sends correct actions if API is success', async () => {
let updatedInbox = inboxList[0];
updatedInbox.enable_auto_assignment = false;
axios.patch.mockResolvedValue({ data: updatedInbox });
await actions.updateAutoAssignment({ commit }, { id: updatedInbox.id, inbox: { enable_auto_assignment: false} });
expect(commit.mock.calls).toEqual([
[types.default.SET_INBOXES_UI_FLAG, { isUpdatingAutoAssignment: true }],
[types.default.EDIT_INBOXES, updatedInbox],
[types.default.SET_INBOXES_UI_FLAG, { isUpdatingAutoAssignment: false }],
]);
});
it('sends correct actions if API is error', async () => {
axios.patch.mockRejectedValue({ message: 'Incorrect header' });
await expect(
actions.updateAutoAssignment({ commit }, { id: inboxList[0].id, inbox: { enable_auto_assignment: false} })
).rejects.toThrow(Error);
expect(commit.mock.calls).toEqual([
[types.default.SET_INBOXES_UI_FLAG, { isUpdatingAutoAssignment: true }],
[types.default.SET_INBOXES_UI_FLAG, { isUpdatingAutoAssignment: false }],
]);
});
});
describe('#delete', () => {
it('sends correct actions if API is success', async () => {

View File

@@ -8,6 +8,7 @@ export default [
page_id: '12345',
widget_color: null,
website_token: null,
enable_auto_assignment: true,
},
{
id: 2,
@@ -18,6 +19,7 @@ export default [
page_id: null,
widget_color: '#7B64FF',
website_token: 'randomid123',
enable_auto_assignment: true,
},
{
id: 3,
@@ -28,6 +30,7 @@ export default [
page_id: null,
widget_color: '#68BC00',
website_token: 'randomid124',
enable_auto_assignment: true,
},
{
id: 4,
@@ -38,5 +41,6 @@ export default [
page_id: null,
widget_color: '#68BC00',
website_token: 'randomid125',
enable_auto_assignment: true,
},
];

View File

@@ -22,6 +22,7 @@ describe('#getters', () => {
page_id: '12345',
widget_color: null,
website_token: null,
enable_auto_assignment: true,
});
});
@@ -32,6 +33,7 @@ describe('#getters', () => {
isFetchingItem: false,
isCreating: false,
isUpdating: false,
isUpdatingAutoAssignment: false,
isDeleting: false,
},
};
@@ -40,6 +42,7 @@ describe('#getters', () => {
isFetchingItem: false,
isCreating: false,
isUpdating: false,
isUpdatingAutoAssignment: false,
isDeleting: false,
});
});

View File

@@ -151,6 +151,7 @@ class Conversation < ApplicationRecord
def run_round_robin
# return unless conversation.account.has_feature?(round_robin)
# return unless conversation.account.round_robin_enabled?
return unless inbox.enable_auto_assignment
return if assignee
inbox.next_available_agent.then { |new_assignee| update_assignee(new_assignee) }

View File

@@ -4,13 +4,14 @@
#
# Table name: inboxes
#
# id :integer not null, primary key
# channel_type :string
# name :string not null
# created_at :datetime not null
# updated_at :datetime not null
# account_id :integer not null
# channel_id :integer not null
# id :integer not null, primary key
# channel_type :string
# enable_auto_assignment :boolean default(TRUE)
# name :string not null
# created_at :datetime not null
# updated_at :datetime not null
# account_id :integer not null
# channel_id :integer not null
#
# Indexes
#

View File

@@ -8,5 +8,6 @@ json.payload do
json.page_id inbox.channel.try(:page_id)
json.widget_color inbox.channel.try(:widget_color)
json.website_token inbox.channel.try(:website_token)
json.enable_auto_assignment inbox.enable_auto_assignment
end
end