feat(SW-176): use the availability endpoint
This commit is contained in:
@@ -1,11 +1,11 @@
|
|||||||
import { serverClient } from "@/lib/trpc/server"
|
import { serverClient } from "@/lib/trpc/server"
|
||||||
import tempHotelData from "@/server/routers/hotels/tempHotelData.json"
|
|
||||||
|
|
||||||
import HotelCard from "@/components/HotelReservation/HotelCard"
|
import HotelCard from "@/components/HotelReservation/HotelCard"
|
||||||
import HotelFilter from "@/components/HotelReservation/SelectHotel/HotelFilter"
|
import HotelFilter from "@/components/HotelReservation/SelectHotel/HotelFilter"
|
||||||
import { ChevronRightIcon } from "@/components/Icons"
|
import { ChevronRightIcon } from "@/components/Icons"
|
||||||
import StaticMap from "@/components/Maps/StaticMap"
|
import StaticMap from "@/components/Maps/StaticMap"
|
||||||
import Link from "@/components/TempDesignSystem/Link"
|
import Link from "@/components/TempDesignSystem/Link"
|
||||||
|
import Title from "@/components/TempDesignSystem/Text/Title"
|
||||||
import { getIntl } from "@/i18n"
|
import { getIntl } from "@/i18n"
|
||||||
import { setLang } from "@/i18n/serverContext"
|
import { setLang } from "@/i18n/serverContext"
|
||||||
|
|
||||||
@@ -19,10 +19,7 @@ export default async function SelectHotelPage({
|
|||||||
const intl = await getIntl()
|
const intl = await getIntl()
|
||||||
setLang(params.lang)
|
setLang(params.lang)
|
||||||
|
|
||||||
// TODO: Use real endpoint.
|
|
||||||
const tempSearchTerm = "Stockholm"
|
const tempSearchTerm = "Stockholm"
|
||||||
const hotel = tempHotelData.data.attributes
|
|
||||||
const hotels = [hotel]
|
|
||||||
|
|
||||||
const hotelFilters = await serverClient().hotel.filters.get({
|
const hotelFilters = await serverClient().hotel.filters.get({
|
||||||
hotelId: "879",
|
hotelId: "879",
|
||||||
@@ -30,16 +27,14 @@ export default async function SelectHotelPage({
|
|||||||
|
|
||||||
const availability = await serverClient().hotel.availability.get({
|
const availability = await serverClient().hotel.availability.get({
|
||||||
cityId: "8ec4bba3-1c38-4606-82d1-bbe3f6738e54",
|
cityId: "8ec4bba3-1c38-4606-82d1-bbe3f6738e54",
|
||||||
roomStayStartDate: "2024-11-01",
|
roomStayStartDate: "2024-11-02",
|
||||||
roomStayEndDate: "2024-11-02",
|
roomStayEndDate: "2024-11-03",
|
||||||
adults: 1,
|
adults: 1,
|
||||||
})
|
})
|
||||||
|
|
||||||
const filterAvailability = availability?.availability.data.filter(
|
const filterAvailability = availability?.availability.data
|
||||||
(hotels) => hotels.attributes.status === "Available"
|
.filter((hotels) => hotels.attributes.status === "Available")
|
||||||
)
|
.flatMap((hotels) => hotels.attributes)
|
||||||
|
|
||||||
console.log(filterAvailability)
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main className={styles.main}>
|
<main className={styles.main}>
|
||||||
@@ -58,9 +53,19 @@ export default async function SelectHotelPage({
|
|||||||
<HotelFilter filters={hotelFilters} />
|
<HotelFilter filters={hotelFilters} />
|
||||||
</section>
|
</section>
|
||||||
<section className={styles.hotelCards}>
|
<section className={styles.hotelCards}>
|
||||||
{hotels.map((hotel) => (
|
{filterAvailability?.length ? (
|
||||||
<HotelCard key={hotel.name} hotel={hotel} />
|
filterAvailability.map((hotel) => (
|
||||||
))}
|
<HotelCard
|
||||||
|
key={hotel.hotelId}
|
||||||
|
checkInDate={hotel.checkInDate}
|
||||||
|
checkOutDate={hotel.checkOutDate}
|
||||||
|
hotelId={hotel.hotelId}
|
||||||
|
price={hotel.bestPricePerNight}
|
||||||
|
/>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<Title>No hotels found</Title>
|
||||||
|
)}
|
||||||
</section>
|
</section>
|
||||||
</main>
|
</main>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -77,6 +77,7 @@
|
|||||||
"image header"
|
"image header"
|
||||||
"image hotel"
|
"image hotel"
|
||||||
"image prices";
|
"image prices";
|
||||||
|
grid-template-columns: 518px;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
width: 1050px;
|
width: 1050px;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { serverClient } from "@/lib/trpc/server"
|
||||||
|
|
||||||
import { mapFacilityToIcon } from "@/components/ContentType/HotelPage/data"
|
import { mapFacilityToIcon } from "@/components/ContentType/HotelPage/data"
|
||||||
import {
|
import {
|
||||||
ChevronRightIcon,
|
ChevronRightIcon,
|
||||||
@@ -13,15 +15,28 @@ import Caption from "@/components/TempDesignSystem/Text/Caption"
|
|||||||
import Footnote from "@/components/TempDesignSystem/Text/Footnote"
|
import Footnote from "@/components/TempDesignSystem/Text/Footnote"
|
||||||
import Title from "@/components/TempDesignSystem/Text/Title"
|
import Title from "@/components/TempDesignSystem/Text/Title"
|
||||||
import { getIntl } from "@/i18n"
|
import { getIntl } from "@/i18n"
|
||||||
|
import { getLang } from "@/i18n/serverContext"
|
||||||
|
|
||||||
import styles from "./hotelCard.module.css"
|
import styles from "./hotelCard.module.css"
|
||||||
|
|
||||||
import { HotelCardProps } from "@/types/components/hotelReservation/selectHotel/hotelCardProps"
|
import { HotelCardProps } from "@/types/components/hotelReservation/selectHotel/hotelCardProps"
|
||||||
|
|
||||||
export default async function HotelCard({ hotel }: HotelCardProps) {
|
export default async function HotelCard({
|
||||||
|
checkInDate,
|
||||||
|
checkOutDate,
|
||||||
|
hotelId,
|
||||||
|
price,
|
||||||
|
}: HotelCardProps) {
|
||||||
const intl = await getIntl()
|
const intl = await getIntl()
|
||||||
|
|
||||||
const sortedAmenities = hotel.detailedFacilities
|
const hotelData = await serverClient().hotel.get({
|
||||||
|
hotelId: hotelId.toString(),
|
||||||
|
language: getLang(),
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!hotelData) return null
|
||||||
|
|
||||||
|
const sortedAmenities = hotelData.hotel.detailedFacilities
|
||||||
.sort((a, b) => b.sortOrder - a.sortOrder)
|
.sort((a, b) => b.sortOrder - a.sortOrder)
|
||||||
.slice(0, 5)
|
.slice(0, 5)
|
||||||
|
|
||||||
@@ -29,8 +44,8 @@ export default async function HotelCard({ hotel }: HotelCardProps) {
|
|||||||
<article className={styles.card}>
|
<article className={styles.card}>
|
||||||
<section className={styles.imageContainer}>
|
<section className={styles.imageContainer}>
|
||||||
<Image
|
<Image
|
||||||
src={hotel.hotelContent.images.imageSizes.large}
|
src={hotelData.hotel.hotelContent.images.imageSizes.large}
|
||||||
alt={hotel.hotelContent.images.metaData.altText}
|
alt={hotelData.hotel.hotelContent.images.metaData.altText}
|
||||||
width={300}
|
width={300}
|
||||||
height={200}
|
height={200}
|
||||||
className={styles.image}
|
className={styles.image}
|
||||||
@@ -38,25 +53,25 @@ export default async function HotelCard({ hotel }: HotelCardProps) {
|
|||||||
<div className={styles.tripAdvisor}>
|
<div className={styles.tripAdvisor}>
|
||||||
<Chip intent="primary" className={styles.tripAdvisor}>
|
<Chip intent="primary" className={styles.tripAdvisor}>
|
||||||
<TripAdvisorIcon color="white" />
|
<TripAdvisorIcon color="white" />
|
||||||
{hotel.ratings?.tripAdvisor.rating}
|
{hotelData.hotel.ratings?.tripAdvisor.rating}
|
||||||
</Chip>
|
</Chip>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
<section className={styles.hotelInformation}>
|
<section className={styles.hotelInformation}>
|
||||||
<ScandicLogoIcon color="red" />
|
<ScandicLogoIcon color="red" />
|
||||||
<Title as="h4" textTransform="capitalize">
|
<Title as="h4" textTransform="capitalize">
|
||||||
{hotel.name}
|
{hotelData.hotel.name}
|
||||||
</Title>
|
</Title>
|
||||||
<Footnote color="textMediumContrast" className={styles.adress}>
|
<Footnote color="textMediumContrast" className={styles.adress}>
|
||||||
{`${hotel.address.streetAddress}, ${hotel.address.city}`}
|
{`${hotelData.hotel.address.streetAddress}, ${hotelData.hotel.address.city}`}
|
||||||
</Footnote>
|
</Footnote>
|
||||||
<Footnote color="textMediumContrast">
|
<Footnote color="textMediumContrast">
|
||||||
{`${hotel.location.distanceToCentre} ${intl.formatMessage({ id: "km to city center" })}`}
|
{`${hotelData.hotel.location.distanceToCentre} ${intl.formatMessage({ id: "km to city center" })}`}
|
||||||
</Footnote>
|
</Footnote>
|
||||||
</section>
|
</section>
|
||||||
<section className={styles.hotel}>
|
<section className={styles.hotel}>
|
||||||
<div className={styles.facilities}>
|
<div className={styles.facilities}>
|
||||||
{sortedAmenities.map((facility) => {
|
{sortedAmenities?.map((facility) => {
|
||||||
const IconComponent = mapFacilityToIcon(facility.name)
|
const IconComponent = mapFacilityToIcon(facility.name)
|
||||||
return (
|
return (
|
||||||
<div className={styles.facilitiesItem} key={facility.id}>
|
<div className={styles.facilitiesItem} key={facility.id}>
|
||||||
@@ -77,7 +92,9 @@ export default async function HotelCard({ hotel }: HotelCardProps) {
|
|||||||
<PriceTagIcon color="white" width={15} height={15} />
|
<PriceTagIcon color="white" width={15} height={15} />
|
||||||
{intl.formatMessage({ id: "Public price from" })}
|
{intl.formatMessage({ id: "Public price from" })}
|
||||||
</Chip>
|
</Chip>
|
||||||
<Caption color="textMediumContrast">2820 SEK / night</Caption>
|
<Caption color="textMediumContrast">
|
||||||
|
{price?.regularAmount} SEK / night
|
||||||
|
</Caption>
|
||||||
<Footnote color="textMediumContrast">approx 280 eur</Footnote>
|
<Footnote color="textMediumContrast">approx 280 eur</Footnote>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
@@ -85,7 +102,9 @@ export default async function HotelCard({ hotel }: HotelCardProps) {
|
|||||||
<PriceTagIcon color="white" width={15} height={15} />
|
<PriceTagIcon color="white" width={15} height={15} />
|
||||||
{intl.formatMessage({ id: "Member price from" })}
|
{intl.formatMessage({ id: "Member price from" })}
|
||||||
</Chip>
|
</Chip>
|
||||||
<Caption color="textMediumContrast">2820 SEK / night</Caption>
|
<Caption color="textMediumContrast">
|
||||||
|
{price?.memberAmount} SEK / night
|
||||||
|
</Caption>
|
||||||
<Footnote color="textMediumContrast">approx 280 eur</Footnote>
|
<Footnote color="textMediumContrast">approx 280 eur</Footnote>
|
||||||
</div>
|
</div>
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
@@ -526,6 +526,9 @@ const availabilitySchema = z.object({
|
|||||||
})
|
})
|
||||||
|
|
||||||
export const getAvailabilitySchema = availabilitySchema
|
export const getAvailabilitySchema = availabilitySchema
|
||||||
|
export type Availability = z.infer<typeof availabilitySchema>
|
||||||
|
export type AvailabilityPrices =
|
||||||
|
Availability["data"][number]["attributes"]["bestPricePerNight"]
|
||||||
|
|
||||||
const flexibilityPrice = z.object({
|
const flexibilityPrice = z.object({
|
||||||
standard: z.number(),
|
standard: z.number(),
|
||||||
|
|||||||
@@ -1,3 +1,11 @@
|
|||||||
import { Hotel } from "@/types/hotel"
|
import {
|
||||||
|
Availability,
|
||||||
|
AvailabilityPrices,
|
||||||
|
} from "@/server/routers/hotels/output"
|
||||||
|
|
||||||
export type HotelCardProps = { hotel: Hotel }
|
export type HotelCardProps = {
|
||||||
|
checkInDate: Availability["data"][number]["attributes"]["checkInDate"]
|
||||||
|
checkOutDate: Availability["data"][number]["attributes"]["checkOutDate"]
|
||||||
|
hotelId: Availability["data"][number]["attributes"]["hotelId"]
|
||||||
|
price: AvailabilityPrices
|
||||||
|
}
|
||||||
|
|||||||
@@ -18,5 +18,3 @@ export type HotelTripAdvisor =
|
|||||||
| undefined
|
| undefined
|
||||||
|
|
||||||
export type RoomData = z.infer<typeof roomSchema>
|
export type RoomData = z.infer<typeof roomSchema>
|
||||||
|
|
||||||
export type Availability = z.infer<typeof getAvailabilitySchema>
|
|
||||||
|
|||||||
Reference in New Issue
Block a user