2021-05-17 16:08:35 +00:00
|
|
|
export const stripTrailingSlash = ({ URL }) => {
|
|
|
|
return URL.replace(/\/$/, '');
|
|
|
|
};
|
|
|
|
|
|
|
|
// Format all campaigns
|
2021-05-18 06:45:23 +00:00
|
|
|
export const formatCampaigns = ({ campaigns }) => {
|
|
|
|
return campaigns.map(item => {
|
2021-05-17 16:08:35 +00:00
|
|
|
return {
|
|
|
|
id: item.id,
|
2021-10-12 12:28:33 +00:00
|
|
|
triggerOnlyDuringBusinessHours:
|
|
|
|
item.trigger_only_during_business_hours || false,
|
2021-05-17 16:08:35 +00:00
|
|
|
timeOnPage: item?.trigger_rules?.time_on_page,
|
|
|
|
url: item?.trigger_rules?.url,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2021-10-12 12:28:33 +00:00
|
|
|
// Filter all campaigns based on current URL and business availability time
|
|
|
|
export const filterCampaigns = ({
|
|
|
|
campaigns,
|
|
|
|
currentURL,
|
|
|
|
isInBusinessHours,
|
|
|
|
}) => {
|
2021-11-22 18:02:17 +00:00
|
|
|
return campaigns.filter(campaign => {
|
|
|
|
const hasMatchingURL =
|
|
|
|
stripTrailingSlash({ URL: campaign.url }) ===
|
|
|
|
stripTrailingSlash({ URL: currentURL });
|
|
|
|
if (!hasMatchingURL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (campaign.triggerOnlyDuringBusinessHours) {
|
|
|
|
return isInBusinessHours;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
2021-05-17 16:08:35 +00:00
|
|
|
};
|