Chore: Move conversationStats to a seperate module (#962)
* Chore: Move conversationStats to a seperate module * Move toggleTyping to conversationTypingStatus * Remove unused agentTyping flag * Fix review comments
This commit is contained in:
@@ -2,7 +2,6 @@ import Vue from 'vue';
|
||||
import * as types from '../../mutation-types';
|
||||
import ConversationApi from '../../../api/inbox/conversation';
|
||||
import MessageApi from '../../../api/inbox/message';
|
||||
import FBChannel from '../../../api/channel/fbChannel';
|
||||
|
||||
// actions
|
||||
const actions = {
|
||||
@@ -26,7 +25,7 @@ const actions = {
|
||||
const { data } = response.data;
|
||||
const { payload: chatList, meta: metaData } = data;
|
||||
commit(types.default.SET_ALL_CONVERSATION, chatList);
|
||||
commit(types.default.SET_CONV_TAB_META, metaData);
|
||||
dispatch('conversationStats/set', metaData);
|
||||
commit(types.default.CLEAR_LIST_LOADING_STATUS);
|
||||
commit(
|
||||
`contacts/${types.default.SET_CONTACTS}`,
|
||||
@@ -171,24 +170,6 @@ const actions = {
|
||||
commit(types.default.UPDATE_CONVERSATION, conversation);
|
||||
},
|
||||
|
||||
toggleTyping: async ({ commit }, { status, conversationId }) => {
|
||||
try {
|
||||
commit(types.default.SET_AGENT_TYPING, { status });
|
||||
await ConversationApi.toggleTyping({ status, conversationId });
|
||||
} catch (error) {
|
||||
// Handle error
|
||||
}
|
||||
},
|
||||
|
||||
markSeen: async ({ commit }, data) => {
|
||||
try {
|
||||
await FBChannel.markSeen(data);
|
||||
commit(types.default.MARK_SEEN);
|
||||
} catch (error) {
|
||||
// Handle error
|
||||
}
|
||||
},
|
||||
|
||||
markMessagesRead: async ({ commit }, data) => {
|
||||
setTimeout(() => {
|
||||
commit(types.default.MARK_MESSAGE_READ, data);
|
||||
@@ -236,15 +217,6 @@ const actions = {
|
||||
//
|
||||
}
|
||||
},
|
||||
|
||||
getConversationStats: async ({ commit }, params) => {
|
||||
try {
|
||||
const response = await ConversationApi.meta(params);
|
||||
commit(types.default.SET_CONV_TAB_META, response.data.meta);
|
||||
} catch (error) {
|
||||
// Ignore error
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default actions;
|
||||
|
||||
@@ -52,7 +52,6 @@ const getters = {
|
||||
},
|
||||
getChatStatusFilter: ({ chatStatusFilter }) => chatStatusFilter,
|
||||
getSelectedInbox: ({ currentInbox }) => currentInbox,
|
||||
getConvTabStats: ({ convTabStats }) => convTabStats,
|
||||
getNextChatConversation: _state => {
|
||||
const { selectedChat } = _state;
|
||||
const conversations = getters.getAllStatusChats(_state);
|
||||
|
||||
@@ -12,16 +12,10 @@ const initialSelectedChat = {
|
||||
status: null,
|
||||
muted: false,
|
||||
seen: false,
|
||||
agentTyping: 'off',
|
||||
dataFetched: false,
|
||||
};
|
||||
const state = {
|
||||
allConversations: [],
|
||||
convTabStats: {
|
||||
mineCount: 0,
|
||||
unAssignedCount: 0,
|
||||
allCount: 0,
|
||||
},
|
||||
selectedChat: { ...initialSelectedChat },
|
||||
listLoadingStatus: true,
|
||||
chatStatusFilter: wootConstants.STATUS_TYPE.OPEN,
|
||||
@@ -57,7 +51,6 @@ const mutations = {
|
||||
},
|
||||
[types.default.CLEAR_CURRENT_CHAT_WINDOW](_state) {
|
||||
_state.selectedChat.id = null;
|
||||
_state.selectedChat.agentTyping = 'off';
|
||||
},
|
||||
|
||||
[types.default.SET_PREVIOUS_CONVERSATIONS](_state, { id, data }) {
|
||||
@@ -67,19 +60,6 @@ const mutations = {
|
||||
}
|
||||
},
|
||||
|
||||
[types.default.SET_CONV_TAB_META](
|
||||
_state,
|
||||
{
|
||||
mine_count: mineCount,
|
||||
unassigned_count: unAssignedCount,
|
||||
all_count: allCount,
|
||||
} = {}
|
||||
) {
|
||||
Vue.set(_state.convTabStats, 'mineCount', mineCount);
|
||||
Vue.set(_state.convTabStats, 'allCount', allCount);
|
||||
Vue.set(_state.convTabStats, 'unAssignedCount', unAssignedCount);
|
||||
},
|
||||
|
||||
[types.default.CURRENT_CHAT_WINDOW](_state, activeChat) {
|
||||
if (activeChat) {
|
||||
Object.assign(_state.selectedChat, activeChat);
|
||||
@@ -176,10 +156,6 @@ const mutations = {
|
||||
_state.selectedChat.seen = true;
|
||||
},
|
||||
|
||||
[types.default.SET_AGENT_TYPING](_state, { status }) {
|
||||
_state.selectedChat.agentTyping = status;
|
||||
},
|
||||
|
||||
[types.default.SET_LIST_LOADING_STATUS](_state) {
|
||||
_state.listLoadingStatus = true;
|
||||
},
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
import axios from 'axios';
|
||||
import actions from '../actions';
|
||||
import * as types from '../../../mutation-types';
|
||||
|
||||
const commit = jest.fn();
|
||||
global.axios = axios;
|
||||
jest.mock('axios');
|
||||
|
||||
describe('#actions', () => {
|
||||
describe('#getConversationStats', () => {
|
||||
it('sends correct actions if API is success', async () => {
|
||||
axios.get.mockResolvedValue({ data: { meta: { mine_count: 1 } } });
|
||||
await actions.getConversationStats(
|
||||
{ commit },
|
||||
{ inboxId: 1, assigneeTpe: 'me', status: 'open' }
|
||||
);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.default.SET_CONV_TAB_META, { mine_count: 1 }],
|
||||
]);
|
||||
});
|
||||
it('sends correct actions if API is error', async () => {
|
||||
axios.get.mockRejectedValue({ message: 'Incorrect header' });
|
||||
await actions.getConversationStats(
|
||||
{ commit },
|
||||
{ inboxId: 1, assigneeTpe: 'me', status: 'open' }
|
||||
);
|
||||
expect(commit.mock.calls).toEqual([]);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user