feat: Add ability to create a new conversation if the previous conversation is resolved (#2512)
Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
This commit is contained in:
@@ -11,7 +11,7 @@ import { refreshActionCableConnector } from '../../../helpers/actionCable';
|
||||
import { createTemporaryMessage, onNewMessageCreated } from './helpers';
|
||||
|
||||
export const actions = {
|
||||
createConversation: async ({ commit }, params) => {
|
||||
createConversation: async ({ commit, dispatch }, params) => {
|
||||
commit('setConversationUIFlag', { isCreating: true });
|
||||
try {
|
||||
const { data } = await createConversationAPI(params);
|
||||
@@ -22,6 +22,7 @@ export const actions = {
|
||||
const [message = {}] = messages;
|
||||
commit('pushMessageToConversation', message);
|
||||
refreshActionCableConnector(pubsubToken);
|
||||
dispatch('conversationAttributes/getAttributes', {}, { root: true });
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
// Ignore error
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
SET_CONVERSATION_ATTRIBUTES,
|
||||
UPDATE_CONVERSATION_ATTRIBUTES,
|
||||
CLEAR_CONVERSATION_ATTRIBUTES,
|
||||
} from '../types';
|
||||
import { getConversationAPI } from '../../api/conversation';
|
||||
|
||||
@@ -14,7 +15,7 @@ export const getters = {
|
||||
};
|
||||
|
||||
export const actions = {
|
||||
get: async ({ commit }) => {
|
||||
getAttributes: async ({ commit }) => {
|
||||
try {
|
||||
const { data } = await getConversationAPI();
|
||||
const { contact_last_seen_at: lastSeen } = data;
|
||||
@@ -27,6 +28,9 @@ export const actions = {
|
||||
update({ commit }, data) {
|
||||
commit(UPDATE_CONVERSATION_ATTRIBUTES, data);
|
||||
},
|
||||
clearConversationAttributes: ({ commit }) => {
|
||||
commit('CLEAR_CONVERSATION_ATTRIBUTES');
|
||||
},
|
||||
};
|
||||
|
||||
export const mutations = {
|
||||
@@ -40,6 +44,10 @@ export const mutations = {
|
||||
$state.status = data.status;
|
||||
}
|
||||
},
|
||||
[CLEAR_CONVERSATION_ATTRIBUTES]($state) {
|
||||
$state.id = '';
|
||||
$state.status = '';
|
||||
},
|
||||
};
|
||||
|
||||
export default {
|
||||
|
||||
@@ -5,10 +5,10 @@ const commit = jest.fn();
|
||||
jest.mock('widget/helpers/axios');
|
||||
|
||||
describe('#actions', () => {
|
||||
describe('#update', () => {
|
||||
describe('#get attributes', () => {
|
||||
it('sends mutation if api is success', async () => {
|
||||
API.get.mockResolvedValue({ data: { id: 1, status: 'bot' } });
|
||||
await actions.get({ commit });
|
||||
await actions.getAttributes({ commit });
|
||||
expect(commit.mock.calls).toEqual([
|
||||
['SET_CONVERSATION_ATTRIBUTES', { id: 1, status: 'bot' }],
|
||||
['conversation/setMetaUserLastSeenAt', undefined, { root: true }],
|
||||
@@ -16,12 +16,12 @@ describe('#actions', () => {
|
||||
});
|
||||
it('doesnot send mutation if api is error', async () => {
|
||||
API.get.mockRejectedValue({ message: 'Invalid Headers' });
|
||||
await actions.get({ commit });
|
||||
await actions.getAttributes({ commit });
|
||||
expect(commit.mock.calls).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#update', () => {
|
||||
describe('#update attributes', () => {
|
||||
it('sends correct mutations', () => {
|
||||
actions.update({ commit }, { id: 1, status: 'bot' });
|
||||
expect(commit).toBeCalledWith('UPDATE_CONVERSATION_ATTRIBUTES', {
|
||||
@@ -30,4 +30,10 @@ describe('#actions', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('#clear attributes', () => {
|
||||
it('sends correct mutations', () => {
|
||||
actions.clearConversationAttributes({ commit });
|
||||
expect(commit).toBeCalledWith('CLEAR_CONVERSATION_ATTRIBUTES');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -30,4 +30,15 @@ describe('#mutations', () => {
|
||||
expect(state).toEqual({ id: 1, status: 'bot' });
|
||||
});
|
||||
});
|
||||
|
||||
describe('#CLEAR_CONVERSATION_ATTRIBUTES', () => {
|
||||
it('clear status if it is same conversation', () => {
|
||||
const state = { id: 1, status: 'open' };
|
||||
mutations.CLEAR_CONVERSATION_ATTRIBUTES(state, {
|
||||
id: 1,
|
||||
status: 'open',
|
||||
});
|
||||
expect(state).toEqual({ id: '', status: '' });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user