Chatwoot/app/javascript/widget/helpers/campaignHelper.js
Pranav Raj S 20a0d381a7
fix: Resolve infinite loop with campaign API call (#2290)
Co-authored-by: Muhsin <muhsinkeramam@gmail.com>
2021-05-18 12:15:23 +05:30

23 lines
590 B
JavaScript

export const stripTrailingSlash = ({ URL }) => {
return URL.replace(/\/$/, '');
};
// Format all campaigns
export const formatCampaigns = ({ campaigns }) => {
return campaigns.map(item => {
return {
id: item.id,
timeOnPage: item?.trigger_rules?.time_on_page,
url: item?.trigger_rules?.url,
};
});
};
// Find all campaigns that matches the current URL
export const filterCampaigns = ({ campaigns, currentURL }) => {
return campaigns.filter(
item =>
stripTrailingSlash({ URL: item.url }) ===
stripTrailingSlash({ URL: currentURL })
);
};