feat: Add campaigns in web widget (#2227)
* add campaign store(getter, actions and mutations) * add campaign store module * add get campaigns api * add fetch campaign action widget load * add specs * code cleanup * trigger campaig api fixes * integrate campaign trigger action * code cleanup * revert changes * trigger api fixes * review fixes * code beautification * chore: Fix multiple campaigns being send because of race condition * chore: rubocop * chore: Fix specs * disable campaigns Co-authored-by: Nithin David Thomas <webofnithin@gmail.com> Co-authored-by: Sojan <sojan@pepalo.com>
This commit is contained in:
23
app/javascript/widget/api/campaign.js
Normal file
23
app/javascript/widget/api/campaign.js
Normal file
@@ -0,0 +1,23 @@
|
||||
import endPoints from 'widget/api/endPoints';
|
||||
import { API } from 'widget/helpers/axios';
|
||||
|
||||
const getCampaigns = async websiteToken => {
|
||||
const urlData = endPoints.getCampaigns(websiteToken);
|
||||
const result = await API.get(urlData.url, { params: urlData.params });
|
||||
return result;
|
||||
};
|
||||
|
||||
const triggerCampaign = async ({ campaignId }) => {
|
||||
const { websiteToken } = window.chatwootWebChannel;
|
||||
const urlData = endPoints.triggerCampaign(websiteToken, campaignId);
|
||||
|
||||
await API.post(
|
||||
urlData.url,
|
||||
{ ...urlData.data },
|
||||
{
|
||||
params: urlData.params,
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
export { getCampaigns, triggerCampaign };
|
||||
Reference in New Issue
Block a user