From d492b5ad6a368d379b378e23d3915dcd410c8541 Mon Sep 17 00:00:00 2001 From: Erik Tiekstra Date: Mon, 16 Jun 2025 12:33:38 +0000 Subject: [PATCH] feat(SW-2719): Added Dialogshift chat widget to certain hotel pages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Approved-by: Matilda Landström --- .../HotelPage/DialogshiftWidget/Client.tsx | 46 +++++++++++++++++++ .../HotelPage/DialogshiftWidget/index.tsx | 40 ++++++++++++++++ .../ContentType/HotelPage/index.tsx | 4 ++ apps/scandic-web/package.json | 1 + yarn.lock | 8 ++++ 5 files changed, 99 insertions(+) create mode 100644 apps/scandic-web/components/ContentType/HotelPage/DialogshiftWidget/Client.tsx create mode 100644 apps/scandic-web/components/ContentType/HotelPage/DialogshiftWidget/index.tsx diff --git a/apps/scandic-web/components/ContentType/HotelPage/DialogshiftWidget/Client.tsx b/apps/scandic-web/components/ContentType/HotelPage/DialogshiftWidget/Client.tsx new file mode 100644 index 000000000..a4d588456 --- /dev/null +++ b/apps/scandic-web/components/ContentType/HotelPage/DialogshiftWidget/Client.tsx @@ -0,0 +1,46 @@ +"use client" + +import "dialogshift-webchat-sdk/bundles/dialogshift-webchat-sdk.min.css" + +import { useEffect, useRef } from "react" + +import type { Lang } from "@/constants/languages" + +interface DialogshiftWidgetClientProps { + widgetId: string + language: Lang +} + +export default function DialogshiftWidgetClient({ + widgetId, + language, +}: DialogshiftWidgetClientProps) { + const dialogshiftRef = useRef(null) + + useEffect(() => { + const loadDialogshift = async () => { + try { + dialogshiftRef.current = await import("dialogshift-webchat-sdk") + dialogshiftRef.current.instance({ + id: widgetId, + locale: language, + }) + } catch (error) { + console.error("Failed to load Dialogshift chat:", error) + } + } + + if (!dialogshiftRef.current) { + loadDialogshift() + } + + return () => { + if (dialogshiftRef.current?.instance) { + dialogshiftRef.current.instance().destroy() + dialogshiftRef.current = null + } + } + }, [widgetId, language]) + + return null +} diff --git a/apps/scandic-web/components/ContentType/HotelPage/DialogshiftWidget/index.tsx b/apps/scandic-web/components/ContentType/HotelPage/DialogshiftWidget/index.tsx new file mode 100644 index 000000000..1f4d0c883 --- /dev/null +++ b/apps/scandic-web/components/ContentType/HotelPage/DialogshiftWidget/index.tsx @@ -0,0 +1,40 @@ +import { getLang } from "@/i18n/serverContext" + +import DialogshiftWidgetClient from "./Client" + +interface DialogshiftWidgetProps { + hotelId: string +} + +const DIALOG_SHIFT_WIDGET_IDS = [ + { + hotelName: "Scandic Berlin Kurfürstendamm", + hotelId: "554", + widgetId: "pro1dbe", + }, + { + hotelName: "Scandic Berlin Potsdamer Platz", + hotelId: "551", + widgetId: "pro2363", + }, + { + hotelName: "Scandic Hamburg Emporio", + hotelId: "550", + widgetId: "pro219b", + }, +] + +export default async function DialogshiftWidget({ + hotelId, +}: DialogshiftWidgetProps) { + const lang = await getLang() + const widgetId = DIALOG_SHIFT_WIDGET_IDS.find( + (item) => item.hotelId === hotelId + )?.widgetId + + if (!widgetId) { + return null + } + + return +} diff --git a/apps/scandic-web/components/ContentType/HotelPage/index.tsx b/apps/scandic-web/components/ContentType/HotelPage/index.tsx index 4653135bf..a169a76f6 100644 --- a/apps/scandic-web/components/ContentType/HotelPage/index.tsx +++ b/apps/scandic-web/components/ContentType/HotelPage/index.tsx @@ -31,6 +31,7 @@ import RestaurantBarSidePeek from "./SidePeeks/RestaurantBar" import RoomSidePeek from "./SidePeeks/Room" import WellnessAndExerciseSidePeek from "./SidePeeks/WellnessAndExercise" import AmenitiesList from "./AmenitiesList" +import DialogshiftWidget from "./DialogshiftWidget" import Facilities from "./Facilities" import IntroSection from "./IntroSection" import PreviewImages from "./PreviewImages" @@ -287,6 +288,9 @@ export default async function HotelPage({ hotelId }: HotelPageProps) { ))} + + +