feat(SW-251): use parallel fetch for hotels
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { serverClient } from "@/lib/trpc/server"
|
||||
import tempHotelData from "@/server/routers/hotels/tempHotelData.json"
|
||||
import { useIntl } from "react-intl"
|
||||
|
||||
import { mapFacilityToIcon } from "@/components/ContentType/HotelPage/data"
|
||||
import {
|
||||
@@ -15,43 +14,30 @@ import Link from "@/components/TempDesignSystem/Link"
|
||||
import Caption from "@/components/TempDesignSystem/Text/Caption"
|
||||
import Footnote from "@/components/TempDesignSystem/Text/Footnote"
|
||||
import Title from "@/components/TempDesignSystem/Text/Title"
|
||||
import { getIntl } from "@/i18n"
|
||||
import { getLang } from "@/i18n/serverContext"
|
||||
|
||||
import styles from "./hotelCard.module.css"
|
||||
|
||||
import { HotelCardProps } from "@/types/components/hotelReservation/selectHotel/hotelCardProps"
|
||||
|
||||
export default async function HotelCard({
|
||||
checkInDate,
|
||||
checkOutDate,
|
||||
hotelId,
|
||||
price,
|
||||
}: HotelCardProps) {
|
||||
const intl = await getIntl()
|
||||
export default function HotelCard({ hotel }: HotelCardProps) {
|
||||
const intl = useIntl()
|
||||
|
||||
// TODO: Use real endpoint.
|
||||
const hotel = tempHotelData.data.attributes
|
||||
const { hotelData } = hotel
|
||||
const { price } = hotel
|
||||
|
||||
const hotelResponse = await serverClient().hotel.hotel.get({
|
||||
hotelId: hotelId.toString(),
|
||||
language: getLang(),
|
||||
})
|
||||
if (!hotelData) return null
|
||||
if (!price) return null
|
||||
|
||||
if (!hotelResponse) return null
|
||||
|
||||
const { data } = hotelResponse
|
||||
|
||||
const sortedAmenities = data.attributes.detailedFacilities
|
||||
.sort((a, b) => b.sortOrder - a.sortOrder)
|
||||
const sortedAmenities = hotelData.detailedFacilities
|
||||
?.sort((a, b) => b.sortOrder - a.sortOrder)
|
||||
.slice(0, 5)
|
||||
|
||||
return (
|
||||
<article className={styles.card}>
|
||||
<section className={styles.imageContainer}>
|
||||
<Image
|
||||
src={data.attributes.hotelContent.images.imageSizes.large}
|
||||
alt={data.attributes.hotelContent.images.metaData.altText}
|
||||
src={hotelData.hotelContent.images.imageSizes.medium}
|
||||
alt={hotelData.hotelContent.images.metaData.altText}
|
||||
width={300}
|
||||
height={200}
|
||||
className={styles.image}
|
||||
@@ -59,25 +45,25 @@ export default async function HotelCard({
|
||||
<div className={styles.tripAdvisor}>
|
||||
<Chip intent="primary" className={styles.tripAdvisor}>
|
||||
<TripAdvisorIcon color="white" />
|
||||
{data.attributes.ratings?.tripAdvisor.rating}
|
||||
{hotelData.ratings?.tripAdvisor.rating}
|
||||
</Chip>
|
||||
</div>
|
||||
</section>
|
||||
<section className={styles.hotelInformation}>
|
||||
<ScandicLogoIcon color="red" />
|
||||
<Title as="h4" textTransform="capitalize">
|
||||
{hotel.name}
|
||||
{hotelData.name}
|
||||
</Title>
|
||||
<Footnote color="textMediumContrast" className={styles.adress}>
|
||||
{`${data.attributes.address.streetAddress}, ${data.attributes.address.city}`}
|
||||
{`${hotelData.address?.streetAddress}, ${hotelData.address?.city}`}
|
||||
</Footnote>
|
||||
<Footnote color="textMediumContrast">
|
||||
{`${data.attributes.location.distanceToCentre} ${intl.formatMessage({ id: "km to city center" })}`}
|
||||
{`${hotelData.location.distanceToCentre} ${intl.formatMessage({ id: "km to city center" })}`}
|
||||
</Footnote>
|
||||
</section>
|
||||
<section className={styles.hotel}>
|
||||
<div className={styles.facilities}>
|
||||
{sortedAmenities.map((facility) => {
|
||||
{sortedAmenities?.map((facility) => {
|
||||
const IconComponent = mapFacilityToIcon(facility.name)
|
||||
return (
|
||||
<div className={styles.facilitiesItem} key={facility.id}>
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
.hotelCards {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--Spacing-x4);
|
||||
}
|
||||
25
components/HotelReservation/HotelCardListing/index.tsx
Normal file
25
components/HotelReservation/HotelCardListing/index.tsx
Normal file
@@ -0,0 +1,25 @@
|
||||
"use client"
|
||||
|
||||
import Title from "@/components/TempDesignSystem/Text/Title"
|
||||
|
||||
import HotelCard from "../HotelCard"
|
||||
|
||||
import styles from "./hotelCardListing.module.css"
|
||||
|
||||
import { HotelCardListingProps } from "@/types/components/hotelReservation/selectHotel/hotelCardListingProps"
|
||||
|
||||
export default function HotelCardListing({ hotelData }: HotelCardListingProps) {
|
||||
if (!hotelData) return null
|
||||
|
||||
return (
|
||||
<section className={styles.hotelCards}>
|
||||
{hotelData && hotelData.length ? (
|
||||
hotelData.map((hotel) => (
|
||||
<HotelCard key={hotel.hotelData?.name} hotel={hotel} />
|
||||
))
|
||||
) : (
|
||||
<Title>Hallå</Title>
|
||||
)}
|
||||
</section>
|
||||
)
|
||||
}
|
||||
@@ -3,15 +3,15 @@ import { getIntl } from "@/i18n"
|
||||
import styles from "./hotelFilter.module.css"
|
||||
|
||||
export default async function HotelFilter() {
|
||||
const { formatMessage } = await getIntl()
|
||||
const intl = await getIntl()
|
||||
|
||||
return (
|
||||
<aside className={styles.container}>
|
||||
<div className={styles.facilities}>
|
||||
{formatMessage({ id: "Hotel facilities" })}
|
||||
{intl.formatMessage({ id: "Hotel facilities" })}
|
||||
</div>
|
||||
<div className={styles.facilities}>
|
||||
{formatMessage({ id: "Hotel surroundings" })}
|
||||
{intl.formatMessage({ id: "Hotel surroundings" })}
|
||||
{/* {filters.hotelSurroundings.map((surroundings) => (
|
||||
<div key={surroundings} className={styles.filter}>
|
||||
<input id={surroundings} name={surroundings} type="checkbox" />
|
||||
|
||||
Reference in New Issue
Block a user