Files
web/apps/scandic-web/components/HotelReservation/SelectRate/index.tsx
Anton Gunnarsson 87402a2092 Merged in feat/sw-2873-move-selecthotel-to-booking-flow (pull request #2727)
feat(SW-2873): Move select-hotel to booking flow

* crude setup of select-hotel in partner-sas

* wip

* Fix linting

* restructure tracking files

* Remove dependency on trpc in tracking hooks

* Move pageview tracking to common

* Fix some lint and import issues

* Add AlternativeHotelsPage

* Add SelectHotelMapPage

* Add AlternativeHotelsMapPage

* remove next dependency in tracking store

* Remove dependency on react in tracking hooks

* move isSameBooking to booking-flow

* Inject searchParamsComparator into tracking store

* Move useTrackHardNavigation to common

* Move useTrackSoftNavigation to common

* Add TrackingSDK to partner-sas

* call serverclient in layout

* Remove unused css

* Update types

* Move HotelPin type

* Fix todos

* Merge branch 'master' into feat/sw-2873-move-selecthotel-to-booking-flow

* Merge branch 'master' into feat/sw-2873-move-selecthotel-to-booking-flow

* Fix component


Approved-by: Joakim Jäderberg
2025-09-01 08:37:00 +00:00

104 lines
3.2 KiB
TypeScript

import { cookies } from "next/headers"
import FnFNotAllowedAlert from "@scandic-hotels/booking-flow/components/FnFNotAllowedAlert"
import { HotelDetailsSidePeek } from "@scandic-hotels/booking-flow/components/HotelDetailsSidePeek"
import { FamilyAndFriendsCodes } from "@scandic-hotels/common/constants/familyAndFriends"
import { dt } from "@scandic-hotels/common/dt"
import { HotelInfoCard } from "@scandic-hotels/design-system/HotelInfoCard"
import { RoomsContainer } from "@/components/HotelReservation/SelectRate/RoomsContainer"
import { getIntl } from "@/i18n"
import { mapApiImagesToGalleryImages } from "@/utils/imageGallery"
import { hasOverlappingDates } from "../utils"
import AvailabilityError from "./AvailabilityError"
import Tracking from "./Tracking"
import type { RouterOutput } from "@scandic-hotels/trpc/client"
import type { SelectRateBooking } from "@/types/components/hotelReservation/selectRate/selectRate"
export default async function SelectRatePage({
booking,
hotelData,
}: {
hotelData: NonNullable<RouterOutput["hotel"]["get"]>
booking: SelectRateBooking
}) {
const intl = await getIntl()
const bookingCode = booking.bookingCode
let isInValidFNF = false
if (bookingCode && FamilyAndFriendsCodes.includes(bookingCode)) {
const cookieStore = await cookies()
isInValidFNF = cookieStore.get("sc")?.value !== "1"
}
const validAlerts = hotelData.hotel.specialAlerts.filter((alert) =>
hasOverlappingDates(alert, dt(booking.fromDate), dt(booking.toDate))
)
return (
<>
<HotelInfoCard
hotel={{
id: hotelData.hotel.id,
name: hotelData.hotel.name,
url: hotelData.url,
ratings: hotelData.hotel.ratings,
}}
address={{
streetAddress: hotelData.hotel.address.streetAddress,
city: hotelData.hotel.address.city,
kilometersToCentre: hotelData.hotel.location.distanceToCentre / 1000,
}}
galleryImages={mapApiImagesToGalleryImages(
hotelData.hotel.galleryImages
)}
description={
hotelData.hotel.hotelContent.texts.descriptions?.medium ?? ""
}
alerts={validAlerts.map((alert) => ({
...alert,
heading: alert.heading ?? "",
text: alert.text ?? "",
}))}
facilities={hotelData.hotel.detailedFacilities}
slot={
<HotelDetailsSidePeek
hotel={{
...hotelData.hotel,
url: hotelData.url,
}}
restaurants={hotelData.restaurants}
additionalHotelData={hotelData.additionalData}
triggerLabel={intl.formatMessage({
defaultMessage: "See all amenities",
})}
buttonVariant="primary"
/>
}
/>
{isInValidFNF ? (
<FnFNotAllowedAlert />
) : (
<RoomsContainer
hotelType={hotelData.hotel.hotelType}
roomCategories={hotelData.roomCategories}
vat={hotelData.hotel.vat}
/>
)}
<Tracking
hotelId={hotelData.hotel.id}
hotelName={hotelData.hotel.name}
country={hotelData.hotel.address.country}
city={hotelData.hotel.address.city}
/>
<AvailabilityError />
</>
)
}