Files
web/apps/scandic-web/components/HotelReservation/SelectRate/index.tsx
Hrishikesh Vaipurkar 0a4bf40a15 Merged in chore/SW-3321-move-selectratecontext-to- (pull request #2729)
chore(SW-3321): Moved Select rate context to booking-flow package

* chore(SW-3321): Moved Select rate context to booking-flow package

* chore(SW-3321): Optimised code


Approved-by: Joakim Jäderberg
2025-09-02 07:40:01 +00:00

103 lines
3.3 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 { hasOverlappingDates } from "@scandic-hotels/booking-flow/utils/SelectRate"
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 AvailabilityError from "./AvailabilityError"
import Tracking from "./Tracking"
import type { SelectRateBooking } from "@scandic-hotels/booking-flow/types/components/selectRate/selectRate"
import type { RouterOutput } from "@scandic-hotels/trpc/client"
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 />
</>
)
}