feat(BOOK-67): Added functionality to show/hide the chatbot

Approved-by: Linus Flood
This commit is contained in:
Erik Tiekstra
2025-10-16 10:59:47 +00:00
parent 69a1b5f213
commit 800df0ade9
13 changed files with 147 additions and 72 deletions

View File

@@ -0,0 +1,42 @@
import {
removeMultipleSlashes,
removeTrailingSlash,
} from "@scandic-hotels/common/utils/url"
import { CHATBOT_HIDE_CONDITIONS, CHATBOT_SHOW_ROUTES } from "./constants"
import type { Lang } from "@scandic-hotels/common/constants/language"
export function shouldShowChatbot(
pathname: string,
searchParams: URLSearchParams | null,
lang: Lang
): boolean {
const cleanPathname = removeTrailingSlash(removeMultipleSlashes(pathname))
const isOnShowRoute = CHATBOT_SHOW_ROUTES[lang].some((route) => {
const fullRoute = removeTrailingSlash(
removeMultipleSlashes(`/${lang}${route}`)
)
return cleanPathname.startsWith(fullRoute)
})
const isOnStartPage = cleanPathname === `/${lang}`
if (!isOnShowRoute && !isOnStartPage) {
return false
}
if (searchParams) {
const shouldHideOnSearchParams = CHATBOT_HIDE_CONDITIONS.searchParams.some(
({ key, value }) => {
const paramValue = searchParams.get(key)
return paramValue === value
}
)
if (shouldHideOnSearchParams) {
return false
}
}
return true
}