chore: Add inbox id in get campaigns API (#2278)

This commit is contained in:
Muhsin Keloth 2021-05-17 21:38:12 +05:30 committed by GitHub
parent 60177ef418
commit 18cea3b0ac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 31 additions and 7 deletions

View file

@ -9,6 +9,10 @@ class Inboxes extends ApiClient {
getAssignableAgents(inboxId) { getAssignableAgents(inboxId) {
return axios.get(`${this.url}/${inboxId}/assignable_agents`); return axios.get(`${this.url}/${inboxId}/assignable_agents`);
} }
getCampaigns(inboxId) {
return axios.get(`${this.url}/${inboxId}/campaigns`);
}
} }
export default new Inboxes(); export default new Inboxes();

View file

@ -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');
});
});

View file

@ -335,6 +335,10 @@ export default {
if (this.isAWebWidgetInbox) { if (this.isAWebWidgetInbox) {
return [ return [
...visibleToAllChannelTabs, ...visibleToAllChannelTabs,
{
key: 'campaign',
name: this.$t('INBOX_MGMT.TABS.CAMPAIGN'),
},
{ {
key: 'preChatForm', key: 'preChatForm',
name: this.$t('INBOX_MGMT.TABS.PRE_CHAT_FORM'), name: this.$t('INBOX_MGMT.TABS.PRE_CHAT_FORM'),
@ -397,7 +401,7 @@ export default {
}, },
toggleInput(selected, current) { toggleInput(selected, current) {
if (selected.includes(current)) { if (selected.includes(current)) {
const newSelectedFlags = selected.filter((flag) => flag !== current); const newSelectedFlags = selected.filter(flag => flag !== current);
return newSelectedFlags; return newSelectedFlags;
} }
return [...selected, current]; return [...selected, current];
@ -438,7 +442,7 @@ export default {
} }
}, },
async updateAgents() { async updateAgents() {
const agentList = this.selectedAgents.map((el) => el.id); const agentList = this.selectedAgents.map(el => el.id);
this.isAgentListUpdating = true; this.isAgentListUpdating = true;
try { try {
await this.$store.dispatch('inboxMembers/create', { await this.$store.dispatch('inboxMembers/create', {

View file

@ -62,7 +62,9 @@ export default {
}, },
}, },
mounted() { mounted() {
this.$store.dispatch('campaigns/get'); this.$store.dispatch('campaigns/get', {
inboxId: this.$route.params.inboxId,
});
}, },
methods: { methods: {
openAddPopup() { openAddPopup() {

View file

@ -1,6 +1,7 @@
import * as MutationHelpers from 'shared/helpers/vuex/mutationHelpers'; import * as MutationHelpers from 'shared/helpers/vuex/mutationHelpers';
import types from '../mutation-types'; import types from '../mutation-types';
import CampaignsAPI from '../../api/campaigns'; import CampaignsAPI from '../../api/campaigns';
import InboxesAPI from '../../api/inboxes';
export const state = { export const state = {
records: [], records: [],
@ -20,10 +21,10 @@ export const getters = {
}; };
export const actions = { export const actions = {
get: async function getCampaigns({ commit }) { get: async function getCampaigns({ commit }, { inboxId }) {
commit(types.SET_CAMPAIGN_UI_FLAG, { isFetching: true }); commit(types.SET_CAMPAIGN_UI_FLAG, { isFetching: true });
try { try {
const response = await CampaignsAPI.get(); const response = await InboxesAPI.getCampaigns(inboxId);
commit(types.SET_CAMPAIGNS, response.data); commit(types.SET_CAMPAIGNS, response.data);
} catch (error) { } catch (error) {
// Ignore error // Ignore error

View file

@ -11,7 +11,7 @@ describe('#actions', () => {
describe('#get', () => { describe('#get', () => {
it('sends correct actions if API is success', async () => { it('sends correct actions if API is success', async () => {
axios.get.mockResolvedValue({ data: campaignList }); axios.get.mockResolvedValue({ data: campaignList });
await actions.get({ commit }); await actions.get({ commit }, { inboxId: 23 });
expect(commit.mock.calls).toEqual([ expect(commit.mock.calls).toEqual([
[types.default.SET_CAMPAIGN_UI_FLAG, { isFetching: true }], [types.default.SET_CAMPAIGN_UI_FLAG, { isFetching: true }],
[types.default.SET_CAMPAIGNS, campaignList], [types.default.SET_CAMPAIGNS, campaignList],
@ -20,7 +20,7 @@ describe('#actions', () => {
}); });
it('sends correct actions if API is error', async () => { it('sends correct actions if API is error', async () => {
axios.get.mockRejectedValue({ message: 'Incorrect header' }); axios.get.mockRejectedValue({ message: 'Incorrect header' });
await actions.get({ commit }); await actions.get({ commit }, { inboxId: 23 });
expect(commit.mock.calls).toEqual([ expect(commit.mock.calls).toEqual([
[types.default.SET_CAMPAIGN_UI_FLAG, { isFetching: true }], [types.default.SET_CAMPAIGN_UI_FLAG, { isFetching: true }],
[types.default.SET_CAMPAIGN_UI_FLAG, { isFetching: false }], [types.default.SET_CAMPAIGN_UI_FLAG, { isFetching: false }],