diff --git a/app/javascript/dashboard/i18n/locale/en/campaign.json b/app/javascript/dashboard/i18n/locale/en/campaign.json
index 4d727b8e3..34bb9cdd3 100644
--- a/app/javascript/dashboard/i18n/locale/en/campaign.json
+++ b/app/javascript/dashboard/i18n/locale/en/campaign.json
@@ -42,6 +42,14 @@
"ERROR_MESSAGE": "There was an error. Please try again."
}
},
+ "EDIT": {
+ "TITLE": "Edit campaign",
+ "UPDATE_BUTTON_TEXT": "Update",
+ "API": {
+ "SUCCESS_MESSAGE": "Campaign updated successfully",
+ "ERROR_MESSAGE": "There was an error, please try again"
+ }
+ },
"LIST": {
"LOADING_MESSAGE": "Loading campaigns...",
"TABLE_HEADER": {
diff --git a/app/javascript/dashboard/routes/dashboard/settings/inbox/Settings.vue b/app/javascript/dashboard/routes/dashboard/settings/inbox/Settings.vue
index 4ba8cedc2..0f7f2dba1 100644
--- a/app/javascript/dashboard/routes/dashboard/settings/inbox/Settings.vue
+++ b/app/javascript/dashboard/routes/dashboard/settings/inbox/Settings.vue
@@ -335,10 +335,6 @@ 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'),
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 4ad99e316..928f8d8db 100644
--- a/app/javascript/dashboard/routes/dashboard/settings/inbox/components/Campaign.vue
+++ b/app/javascript/dashboard/routes/dashboard/settings/inbox/components/Campaign.vue
@@ -1,8 +1,7 @@
-
-
+
{{ $t('CAMPAIGN.HEADER_BTN_TXT') }}
@@ -10,22 +9,32 @@
:campaigns="records"
:show-empty-state="showEmptyResult"
:is-loading="uiFlags.isFetching"
+ :on-edit-click="openEditPopup"
/>
+
+
+
diff --git a/app/javascript/dashboard/routes/dashboard/settings/inbox/components/CampaignsTable.vue b/app/javascript/dashboard/routes/dashboard/settings/inbox/components/CampaignsTable.vue
index 8df1a58a6..084bb497c 100644
--- a/app/javascript/dashboard/routes/dashboard/settings/inbox/components/CampaignsTable.vue
+++ b/app/javascript/dashboard/routes/dashboard/settings/inbox/components/CampaignsTable.vue
@@ -44,6 +44,10 @@ export default {
type: Boolean,
default: false,
},
+ onEditClick: {
+ type: Function,
+ default: () => {},
+ },
},
data() {
@@ -130,14 +134,14 @@ export default {
key: 'buttons',
title: '',
align: 'left',
- renderBodyCell: () => (
+ renderBodyCell: (row) => (
this.onEditClick(row)}
>
{this.$t('CAMPAIGN.LIST.BUTTONS.EDIT')}
diff --git a/app/javascript/dashboard/routes/dashboard/settings/inbox/components/EditCampaign.vue b/app/javascript/dashboard/routes/dashboard/settings/inbox/components/EditCampaign.vue
new file mode 100644
index 000000000..707f73294
--- /dev/null
+++ b/app/javascript/dashboard/routes/dashboard/settings/inbox/components/EditCampaign.vue
@@ -0,0 +1,236 @@
+
+
+
+
+
+
+
+
diff --git a/app/javascript/dashboard/store/modules/campaigns.js b/app/javascript/dashboard/store/modules/campaigns.js
index 683dc0d98..ded7f6aa0 100644
--- a/app/javascript/dashboard/store/modules/campaigns.js
+++ b/app/javascript/dashboard/store/modules/campaigns.js
@@ -42,6 +42,17 @@ export const actions = {
commit(types.SET_CAMPAIGN_UI_FLAG, { isCreating: false });
}
},
+ update: async ({ commit }, { id, ...updateObj }) => {
+ commit(types.SET_CAMPAIGN_UI_FLAG, { isUpdating: true });
+ try {
+ const response = await CampaignsAPI.update(id, updateObj);
+ commit(types.EDIT_CAMPAIGN, response.data);
+ } catch (error) {
+ throw new Error(error);
+ } finally {
+ commit(types.SET_CAMPAIGN_UI_FLAG, { isUpdating: false });
+ }
+ },
};
export const mutations = {
@@ -54,6 +65,7 @@ export const mutations = {
[types.ADD_CAMPAIGN]: MutationHelpers.create,
[types.SET_CAMPAIGNS]: MutationHelpers.set,
+ [types.EDIT_CAMPAIGN]: MutationHelpers.update,
};
export default {
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 d49c6a2a5..77e0cedb1 100644
--- a/app/javascript/dashboard/store/modules/specs/campaigns/actions.spec.js
+++ b/app/javascript/dashboard/store/modules/specs/campaigns/actions.spec.js
@@ -46,4 +46,26 @@ describe('#actions', () => {
]);
});
});
+
+ describe('#update', () => {
+ it('sends correct actions if API is success', async () => {
+ axios.patch.mockResolvedValue({ data: campaignList[0] });
+ await actions.update({ commit }, campaignList[0]);
+ expect(commit.mock.calls).toEqual([
+ [types.default.SET_CAMPAIGN_UI_FLAG, { isUpdating: true }],
+ [types.default.EDIT_CAMPAIGN, campaignList[0]],
+ [types.default.SET_CAMPAIGN_UI_FLAG, { isUpdating: false }],
+ ]);
+ });
+ it('sends correct actions if API is error', async () => {
+ axios.patch.mockRejectedValue({ message: 'Incorrect header' });
+ await expect(actions.update({ commit }, campaignList[0])).rejects.toThrow(
+ Error
+ );
+ expect(commit.mock.calls).toEqual([
+ [types.default.SET_CAMPAIGN_UI_FLAG, { isUpdating: true }],
+ [types.default.SET_CAMPAIGN_UI_FLAG, { isUpdating: false }],
+ ]);
+ });
+ });
});
diff --git a/app/javascript/dashboard/store/modules/specs/campaigns/fixtures.js b/app/javascript/dashboard/store/modules/specs/campaigns/fixtures.js
index 470eef9d9..38c954f90 100644
--- a/app/javascript/dashboard/store/modules/specs/campaigns/fixtures.js
+++ b/app/javascript/dashboard/store/modules/specs/campaigns/fixtures.js
@@ -1,6 +1,6 @@
export default [
{
- id: 8,
+ id: 1,
title: 'Welcome',
description: null,
account_id: 1,
@@ -115,7 +115,7 @@ export default [
updated_at: '2021-05-03T04:53:36.354Z',
},
{
- id: 11,
+ id: 2,
title: 'Onboarding Campaign',
description: null,
account_id: 1,
@@ -231,7 +231,7 @@ export default [
updated_at: '2021-05-03T08:15:35.828Z',
},
{
- id: 12,
+ id: 3,
title: 'Thanks',
description: null,
account_id: 1,
diff --git a/app/javascript/dashboard/store/modules/specs/campaigns/mutations.spec.js b/app/javascript/dashboard/store/modules/specs/campaigns/mutations.spec.js
index 61e33359e..e01359c78 100644
--- a/app/javascript/dashboard/store/modules/specs/campaigns/mutations.spec.js
+++ b/app/javascript/dashboard/store/modules/specs/campaigns/mutations.spec.js
@@ -18,4 +18,16 @@ describe('#mutations', () => {
expect(state.records).toEqual([campaigns[0], campaigns[1]]);
});
});
+ describe('#EDIT_CAMPAIGN', () => {
+ it('update campaign record', () => {
+ const state = { records: [campaigns[0]] };
+ mutations[types.EDIT_CAMPAIGN](state, {
+ id: 1,
+ title: 'Welcome',
+ account_id: 1,
+ message: 'Hey, What brings you today',
+ });
+ expect(state.records[0].message).toEqual('Hey, What brings you today');
+ });
+ });
});
diff --git a/app/javascript/dashboard/store/mutation-types.js b/app/javascript/dashboard/store/mutation-types.js
index a8634065e..29b1e45b5 100755
--- a/app/javascript/dashboard/store/mutation-types.js
+++ b/app/javascript/dashboard/store/mutation-types.js
@@ -150,4 +150,5 @@ export default {
SET_CAMPAIGN_UI_FLAG: 'SET_CAMPAIGN_UI_FLAG',
SET_CAMPAIGNS: 'SET_CAMPAIGNS',
ADD_CAMPAIGN: 'ADD_CAMPAIGN',
+ EDIT_CAMPAIGN: 'EDIT_CAMPAIGN',
};