feat(BOOK-577): Added chatbot functionality for SE
Approved-by: Bianca Widstam
This commit is contained in:
@@ -4,7 +4,10 @@ import { usePathname, useSearchParams } from "next/navigation"
|
|||||||
import Script from "next/script"
|
import Script from "next/script"
|
||||||
import { useEffect } from "react"
|
import { useEffect } from "react"
|
||||||
|
|
||||||
import { shouldShowChatbot } from "@/components/ChatbotScript/utils"
|
import {
|
||||||
|
getChatbotKey,
|
||||||
|
shouldShowChatbot,
|
||||||
|
} from "@/components/ChatbotScript/utils"
|
||||||
import useLang from "@/hooks/useLang"
|
import useLang from "@/hooks/useLang"
|
||||||
|
|
||||||
interface ChatbotClientProps {
|
interface ChatbotClientProps {
|
||||||
@@ -15,10 +18,9 @@ export function ChatbotClient({ liveLangs }: ChatbotClientProps) {
|
|||||||
const lang = useLang()
|
const lang = useLang()
|
||||||
const pathname = usePathname()
|
const pathname = usePathname()
|
||||||
const searchParams = useSearchParams()
|
const searchParams = useSearchParams()
|
||||||
const currentLang = useLang()
|
const isLive = liveLangs.includes(lang)
|
||||||
const isLive = liveLangs.includes(currentLang)
|
const shouldShow = isLive && shouldShowChatbot(pathname, searchParams, lang)
|
||||||
const shouldShow =
|
const chatbotKey = getChatbotKey(lang)
|
||||||
isLive && shouldShowChatbot(pathname, searchParams, currentLang)
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
window.kindlyOptions = {
|
window.kindlyOptions = {
|
||||||
@@ -53,7 +55,7 @@ export function ChatbotClient({ liveLangs }: ChatbotClientProps) {
|
|||||||
<Script
|
<Script
|
||||||
id="kindly-chat"
|
id="kindly-chat"
|
||||||
src="https://chat.kindlycdn.com/kindly-chat.js"
|
src="https://chat.kindlycdn.com/kindly-chat.js"
|
||||||
data-bot-key="910bd27a-7472-43a1-bcfc-955b41adc3e7"
|
data-bot-key={chatbotKey}
|
||||||
data-shadow-dom
|
data-shadow-dom
|
||||||
data-bubble-hidden={!shouldShow}
|
data-bubble-hidden={!shouldShow}
|
||||||
data-language={lang}
|
data-language={lang}
|
||||||
|
|||||||
@@ -1,12 +1,8 @@
|
|||||||
import { Lang } from "@scandic-hotels/common/constants/language"
|
import { Lang } from "@scandic-hotels/common/constants/language"
|
||||||
|
|
||||||
export const CHATBOT_SHOW_ROUTES = {
|
export const CHATBOT_SHOW_ROUTES = {
|
||||||
[Lang.en]: [
|
[Lang.en]: ["/customer-service", "/scandic-friends", "/hotels"],
|
||||||
"/customer-service", // Customer service pages
|
[Lang.sv]: ["/kundservice", "/scandic-friends", "/hotell"],
|
||||||
"/scandic-friends", // My pages
|
|
||||||
"/hotels", // Hotel pages
|
|
||||||
],
|
|
||||||
[Lang.sv]: [],
|
|
||||||
[Lang.no]: [],
|
[Lang.no]: [],
|
||||||
[Lang.fi]: [],
|
[Lang.fi]: [],
|
||||||
[Lang.da]: [],
|
[Lang.da]: [],
|
||||||
@@ -21,7 +17,11 @@ export const CHATBOT_HIDE_CONDITIONS = {
|
|||||||
"/hotels/scandic-berlin-kurfurstendamm",
|
"/hotels/scandic-berlin-kurfurstendamm",
|
||||||
"/hotels/scandic-hamburg-emporio",
|
"/hotels/scandic-hamburg-emporio",
|
||||||
],
|
],
|
||||||
[Lang.sv]: [],
|
[Lang.sv]: [
|
||||||
|
"/hotell/scandic-berlin-potsdamer-platz",
|
||||||
|
"/hotell/scandic-berlin-kurfurstendamm",
|
||||||
|
"/hotell/scandic-hamburg-emporio",
|
||||||
|
],
|
||||||
[Lang.no]: [],
|
[Lang.no]: [],
|
||||||
[Lang.fi]: [],
|
[Lang.fi]: [],
|
||||||
[Lang.da]: [],
|
[Lang.da]: [],
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { Lang } from "@scandic-hotels/common/constants/language"
|
||||||
import {
|
import {
|
||||||
removeMultipleSlashes,
|
removeMultipleSlashes,
|
||||||
removeTrailingSlash,
|
removeTrailingSlash,
|
||||||
@@ -5,8 +6,6 @@ import {
|
|||||||
|
|
||||||
import { CHATBOT_HIDE_CONDITIONS, CHATBOT_SHOW_ROUTES } from "./constants"
|
import { CHATBOT_HIDE_CONDITIONS, CHATBOT_SHOW_ROUTES } from "./constants"
|
||||||
|
|
||||||
import type { Lang } from "@scandic-hotels/common/constants/language"
|
|
||||||
|
|
||||||
export function shouldShowChatbot(
|
export function shouldShowChatbot(
|
||||||
pathname: string,
|
pathname: string,
|
||||||
searchParams: URLSearchParams | null,
|
searchParams: URLSearchParams | null,
|
||||||
@@ -51,3 +50,17 @@ export function shouldShowChatbot(
|
|||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getChatbotKey(lang: Lang) {
|
||||||
|
switch (lang) {
|
||||||
|
case Lang.sv:
|
||||||
|
return "6008f930-ad4f-4fd2-8d7e-b58e65afe123"
|
||||||
|
case Lang.no:
|
||||||
|
case Lang.da:
|
||||||
|
case Lang.fi:
|
||||||
|
case Lang.de:
|
||||||
|
case Lang.en:
|
||||||
|
default:
|
||||||
|
return "910bd27a-7472-43a1-bcfc-955b41adc3e7"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user