feat: Show pre-chat form before triggering the campaign (#3215)

This commit is contained in:
Muhsin Keloth
2021-11-11 19:02:16 +05:30
committed by GitHub
parent 76370267f3
commit c6326993df
9 changed files with 175 additions and 26 deletions

View File

@@ -12,6 +12,7 @@ const state = {
hasFetched: false,
},
activeCampaign: {},
campaignHasExecuted: false,
};
const resetCampaignTimers = (
@@ -34,6 +35,7 @@ export const getters = {
getHasFetched: $state => $state.uiFlags.hasFetched,
getCampaigns: $state => $state.records,
getActiveCampaign: $state => $state.activeCampaign,
getCampaignHasExecuted: $state => $state.campaignHasExecuted,
};
export const actions = {
@@ -76,17 +78,37 @@ export const actions = {
);
}
},
startCampaign: async ({ commit }, { websiteToken, campaignId }) => {
const { data: campaigns } = await getCampaigns(websiteToken);
const campaign = campaigns.find(item => item.id === campaignId);
if (campaign) {
commit('setActiveCampaign', campaign);
startCampaign: async (
{
commit,
rootState: {
events: { isOpen },
},
},
{ websiteToken, campaignId }
) => {
// Disable campaign execution if widget is opened
if (!isOpen) {
const { data: campaigns } = await getCampaigns(websiteToken);
// Check campaign is disabled or not
const campaign = campaigns.find(item => item.id === campaignId);
if (campaign) {
commit('setActiveCampaign', campaign);
}
}
},
executeCampaign: async ({ commit }, { campaignId, websiteToken }) => {
try {
await triggerCampaign({ campaignId, websiteToken });
commit('setCampaignExecuted');
commit('setActiveCampaign', {});
} catch (error) {
commit('setError', true);
}
},
resetCampaign: async ({ commit }) => {
try {
commit('setActiveCampaign', {});
} catch (error) {
commit('setError', true);
@@ -107,6 +129,9 @@ export const mutations = {
setHasFetched($state, value) {
Vue.set($state.uiFlags, 'hasFetched', value);
},
setCampaignExecuted($state) {
Vue.set($state, 'campaignHasExecuted', true);
},
};
export default {