Feat/BOOK-424 campaign banner

Approved-by: Bianca Widstam
This commit is contained in:
Erik Tiekstra
2025-10-29 12:47:40 +00:00
parent 377c8886ad
commit 4c10989e8e
29 changed files with 1052 additions and 22 deletions

View 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
}