Chatwoot/app/javascript/widget/helpers/campaignTimer.js
Muhsin Keloth fb2f3ff89f
feat: Create campaign conversation only if user interacts with the bubble (#2335)
Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
2021-06-15 20:09:42 +05:30

24 lines
616 B
JavaScript

import store from '../store';
class CampaignTimer {
constructor() {
this.campaignTimers = [];
}
initTimers = ({ campaigns }) => {
this.clearTimers();
campaigns.forEach(campaign => {
const { timeOnPage, id: campaignId } = campaign;
this.campaignTimers[campaignId] = setTimeout(() => {
store.dispatch('campaign/startCampaign', { campaignId });
}, timeOnPage * 1000);
});
};
clearTimers = () => {
this.campaignTimers.forEach(timerId => {
clearTimeout(timerId);
this.campaignTimers[timerId] = null;
});
};
}
export default new CampaignTimer();