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,
|
|
|
|
}) => {
|
|
|
|
return campaigns.filter(item =>
|
|
|
|
item.triggerOnlyDuringBusinessHours
|
|
|
|
? isInBusinessHours
|
|
|
|
: stripTrailingSlash({ URL: item.url }) ===
|
|
|
|
stripTrailingSlash({ URL: currentURL })
|
2021-05-17 16:08:35 +00:00
|
|
|
);
|
|
|
|
};
|