feat: Dedicated tab for campaigns (#2741)
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
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: [],
|
||||
@@ -15,16 +14,18 @@ export const getters = {
|
||||
getUIFlags(_state) {
|
||||
return _state.uiFlags;
|
||||
},
|
||||
getCampaigns(_state) {
|
||||
return _state.records;
|
||||
getCampaigns: _state => campaignType => {
|
||||
return _state.records.filter(
|
||||
record => record.campaign_type === campaignType
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
export const actions = {
|
||||
get: async function getCampaigns({ commit }, { inboxId }) {
|
||||
get: async function getCampaigns({ commit }) {
|
||||
commit(types.SET_CAMPAIGN_UI_FLAG, { isFetching: true });
|
||||
try {
|
||||
const response = await InboxesAPI.getCampaigns(inboxId);
|
||||
const response = await CampaignsAPI.get();
|
||||
commit(types.SET_CAMPAIGNS, response.data);
|
||||
} catch (error) {
|
||||
// Ignore error
|
||||
|
||||
@@ -66,8 +66,11 @@ export const getters = {
|
||||
return $state.uiFlags;
|
||||
},
|
||||
getWebsiteInboxes($state) {
|
||||
return $state.records.filter(item => item.channel_type === INBOX_TYPES.WEB);
|
||||
},
|
||||
getTwilioInboxes($state) {
|
||||
return $state.records.filter(
|
||||
item => item.channel_type === 'Channel::WebWidget'
|
||||
item => item.channel_type === INBOX_TYPES.TWILIO
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -4,107 +4,7 @@ export default [
|
||||
title: 'Welcome',
|
||||
description: null,
|
||||
account_id: 1,
|
||||
inbox: {
|
||||
id: 37,
|
||||
channel_id: 1,
|
||||
name: 'Chatwoot',
|
||||
channel_type: 'Channel::WebWidget',
|
||||
greeting_enabled: true,
|
||||
greeting_message: '',
|
||||
working_hours_enabled: true,
|
||||
out_of_office_message:
|
||||
'We are unavailable at the moment. Leave a message we will respond once we are back.',
|
||||
working_hours: [
|
||||
{
|
||||
day_of_week: 0,
|
||||
closed_all_day: true,
|
||||
open_hour: null,
|
||||
open_minutes: null,
|
||||
close_hour: null,
|
||||
close_minutes: null,
|
||||
},
|
||||
{
|
||||
day_of_week: 1,
|
||||
closed_all_day: false,
|
||||
open_hour: 11,
|
||||
open_minutes: 0,
|
||||
close_hour: 23,
|
||||
close_minutes: 30,
|
||||
},
|
||||
{
|
||||
day_of_week: 2,
|
||||
closed_all_day: false,
|
||||
open_hour: 11,
|
||||
open_minutes: 0,
|
||||
close_hour: 23,
|
||||
close_minutes: 30,
|
||||
},
|
||||
{
|
||||
day_of_week: 3,
|
||||
closed_all_day: false,
|
||||
open_hour: 11,
|
||||
open_minutes: 0,
|
||||
close_hour: 23,
|
||||
close_minutes: 30,
|
||||
},
|
||||
{
|
||||
day_of_week: 4,
|
||||
closed_all_day: false,
|
||||
open_hour: 11,
|
||||
open_minutes: 0,
|
||||
close_hour: 23,
|
||||
close_minutes: 30,
|
||||
},
|
||||
{
|
||||
day_of_week: 5,
|
||||
closed_all_day: false,
|
||||
open_hour: 11,
|
||||
open_minutes: 0,
|
||||
close_hour: 23,
|
||||
close_minutes: 30,
|
||||
},
|
||||
{
|
||||
day_of_week: 6,
|
||||
closed_all_day: true,
|
||||
open_hour: null,
|
||||
open_minutes: null,
|
||||
close_hour: null,
|
||||
close_minutes: null,
|
||||
},
|
||||
],
|
||||
timezone: 'Asia/Kolkata',
|
||||
avatar_url: '',
|
||||
page_id: null,
|
||||
widget_color: '#1F93FF',
|
||||
website_url: 'chatwoot.com',
|
||||
welcome_title: 'Hi there ! 🙌🏼',
|
||||
welcome_tagline:
|
||||
'We make it simple to connect with us. Ask us anything, or share your feedback.',
|
||||
enable_auto_assignment: true,
|
||||
website_token: '',
|
||||
forward_to_email: null,
|
||||
phone_number: null,
|
||||
selected_feature_flags: ['attachments', 'emoji_picker'],
|
||||
reply_time: 'in_a_few_hours',
|
||||
hmac_token: '',
|
||||
pre_chat_form_enabled: true,
|
||||
pre_chat_form_options: {
|
||||
require_email: true,
|
||||
pre_chat_message: 'Share your queries or comments here.',
|
||||
},
|
||||
},
|
||||
sender: {
|
||||
account_id: 1,
|
||||
availability_status: 'offline',
|
||||
confirmed: true,
|
||||
email: 'sojan@chatwoot.com',
|
||||
available_name: 'Sojan',
|
||||
id: 10,
|
||||
name: 'Sojan',
|
||||
role: 'administrator',
|
||||
thumbnail:
|
||||
'http://0.0.0.0:3000/rails/active_storage/representations/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBDZz09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--bfa5e8a4563aef73980771fc9b8007d380e586e5/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdCam9MY21WemFYcGxTU0lNTWpVd2VESTFNQVk2QmtWVSIsImV4cCI6bnVsbCwicHVyIjoidmFyaWF0aW9uIn19--c13bd5229b2a2a692444606e22f76ad61c634661/73185.jpeg',
|
||||
},
|
||||
campaign_type: 'ongoing',
|
||||
message: 'Hey, What brings you today',
|
||||
enabled: true,
|
||||
trigger_rules: {
|
||||
@@ -119,110 +19,7 @@ export default [
|
||||
title: 'Onboarding Campaign',
|
||||
description: null,
|
||||
account_id: 1,
|
||||
inbox: {
|
||||
id: 37,
|
||||
channel_id: 1,
|
||||
name: 'Chatwoot',
|
||||
channel_type: 'Channel::WebWidget',
|
||||
greeting_enabled: true,
|
||||
greeting_message: '',
|
||||
working_hours_enabled: true,
|
||||
out_of_office_message:
|
||||
'We are unavailable at the moment. Leave a message we will respond once we are back.',
|
||||
working_hours: [
|
||||
{
|
||||
day_of_week: 0,
|
||||
closed_all_day: true,
|
||||
open_hour: null,
|
||||
open_minutes: null,
|
||||
close_hour: null,
|
||||
close_minutes: null,
|
||||
},
|
||||
{
|
||||
day_of_week: 1,
|
||||
closed_all_day: false,
|
||||
open_hour: 11,
|
||||
open_minutes: 0,
|
||||
close_hour: 23,
|
||||
close_minutes: 30,
|
||||
},
|
||||
{
|
||||
day_of_week: 2,
|
||||
closed_all_day: false,
|
||||
open_hour: 11,
|
||||
open_minutes: 0,
|
||||
close_hour: 23,
|
||||
close_minutes: 30,
|
||||
},
|
||||
{
|
||||
day_of_week: 3,
|
||||
closed_all_day: false,
|
||||
open_hour: 11,
|
||||
open_minutes: 0,
|
||||
close_hour: 23,
|
||||
close_minutes: 30,
|
||||
},
|
||||
{
|
||||
day_of_week: 4,
|
||||
closed_all_day: false,
|
||||
open_hour: 11,
|
||||
open_minutes: 0,
|
||||
close_hour: 23,
|
||||
close_minutes: 30,
|
||||
},
|
||||
{
|
||||
day_of_week: 5,
|
||||
closed_all_day: false,
|
||||
open_hour: 11,
|
||||
open_minutes: 0,
|
||||
close_hour: 23,
|
||||
close_minutes: 30,
|
||||
},
|
||||
{
|
||||
day_of_week: 6,
|
||||
closed_all_day: true,
|
||||
open_hour: null,
|
||||
open_minutes: null,
|
||||
close_hour: null,
|
||||
close_minutes: null,
|
||||
},
|
||||
],
|
||||
timezone: 'Asia/Kolkata',
|
||||
avatar_url: '',
|
||||
page_id: null,
|
||||
widget_color: '#1F93FF',
|
||||
website_url: 'chatwoot.com',
|
||||
welcome_title: 'Hi there ! 🙌🏼',
|
||||
welcome_tagline:
|
||||
'We make it simple to connect with us. Ask us anything, or share your feedback.',
|
||||
enable_auto_assignment: true,
|
||||
web_widget_script: '',
|
||||
website_token: '',
|
||||
forward_to_email: null,
|
||||
phone_number: null,
|
||||
selected_feature_flags: ['attachments', 'emoji_picker'],
|
||||
reply_time: 'in_a_few_hours',
|
||||
hmac_token: '',
|
||||
pre_chat_form_enabled: true,
|
||||
pre_chat_form_options: {
|
||||
require_email: true,
|
||||
pre_chat_message: 'Share your queries or comments here.',
|
||||
},
|
||||
},
|
||||
sender: {
|
||||
account_id: 1,
|
||||
availability_status: 'offline',
|
||||
confirmed: true,
|
||||
email: 'sojan@chatwoot.com',
|
||||
available_name: 'Sojan',
|
||||
id: 10,
|
||||
name: 'Sojan',
|
||||
role: 'administrator',
|
||||
thumbnail:
|
||||
'http://0.0.0.0:3000/rails/active_storage/representations/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBDZz09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--bfa5e8a4563aef73980771fc9b8007d380e586e5/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdCam9MY21WemFYcGxTU0lNTWpVd2VESTFNQVk2QmtWVSIsImV4cCI6bnVsbCwicHVyIjoidmFyaWF0aW9uIn19--c13bd5229b2a2a692444606e22f76ad61c634661/73185.jpeg',
|
||||
},
|
||||
message: 'Begin your onboarding campaign with a welcome message',
|
||||
enabled: true,
|
||||
campaign_type: 'one_off',
|
||||
trigger_rules: {
|
||||
url: 'https://chatwoot.com',
|
||||
time_on_page: '20',
|
||||
@@ -235,107 +32,7 @@ export default [
|
||||
title: 'Thanks',
|
||||
description: null,
|
||||
account_id: 1,
|
||||
inbox: {
|
||||
id: 37,
|
||||
channel_id: 1,
|
||||
name: 'Chatwoot',
|
||||
channel_type: 'Channel::WebWidget',
|
||||
greeting_enabled: true,
|
||||
greeting_message: '',
|
||||
working_hours_enabled: true,
|
||||
out_of_office_message:
|
||||
'We are unavailable at the moment. Leave a message we will respond once we are back.',
|
||||
working_hours: [
|
||||
{
|
||||
day_of_week: 0,
|
||||
closed_all_day: true,
|
||||
open_hour: null,
|
||||
open_minutes: null,
|
||||
close_hour: null,
|
||||
close_minutes: null,
|
||||
},
|
||||
{
|
||||
day_of_week: 1,
|
||||
closed_all_day: false,
|
||||
open_hour: 11,
|
||||
open_minutes: 0,
|
||||
close_hour: 23,
|
||||
close_minutes: 30,
|
||||
},
|
||||
{
|
||||
day_of_week: 2,
|
||||
closed_all_day: false,
|
||||
open_hour: 11,
|
||||
open_minutes: 0,
|
||||
close_hour: 23,
|
||||
close_minutes: 30,
|
||||
},
|
||||
{
|
||||
day_of_week: 3,
|
||||
closed_all_day: false,
|
||||
open_hour: 11,
|
||||
open_minutes: 0,
|
||||
close_hour: 23,
|
||||
close_minutes: 30,
|
||||
},
|
||||
{
|
||||
day_of_week: 4,
|
||||
closed_all_day: false,
|
||||
open_hour: 11,
|
||||
open_minutes: 0,
|
||||
close_hour: 23,
|
||||
close_minutes: 30,
|
||||
},
|
||||
{
|
||||
day_of_week: 5,
|
||||
closed_all_day: false,
|
||||
open_hour: 11,
|
||||
open_minutes: 0,
|
||||
close_hour: 23,
|
||||
close_minutes: 30,
|
||||
},
|
||||
{
|
||||
day_of_week: 6,
|
||||
closed_all_day: true,
|
||||
open_hour: null,
|
||||
open_minutes: null,
|
||||
close_hour: null,
|
||||
close_minutes: null,
|
||||
},
|
||||
],
|
||||
timezone: 'Asia/Kolkata',
|
||||
avatar_url: '',
|
||||
page_id: null,
|
||||
widget_color: '#1F93FF',
|
||||
website_url: 'chatwoot.com',
|
||||
welcome_title: 'Hi there ! 🙌🏼',
|
||||
welcome_tagline:
|
||||
'We make it simple to connect with us. Ask us anything, or share your feedback.',
|
||||
enable_auto_assignment: true,
|
||||
web_widget_script: '',
|
||||
website_token: '',
|
||||
forward_to_email: null,
|
||||
phone_number: null,
|
||||
selected_feature_flags: ['attachments', 'emoji_picker'],
|
||||
reply_time: 'in_a_few_hours',
|
||||
hmac_token: '',
|
||||
pre_chat_form_enabled: true,
|
||||
pre_chat_form_options: {
|
||||
require_email: true,
|
||||
pre_chat_message: 'Share your queries or comments here.',
|
||||
},
|
||||
},
|
||||
sender: {
|
||||
account_id: 1,
|
||||
availability_status: 'offline',
|
||||
confirmed: true,
|
||||
email: 'nithin@chatwoot.com',
|
||||
available_name: 'Nithin',
|
||||
id: 13,
|
||||
name: 'Nithin',
|
||||
role: 'administrator',
|
||||
thumbnail: '',
|
||||
},
|
||||
campaign_type: 'ongoing',
|
||||
message: 'Thanks for coming to the show. How may I help you?',
|
||||
enabled: false,
|
||||
trigger_rules: {
|
||||
|
||||
@@ -2,9 +2,60 @@ import { getters } from '../../campaigns';
|
||||
import campaigns from './fixtures';
|
||||
|
||||
describe('#getters', () => {
|
||||
it('getCampaigns', () => {
|
||||
it('get ongoing campaigns', () => {
|
||||
const state = { records: campaigns };
|
||||
expect(getters.getCampaigns(state)).toEqual(campaigns);
|
||||
expect(getters.getCampaigns(state)('ongoing')).toEqual([
|
||||
{
|
||||
id: 1,
|
||||
title: 'Welcome',
|
||||
description: null,
|
||||
account_id: 1,
|
||||
campaign_type: 'ongoing',
|
||||
message: 'Hey, What brings you today',
|
||||
enabled: true,
|
||||
trigger_rules: {
|
||||
url: 'https://github.com',
|
||||
time_on_page: 10,
|
||||
},
|
||||
created_at: '2021-05-03T04:53:36.354Z',
|
||||
updated_at: '2021-05-03T04:53:36.354Z',
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
title: 'Thanks',
|
||||
description: null,
|
||||
account_id: 1,
|
||||
campaign_type: 'ongoing',
|
||||
message: 'Thanks for coming to the show. How may I help you?',
|
||||
enabled: false,
|
||||
trigger_rules: {
|
||||
url: 'https://noshow.com',
|
||||
time_on_page: 10,
|
||||
},
|
||||
created_at: '2021-05-03T10:22:51.025Z',
|
||||
updated_at: '2021-05-03T10:22:51.025Z',
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('get one_off campaigns', () => {
|
||||
const state = { records: campaigns };
|
||||
expect(getters.getCampaigns(state)('one_off')).toEqual([
|
||||
{
|
||||
id: 2,
|
||||
title: 'Onboarding Campaign',
|
||||
description: null,
|
||||
account_id: 1,
|
||||
campaign_type: 'one_off',
|
||||
|
||||
trigger_rules: {
|
||||
url: 'https://chatwoot.com',
|
||||
time_on_page: '20',
|
||||
},
|
||||
created_at: '2021-05-03T08:15:35.828Z',
|
||||
updated_at: '2021-05-03T08:15:35.828Z',
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('getUIFlags', () => {
|
||||
|
||||
@@ -43,4 +43,16 @@ export default [
|
||||
website_token: 'randomid125',
|
||||
enable_auto_assignment: true,
|
||||
},
|
||||
{
|
||||
id: 5,
|
||||
channel_id: 5,
|
||||
name: 'Test Widget 5',
|
||||
channel_type: 'Channel::TwilioSms',
|
||||
avatar_url: null,
|
||||
page_id: null,
|
||||
widget_color: '#68BC00',
|
||||
website_token: 'randomid125',
|
||||
enable_auto_assignment: true,
|
||||
},
|
||||
|
||||
];
|
||||
|
||||
@@ -14,6 +14,11 @@ describe('#getters', () => {
|
||||
expect(getters.getWebsiteInboxes(state).length).toEqual(3);
|
||||
});
|
||||
|
||||
it('getTwilioInboxes', () => {
|
||||
const state = { records: inboxList };
|
||||
expect(getters.getTwilioInboxes(state).length).toEqual(1);
|
||||
});
|
||||
|
||||
it('getInbox', () => {
|
||||
const state = {
|
||||
records: inboxList,
|
||||
|
||||
Reference in New Issue
Block a user