feat: End conversation from widget (#3660)
Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com> Co-authored-by: Fayaz Ahmed <15716057+fayazara@users.noreply.github.com> Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com> Co-authored-by: Nithin David Thomas <1277421+nithindavid@users.noreply.github.com> Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
This commit is contained in:
@@ -100,6 +100,7 @@ export const actions = {
|
||||
{ root: true }
|
||||
);
|
||||
await triggerCampaign({ campaignId, websiteToken });
|
||||
commit('setCampaignExecuted', true);
|
||||
commit('setActiveCampaign', {});
|
||||
} catch (error) {
|
||||
commit('setError', true);
|
||||
@@ -113,6 +114,7 @@ export const actions = {
|
||||
},
|
||||
resetCampaign: async ({ commit }) => {
|
||||
try {
|
||||
commit('setCampaignExecuted', false);
|
||||
commit('setActiveCampaign', {});
|
||||
} catch (error) {
|
||||
commit('setError', true);
|
||||
@@ -130,6 +132,12 @@ export const mutations = {
|
||||
setError($state, value) {
|
||||
Vue.set($state.uiFlags, 'isError', value);
|
||||
},
|
||||
setHasFetched($state, value) {
|
||||
Vue.set($state.uiFlags, 'hasFetched', value);
|
||||
},
|
||||
setCampaignExecuted($state, data) {
|
||||
Vue.set($state, 'campaignHasExecuted', data);
|
||||
},
|
||||
};
|
||||
|
||||
export default {
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
sendAttachmentAPI,
|
||||
toggleTyping,
|
||||
setUserLastSeenAt,
|
||||
toggleStatus,
|
||||
} from 'widget/api/conversation';
|
||||
|
||||
import { createTemporaryMessage, getNonDeletedMessages } from './helpers';
|
||||
@@ -130,4 +131,8 @@ export const actions = {
|
||||
// IgnoreError
|
||||
}
|
||||
},
|
||||
|
||||
resolveConversation: async () => {
|
||||
await toggleStatus();
|
||||
},
|
||||
};
|
||||
|
||||
@@ -132,6 +132,7 @@ describe('#actions', () => {
|
||||
root: true,
|
||||
},
|
||||
],
|
||||
['setCampaignExecuted', true],
|
||||
['setActiveCampaign', {}],
|
||||
[
|
||||
'conversation/setConversationUIFlag',
|
||||
@@ -176,7 +177,10 @@ describe('#actions', () => {
|
||||
it('sends correct actions if execute campaign API is success', async () => {
|
||||
API.post.mockResolvedValue({});
|
||||
await actions.resetCampaign({ commit });
|
||||
expect(commit.mock.calls).toEqual([['setActiveCampaign', {}]]);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
['setCampaignExecuted', false],
|
||||
['setActiveCampaign', {}],
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -25,4 +25,12 @@ describe('#mutations', () => {
|
||||
expect(state.activeCampaign).toEqual(campaigns[0]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#setCampaignExecuted', () => {
|
||||
it('set campaign executed flag', () => {
|
||||
const state = { records: [], uiFlags: {}, campaignHasExecuted: false };
|
||||
mutations.setCampaignExecuted(state, true);
|
||||
expect(state.campaignHasExecuted).toEqual(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user