Files
web/apps/scandic-web/components/HotelReservation/SelectHotel/index.tsx
Matilda Landström 93a90bef9d Merged in feat/SW-2038-static-map-button (pull request #2715)
feat(SW-2038): refactor and create wrapper for static map and button

* feat(SW-2038): refactor and create wrapper for static map and button

* feature: use button from design-system over creating a new one

* remove unused fragment

* fix(SW-2038): add removed css

* fix(SW-2038): update fake button component

* fix(SW-2038): move FakeButton to design system


Approved-by: Erik Tiekstra
Approved-by: Joakim Jäderberg
2025-09-01 08:16:27 +00:00

124 lines
4.2 KiB
TypeScript

import BookingCodeFilter from "@scandic-hotels/booking-flow/BookingCodeFilter"
import Link from "@scandic-hotels/design-system/Link"
import { Typography } from "@scandic-hotels/design-system/Typography"
import HotelCardListing from "@/components/HotelReservation/HotelCardListing"
import HotelFilter from "@/components/HotelReservation/SelectHotel/Filters/HotelFilter"
import HotelCount from "@/components/HotelReservation/SelectHotel/HotelCount"
import HotelSorter from "@/components/HotelReservation/SelectHotel/HotelSorter"
import MobileMapButtonContainer from "@/components/HotelReservation/SelectHotel/MobileMapButtonContainer"
import NoAvailabilityAlert from "@/components/HotelReservation/SelectHotel/NoAvailabilityAlert"
import { MapWithButtonWrapper } from "@/components/Maps/MapWithButtonWrapper"
import StaticMap from "@/components/Maps/StaticMap"
import { getFiltersFromHotels, type HotelResponse } from "./helpers"
import styles from "./selectHotel.module.css"
import type { Location } from "@scandic-hotels/trpc/types/locations"
interface SelectHotelProps {
isAlternative?: boolean
bookingCode?: string
city: Location
hotels: HotelResponse[]
isBookingCodeRateAvailable?: boolean
mapHref: string
title: string
}
export default async function SelectHotel({
bookingCode,
city,
hotels,
isAlternative = false,
isBookingCodeRateAvailable = false,
mapHref,
title,
}: SelectHotelProps) {
const isAllUnavailable = hotels.every(
(hotel) => hotel.availability.status !== "Available"
)
const isCityWithCountry = (city: any): city is { country: string } =>
"country" in city
// Special rates (corporate cheque, voucher) will not have regular rate hotels availability
const isSpecialRate = hotels.some(
(hotel) =>
hotel.availability.productType?.bonusCheque ||
hotel.availability.productType?.voucher
)
const filterList = getFiltersFromHotels(hotels)
const showBookingCodeFilter = isBookingCodeRateAvailable && !isSpecialRate
return (
<>
<header className={styles.header}>
<div className={styles.headerContent}>
<div className={styles.title}>
<div className={styles.cityInformation}>
<Typography variant="Title/Subtitle/lg">
<p>{title}</p>
</Typography>
<HotelCount />
</div>
<div className={styles.sorter}>
<HotelSorter discreet />
</div>
</div>
<MobileMapButtonContainer filters={filterList} />
</div>
</header>
<main className={styles.main}>
{showBookingCodeFilter ? <BookingCodeFilter /> : null}
<div className={styles.sideBar}>
{hotels.length ? (
<Link className={styles.link} href={mapHref} keepSearchParams>
<MapWithButtonWrapper>
<StaticMap
city={city.name}
country={isCityWithCountry(city) ? city.country : undefined}
width={340}
height={200}
zoomLevel={11}
mapType="roadmap"
altText={`Map of ${city.name} city center`}
/>
</MapWithButtonWrapper>
</Link>
) : (
<div className={styles.mapContainer}>
<StaticMap
city={city.name}
width={340}
height={200}
zoomLevel={11}
mapType="roadmap"
altText={`Map of ${city.name} city center`}
/>
</div>
)}
<HotelFilter filters={filterList} className={styles.filter} />
</div>
<div className={styles.hotelList}>
<NoAvailabilityAlert
hotelsLength={hotels.length}
isAlternative={isAlternative}
isAllUnavailable={isAllUnavailable}
operaId={hotels?.[0]?.hotel.operaId}
bookingCode={bookingCode}
isBookingCodeRateNotAvailable={!isBookingCodeRateAvailable}
/>
<HotelCardListing
hotelData={hotels}
isAlternative={isAlternative}
unfilteredHotelCount={hotels.length}
/>
</div>
</main>
</>
)
}