Feat/BOOK-424 campaign banner
Approved-by: Bianca Widstam
This commit is contained in:
45
apps/scandic-web/components/CampaignBanner/utils.ts
Normal file
45
apps/scandic-web/components/CampaignBanner/utils.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { AlertTypeEnum } from "@scandic-hotels/common/constants/alert"
|
||||
import {
|
||||
removeMultipleSlashes,
|
||||
removeTrailingSlash,
|
||||
} from "@scandic-hotels/common/utils/url"
|
||||
|
||||
import { CAMPAIGN_BANNER_HIDE_CONDITIONS } from "@/components/CampaignBanner/constants"
|
||||
|
||||
import type { Lang } from "@scandic-hotels/common/constants/language"
|
||||
|
||||
export function shouldShowCampaignBanner(
|
||||
pathname: string,
|
||||
lang: Lang,
|
||||
closedPaths: Set<string>,
|
||||
sitewideAlertType: AlertTypeEnum | null
|
||||
): boolean {
|
||||
const cleanPathname = removeTrailingSlash(removeMultipleSlashes(pathname))
|
||||
|
||||
// Check if the banner should not be visible on the current path based on hide conditions.
|
||||
const isOnHideRoute = CAMPAIGN_BANNER_HIDE_CONDITIONS.routes[lang].some(
|
||||
(route) => {
|
||||
const fullRoute = removeTrailingSlash(
|
||||
removeMultipleSlashes(`/${lang}${route}`)
|
||||
)
|
||||
return cleanPathname === fullRoute
|
||||
}
|
||||
)
|
||||
|
||||
if (isOnHideRoute) {
|
||||
return false
|
||||
}
|
||||
|
||||
// The campaign banner should not be visible if there is an alarming sitewide alert
|
||||
if (sitewideAlertType === AlertTypeEnum.Alarm) {
|
||||
return false
|
||||
}
|
||||
|
||||
// Check if the user closed the banner and should therefore not be visible on the current path.
|
||||
// This is saved in a local state and is reset on page reload.
|
||||
if (closedPaths.has(pathname)) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
Reference in New Issue
Block a user