Feat: Assign conversations to teams. (#1849)
This commit is contained in:
committed by
GitHub
parent
941d4219f0
commit
c99c63cd79
@@ -103,18 +103,38 @@ const actions = {
|
||||
}
|
||||
},
|
||||
|
||||
assignAgent: async ({ commit }, { conversationId, agentId }) => {
|
||||
assignAgent: async ({ dispatch }, { conversationId, agentId }) => {
|
||||
try {
|
||||
const response = await ConversationApi.assignAgent({
|
||||
conversationId,
|
||||
agentId,
|
||||
});
|
||||
commit(types.default.ASSIGN_AGENT, response.data);
|
||||
dispatch('setCurrentChatAssignee', response.data);
|
||||
} catch (error) {
|
||||
// Handle error
|
||||
}
|
||||
},
|
||||
|
||||
setCurrentChatAssignee({ commit }, assignee) {
|
||||
commit(types.default.ASSIGN_AGENT, assignee);
|
||||
},
|
||||
|
||||
assignTeam: async ({ dispatch }, { conversationId, teamId }) => {
|
||||
try {
|
||||
const response = await ConversationApi.assignTeam({
|
||||
conversationId,
|
||||
teamId,
|
||||
});
|
||||
dispatch('setCurrentChatTeam', response.data);
|
||||
} catch (error) {
|
||||
// Handle error
|
||||
}
|
||||
},
|
||||
|
||||
setCurrentChatTeam({ commit }, team) {
|
||||
commit(types.default.ASSIGN_TEAM, team);
|
||||
},
|
||||
|
||||
toggleStatus: async ({ commit }, data) => {
|
||||
try {
|
||||
const response = await ConversationApi.toggleStatus(data);
|
||||
|
||||
@@ -61,7 +61,12 @@ export const mutations = {
|
||||
|
||||
[types.default.ASSIGN_AGENT](_state, assignee) {
|
||||
const [chat] = getSelectedChatConversation(_state);
|
||||
chat.meta.assignee = assignee;
|
||||
Vue.set(chat.meta, 'assignee', assignee);
|
||||
},
|
||||
|
||||
[types.default.ASSIGN_TEAM](_state, team) {
|
||||
const [chat] = getSelectedChatConversation(_state);
|
||||
Vue.set(chat.meta, 'team', team);
|
||||
},
|
||||
|
||||
[types.default.RESOLVE_CONVERSATION](_state, status) {
|
||||
@@ -145,7 +150,7 @@ export const mutations = {
|
||||
// Update assignee on action cable message
|
||||
[types.default.UPDATE_ASSIGNEE](_state, payload) {
|
||||
const [chat] = _state.allConversations.filter(c => c.id === payload.id);
|
||||
chat.meta.assignee = payload.assignee;
|
||||
Vue.set(chat.meta, 'assignee', payload.assignee);
|
||||
},
|
||||
|
||||
[types.default.UPDATE_CONVERSATION_CONTACT](
|
||||
|
||||
@@ -189,4 +189,52 @@ describe('#actions', () => {
|
||||
expect(commit.mock.calls).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#assignAgent', () => {
|
||||
it('sends correct mutations if assignment is successful', async () => {
|
||||
axios.post.mockResolvedValue({
|
||||
data: { id: 1, name: 'User' },
|
||||
});
|
||||
await actions.assignAgent({ commit }, { conversationId: 1, agentId: 1 });
|
||||
expect(commit).toHaveBeenCalledTimes(0);
|
||||
expect(commit.mock.calls).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#setCurrentChatAssignee', () => {
|
||||
it('sends correct mutations if assignment is successful', async () => {
|
||||
axios.post.mockResolvedValue({
|
||||
data: { id: 1, name: 'User' },
|
||||
});
|
||||
await actions.setCurrentChatAssignee({ commit }, { id: 1, name: 'User' });
|
||||
expect(commit).toHaveBeenCalledTimes(1);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
['ASSIGN_AGENT', { id: 1, name: 'User' }],
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#assignTeam', () => {
|
||||
it('sends correct mutations if assignment is successful', async () => {
|
||||
axios.post.mockResolvedValue({
|
||||
data: { id: 1, name: 'Team' },
|
||||
});
|
||||
await actions.assignTeam({ commit }, { conversationId: 1, teamId: 1 });
|
||||
expect(commit).toHaveBeenCalledTimes(0);
|
||||
expect(commit.mock.calls).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#setCurrentChatTeam', () => {
|
||||
it('sends correct mutations if assignment is successful', async () => {
|
||||
axios.post.mockResolvedValue({
|
||||
data: { id: 1, name: 'Team' },
|
||||
});
|
||||
await actions.setCurrentChatTeam({ commit }, { id: 1, name: 'Team' });
|
||||
expect(commit).toHaveBeenCalledTimes(1);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
['ASSIGN_TEAM', { id: 1, name: 'Team' }],
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -28,6 +28,7 @@ export default {
|
||||
MUTE_CONVERSATION: 'MUTE_CONVERSATION',
|
||||
UNMUTE_CONVERSATION: 'UNMUTE_CONVERSATION',
|
||||
ASSIGN_AGENT: 'ASSIGN_AGENT',
|
||||
ASSIGN_TEAM: 'ASSIGN_TEAM',
|
||||
SET_CHAT_META: 'SET_CHAT_META',
|
||||
ADD_MESSAGE: 'ADD_MESSAGE',
|
||||
ADD_PENDING_MESSAGE: 'ADD_PENDING_MESSAGE',
|
||||
|
||||
Reference in New Issue
Block a user