From 18cea3b0acbf20cb0de34a1ecc42df5768a728ac Mon Sep 17 00:00:00 2001 From: Muhsin Keloth Date: Mon, 17 May 2021 21:38:12 +0530 Subject: [PATCH] chore: Add inbox id in get campaigns API (#2278) --- app/javascript/dashboard/api/inboxes.js | 4 ++++ app/javascript/dashboard/api/specs/campaign.spec.js | 13 +++++++++++++ .../routes/dashboard/settings/inbox/Settings.vue | 8 ++++++-- .../settings/inbox/components/Campaign.vue | 4 +++- app/javascript/dashboard/store/modules/campaigns.js | 5 +++-- .../store/modules/specs/campaigns/actions.spec.js | 4 ++-- 6 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 app/javascript/dashboard/api/specs/campaign.spec.js diff --git a/app/javascript/dashboard/api/inboxes.js b/app/javascript/dashboard/api/inboxes.js index 73400b78c..b6d8ab860 100644 --- a/app/javascript/dashboard/api/inboxes.js +++ b/app/javascript/dashboard/api/inboxes.js @@ -9,6 +9,10 @@ class Inboxes extends ApiClient { getAssignableAgents(inboxId) { return axios.get(`${this.url}/${inboxId}/assignable_agents`); } + + getCampaigns(inboxId) { + return axios.get(`${this.url}/${inboxId}/campaigns`); + } } export default new Inboxes(); diff --git a/app/javascript/dashboard/api/specs/campaign.spec.js b/app/javascript/dashboard/api/specs/campaign.spec.js new file mode 100644 index 000000000..b94b6da5d --- /dev/null +++ b/app/javascript/dashboard/api/specs/campaign.spec.js @@ -0,0 +1,13 @@ +import campaigns from '../campaigns'; +import ApiClient from '../ApiClient'; + +describe('#CampaignAPI', () => { + it('creates correct instance', () => { + expect(campaigns).toBeInstanceOf(ApiClient); + expect(campaigns).toHaveProperty('get'); + expect(campaigns).toHaveProperty('show'); + expect(campaigns).toHaveProperty('create'); + expect(campaigns).toHaveProperty('update'); + expect(campaigns).toHaveProperty('delete'); + }); +}); diff --git a/app/javascript/dashboard/routes/dashboard/settings/inbox/Settings.vue b/app/javascript/dashboard/routes/dashboard/settings/inbox/Settings.vue index 0f7f2dba1..f1ee1980c 100644 --- a/app/javascript/dashboard/routes/dashboard/settings/inbox/Settings.vue +++ b/app/javascript/dashboard/routes/dashboard/settings/inbox/Settings.vue @@ -335,6 +335,10 @@ export default { if (this.isAWebWidgetInbox) { return [ ...visibleToAllChannelTabs, + { + key: 'campaign', + name: this.$t('INBOX_MGMT.TABS.CAMPAIGN'), + }, { key: 'preChatForm', name: this.$t('INBOX_MGMT.TABS.PRE_CHAT_FORM'), @@ -397,7 +401,7 @@ export default { }, toggleInput(selected, current) { if (selected.includes(current)) { - const newSelectedFlags = selected.filter((flag) => flag !== current); + const newSelectedFlags = selected.filter(flag => flag !== current); return newSelectedFlags; } return [...selected, current]; @@ -438,7 +442,7 @@ export default { } }, async updateAgents() { - const agentList = this.selectedAgents.map((el) => el.id); + const agentList = this.selectedAgents.map(el => el.id); this.isAgentListUpdating = true; try { await this.$store.dispatch('inboxMembers/create', { diff --git a/app/javascript/dashboard/routes/dashboard/settings/inbox/components/Campaign.vue b/app/javascript/dashboard/routes/dashboard/settings/inbox/components/Campaign.vue index 4929362b7..6692384dd 100644 --- a/app/javascript/dashboard/routes/dashboard/settings/inbox/components/Campaign.vue +++ b/app/javascript/dashboard/routes/dashboard/settings/inbox/components/Campaign.vue @@ -62,7 +62,9 @@ export default { }, }, mounted() { - this.$store.dispatch('campaigns/get'); + this.$store.dispatch('campaigns/get', { + inboxId: this.$route.params.inboxId, + }); }, methods: { openAddPopup() { diff --git a/app/javascript/dashboard/store/modules/campaigns.js b/app/javascript/dashboard/store/modules/campaigns.js index ded7f6aa0..fd8aa6f97 100644 --- a/app/javascript/dashboard/store/modules/campaigns.js +++ b/app/javascript/dashboard/store/modules/campaigns.js @@ -1,6 +1,7 @@ import * as MutationHelpers from 'shared/helpers/vuex/mutationHelpers'; import types from '../mutation-types'; import CampaignsAPI from '../../api/campaigns'; +import InboxesAPI from '../../api/inboxes'; export const state = { records: [], @@ -20,10 +21,10 @@ export const getters = { }; export const actions = { - get: async function getCampaigns({ commit }) { + get: async function getCampaigns({ commit }, { inboxId }) { commit(types.SET_CAMPAIGN_UI_FLAG, { isFetching: true }); try { - const response = await CampaignsAPI.get(); + const response = await InboxesAPI.getCampaigns(inboxId); commit(types.SET_CAMPAIGNS, response.data); } catch (error) { // Ignore error diff --git a/app/javascript/dashboard/store/modules/specs/campaigns/actions.spec.js b/app/javascript/dashboard/store/modules/specs/campaigns/actions.spec.js index 77e0cedb1..ad9b647b2 100644 --- a/app/javascript/dashboard/store/modules/specs/campaigns/actions.spec.js +++ b/app/javascript/dashboard/store/modules/specs/campaigns/actions.spec.js @@ -11,7 +11,7 @@ describe('#actions', () => { describe('#get', () => { it('sends correct actions if API is success', async () => { axios.get.mockResolvedValue({ data: campaignList }); - await actions.get({ commit }); + await actions.get({ commit }, { inboxId: 23 }); expect(commit.mock.calls).toEqual([ [types.default.SET_CAMPAIGN_UI_FLAG, { isFetching: true }], [types.default.SET_CAMPAIGNS, campaignList], @@ -20,7 +20,7 @@ describe('#actions', () => { }); it('sends correct actions if API is error', async () => { axios.get.mockRejectedValue({ message: 'Incorrect header' }); - await actions.get({ commit }); + await actions.get({ commit }, { inboxId: 23 }); expect(commit.mock.calls).toEqual([ [types.default.SET_CAMPAIGN_UI_FLAG, { isFetching: true }], [types.default.SET_CAMPAIGN_UI_FLAG, { isFetching: false }],