From 86331a6e10d5b2eb22ab3d86c5d3f44aabbe81ff Mon Sep 17 00:00:00 2001 From: Matilda Haneling Date: Tue, 30 Dec 2025 08:33:52 +0000 Subject: [PATCH] Merged in fix/book-607-fix-old-links-my-stay (pull request #3365) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix: updated to use new link structure on My Stay * fix: updated to use new link structure on My Stay * fix(BOOK-607): hide hotel page link if link prop is missing * comment fixes * fix(BOOK-607): read href from window (lcalhost not allowed) Approved-by: Matilda Landström --- .../MyStay/BookingSummary/index.tsx | 100 +++++++++--------- .../Actions/AddToCalendar/index.tsx | 17 ++- .../HotelReservation/MyStay/index.tsx | 3 +- apps/scandic-web/providers/MyStay.tsx | 1 + apps/scandic-web/stores/my-stay/index.ts | 2 + apps/scandic-web/types/stores/my-stay.ts | 21 ++-- 6 files changed, 80 insertions(+), 64 deletions(-) diff --git a/apps/scandic-web/components/HotelReservation/MyStay/BookingSummary/index.tsx b/apps/scandic-web/components/HotelReservation/MyStay/BookingSummary/index.tsx index 83c168a5a..d4ec3ca12 100644 --- a/apps/scandic-web/components/HotelReservation/MyStay/BookingSummary/index.tsx +++ b/apps/scandic-web/components/HotelReservation/MyStay/BookingSummary/index.tsx @@ -16,14 +16,64 @@ import type { Hotel } from "@scandic-hotels/trpc/types/hotel" interface BookingSummaryProps { hotel: Hotel + hotelUrl: string | null } -export default function BookingSummary({ hotel }: BookingSummaryProps) { +export default function BookingSummary({ + hotel, + hotelUrl, +}: BookingSummaryProps) { const intl = useIntl() const directionsUrl = `https://www.google.com/maps/dir/?api=1&destination=${encodeURIComponent( `${hotel.name}, ${hotel.address.streetAddress}, ${hotel.address.zipCode} ${hotel.address.city}` )}` + + const directionsLinkObject = { + href: directionsUrl, + text: intl.formatMessage({ + id: "common.directions", + defaultMessage: "Directions", + }), + icon: ( + + ), + onClick: () => trackMyStayPageLink("see on map"), + } + + const emailLinkObject = { + href: `mailto:${hotel.contactInformation.email}`, + text: intl.formatMessage({ + id: "common.email", + defaultMessage: "Email", + }), + icon: ( + + ), + onClick: () => trackMyStayPageLink("email us"), + } + + const hotelLinkObject = { + href: hotelUrl || "", + text: intl.formatMessage({ + id: "myStay.bookingSummary.homepage", + defaultMessage: "Homepage", + }), + icon: ( + + ), + onClick: () => trackMyStayPageLink("hotel homepage"), + } + + const links = [ + directionsLinkObject, + emailLinkObject, + ...(hotelUrl ? [hotelLinkObject] : []), // Only include hotel link if URL is provided + ] return (
@@ -59,53 +109,7 @@ export default function BookingSummary({ hotel }: BookingSummaryProps) { long: hotel.location.longitude, } )} - links={[ - { - href: directionsUrl, - text: intl.formatMessage({ - id: "common.directions", - defaultMessage: "Directions", - }), - icon: ( - - ), - onClick: () => trackMyStayPageLink("see on map"), - }, - { - href: `mailto:${hotel.contactInformation.email}`, - text: intl.formatMessage({ - id: "common.email", - defaultMessage: "Email", - }), - icon: ( - - ), - onClick: () => trackMyStayPageLink("email us"), - }, - { - href: hotel.contactInformation.websiteUrl, - text: intl.formatMessage({ - id: "myStay.bookingSummary.homepage", - defaultMessage: "Homepage", - }), - icon: ( - - ), - onClick: () => trackMyStayPageLink("hotel homepage"), - }, - ]} + links={links} />
{hotel.specialAlerts.map((alert) => ( diff --git a/apps/scandic-web/components/HotelReservation/MyStay/ReferenceCard/Actions/Upcoming/ManageStay/Actions/AddToCalendar/index.tsx b/apps/scandic-web/components/HotelReservation/MyStay/ReferenceCard/Actions/Upcoming/ManageStay/Actions/AddToCalendar/index.tsx index 59ce6bd5d..757d1f698 100644 --- a/apps/scandic-web/components/HotelReservation/MyStay/ReferenceCard/Actions/Upcoming/ManageStay/Actions/AddToCalendar/index.tsx +++ b/apps/scandic-web/components/HotelReservation/MyStay/ReferenceCard/Actions/Upcoming/ManageStay/Actions/AddToCalendar/index.tsx @@ -16,14 +16,21 @@ import type { EventAttributes } from "ics" export default function AddToCalendarAction() { const pathName = usePathname() - const { checkInDate, checkOutDate, createDateTime, hotel } = useMyStayStore( - (state) => ({ + const { checkInDate, checkOutDate, createDateTime, hotelUrl, hotel } = + useMyStayStore((state) => ({ checkInDate: state.bookedRoom.checkInDate, checkOutDate: state.bookedRoom.checkOutDate, createDateTime: state.bookedRoom.createDateTime, hotel: state.hotel, - }) - ) + hotelUrl: state.hotelUrl, + })) + let baseUrl = typeof window !== "undefined" ? window.location.hostname : "" + if (baseUrl.includes("localhost") || !baseUrl) { + // Localhost not valid for calendar URL + baseUrl = "https://www.scandichotels.com" + } + + const url = new URL(hotelUrl || "", baseUrl) const calendarEvent: EventAttributes = { busyStatus: "FREE", @@ -41,7 +48,7 @@ export default function AddToCalendarAction() { startInputType: "utc", status: "CONFIRMED", title: hotel.name, - url: hotel.contactInformation.websiteUrl, + url: url.toString(), } const disabled = dateHasPassed( diff --git a/apps/scandic-web/components/HotelReservation/MyStay/index.tsx b/apps/scandic-web/components/HotelReservation/MyStay/index.tsx index 7c82005cb..68a6d1e08 100644 --- a/apps/scandic-web/components/HotelReservation/MyStay/index.tsx +++ b/apps/scandic-web/components/HotelReservation/MyStay/index.tsx @@ -191,6 +191,7 @@ async function MyStay(props: { const baseUrl = env.PUBLIC_URL || "https://www.scandichotels.com" const promoUrl = new URL(`${baseUrl}/${lang}/`) + const hotelUrl = new URL(`${baseUrl}${bookingConfirmation.url}/`) promoUrl.searchParams.set("hotel", hotel.operaId) @@ -263,7 +264,7 @@ async function MyStay(props: { - + {!isWebview && ( { +export interface InitialState extends Pick< + MyStayState, + | "breakfastPackages" + | "hotel" + | "refId" + | "savedCreditCards" + | "isLoggedIn" + | "isPastBooking" +> { intl: IntlShape roomCategories: RoomCategories rooms: BookingRoom[] + hotelUrl: string | null }