diff --git a/packages/booking-flow/env/server.ts b/packages/booking-flow/env/server.ts index c82a5c942..4be83b5bd 100644 --- a/packages/booking-flow/env/server.ts +++ b/packages/booking-flow/env/server.ts @@ -9,12 +9,14 @@ export const env = createEnv({ */ isServer: typeof window === "undefined" || "Deno" in window, server: { + PUBLIC_URL: z.string().default(""), GOOGLE_STATIC_MAP_KEY: z.string(), GOOGLE_STATIC_MAP_SIGNATURE_SECRET: z.string(), GOOGLE_DYNAMIC_MAP_ID: z.string(), }, emptyStringAsUndefined: true, runtimeEnv: { + PUBLIC_URL: process.env.NEXT_PUBLIC_PUBLIC_URL, GOOGLE_STATIC_MAP_KEY: process.env.GOOGLE_STATIC_MAP_KEY, GOOGLE_STATIC_MAP_SIGNATURE_SECRET: process.env.GOOGLE_STATIC_MAP_SIGNATURE_SECRET, diff --git a/packages/booking-flow/lib/components/BookingConfirmation/Confirmation/index.tsx b/packages/booking-flow/lib/components/BookingConfirmation/Confirmation/index.tsx index e897970ab..aa9914272 100644 --- a/packages/booking-flow/lib/components/BookingConfirmation/Confirmation/index.tsx +++ b/packages/booking-flow/lib/components/BookingConfirmation/Confirmation/index.tsx @@ -10,13 +10,16 @@ import type { BookingConfirmation } from "@scandic-hotels/trpc/types/bookingConf import type { BookingConfirmationRoom } from "../../../types/components/bookingConfirmation/bookingConfirmation" -interface ConfirmationProps - extends Pick { +interface ConfirmationProps extends Pick< + BookingConfirmation, + "booking" | "hotel" | "url" +> { room: BookingConfirmationRoom } export function Confirmation({ booking, + url, hotel, children, }: React.PropsWithChildren) { @@ -24,7 +27,7 @@ export function Confirmation({ return (
-
+
{children}
) diff --git a/packages/booking-flow/lib/components/BookingConfirmation/Header/index.tsx b/packages/booking-flow/lib/components/BookingConfirmation/Header/index.tsx index 16db88090..5a18de93b 100644 --- a/packages/booking-flow/lib/components/BookingConfirmation/Header/index.tsx +++ b/packages/booking-flow/lib/components/BookingConfirmation/Header/index.tsx @@ -18,7 +18,7 @@ import type { MutableRefObject } from "react" interface BookingConfirmationHeaderProps extends Pick< BookingConfirmation, - "booking" | "hotel" + "booking" | "hotel" | "url" > { mainRef: MutableRefObject } @@ -26,6 +26,7 @@ interface BookingConfirmationHeaderProps extends Pick< export function Header({ booking, hotel, + url, // mainRef, }: BookingConfirmationHeaderProps) { const intl = useIntl() @@ -52,7 +53,7 @@ export function Header({ startInputType: "utc", status: "CONFIRMED", title: hotel.name, - url: hotel.contactInformation.websiteUrl, + url: url ?? undefined, } return ( diff --git a/packages/booking-flow/lib/components/BookingConfirmation/HotelDetails/index.tsx b/packages/booking-flow/lib/components/BookingConfirmation/HotelDetails/index.tsx index e2ba7c7f8..51c2f0883 100644 --- a/packages/booking-flow/lib/components/BookingConfirmation/HotelDetails/index.tsx +++ b/packages/booking-flow/lib/components/BookingConfirmation/HotelDetails/index.tsx @@ -11,10 +11,13 @@ import type { BookingConfirmation } from "@scandic-hotels/trpc/types/bookingConf export function HotelDetails({ hotel, + url, }: { hotel: BookingConfirmation["hotel"] + url: string | null }) { const intl = useIntl() + return (
@@ -62,14 +65,16 @@ export function HotelDetails({ > {hotel.contactInformation.email} - - {hotel.contactInformation.websiteUrl} - + {url && ( + + {url} + + )}
) diff --git a/packages/booking-flow/lib/components/BookingConfirmation/index.tsx b/packages/booking-flow/lib/components/BookingConfirmation/index.tsx index 905417806..5683def73 100644 --- a/packages/booking-flow/lib/components/BookingConfirmation/index.tsx +++ b/packages/booking-flow/lib/components/BookingConfirmation/index.tsx @@ -7,6 +7,7 @@ import { Alert } from "@scandic-hotels/design-system/Alert" import { Divider } from "@scandic-hotels/design-system/Divider" import { HotelTypeEnum } from "@scandic-hotels/trpc/enums/hotelType" +import { env } from "../../../env/server" import { BookingConfirmationProvider } from "../../providers/BookingConfirmationProvider" import { getBookingConfirmation } from "../../trpc/memoizedRequests/getBookingConfirmation" import { SidePanel } from "../SidePanel" @@ -41,7 +42,10 @@ export async function BookingConfirmation({ return notFound() } - const { booking, hotel, room, roomCategories } = bookingConfirmation + const { booking, url, hotel, room, roomCategories } = bookingConfirmation + + const baseUrl = env.PUBLIC_URL || "https://www.scandichotels.com" + const hotelUrl = new URL(`${baseUrl}${url}`) if (!room) { return notFound() @@ -69,7 +73,12 @@ export async function BookingConfirmation({ ]} vat={booking.vatPercentage} > - +
{membershipFailedError && ( - + {validAlerts.map((alert) => (
page.hotelId === booking.hotelId ) if (!hotelData) { @@ -86,6 +93,7 @@ export const bookingQueryRouter = router({ return { ...hotelData, + url: hotelPage?.url || null, booking, room: getHotelRoom(hotelData.roomCategories, booking.roomTypeCode), } @@ -132,13 +140,19 @@ export const bookingQueryRouter = router({ return null } - const hotelData = await getHotel( - { - hotelId: booking.hotelId, - isCardOnlyPayment: false, - language: lang, - }, - serviceToken + const [hotelData, hotelPages] = await Promise.all([ + getHotel( + { + hotelId: booking.hotelId, + isCardOnlyPayment: false, + language: lang, + }, + serviceToken + ), + getHotelPageUrls(lang), + ]) + const hotelPage = hotelPages.find( + (page) => page.hotelId === booking.hotelId ) if (!hotelData) { @@ -156,6 +170,7 @@ export const bookingQueryRouter = router({ return { ...hotelData, + url: hotelPage?.url || null, booking, room: getHotelRoom(hotelData.roomCategories, booking.roomTypeCode), } diff --git a/packages/trpc/lib/types/bookingConfirmation.ts b/packages/trpc/lib/types/bookingConfirmation.ts index 637bd6074..dd0761bd9 100644 --- a/packages/trpc/lib/types/bookingConfirmation.ts +++ b/packages/trpc/lib/types/bookingConfirmation.ts @@ -6,12 +6,14 @@ import type { } from "../routers/booking/output" import type { HotelData, Room } from "./hotel" -export interface BookingConfirmationSchema - extends z.output {} +export interface BookingConfirmationSchema extends z.output< + typeof bookingConfirmationSchema +> {} export interface PackageSchema extends z.output {} export interface BookingConfirmation extends HotelData { + url: string | null booking: BookingConfirmationSchema room: | (Room & {