From 3c82a8b4b5e248ced65bedfb6334225958a4352b Mon Sep 17 00:00:00 2001 From: Fredrik Thorsson Date: Thu, 29 Aug 2024 15:25:21 +0200 Subject: [PATCH] feat(SW-176): use the availability endpoint --- .../hotelreservation/select-hotel/page.tsx | 33 ++++++++------- .../HotelCard/hotelCard.module.css | 1 + .../HotelReservation/HotelCard/index.tsx | 41 ++++++++++++++----- server/routers/hotels/output.ts | 3 ++ .../selectHotel/hotelCardProps.ts | 12 +++++- types/hotel.ts | 2 - 6 files changed, 63 insertions(+), 29 deletions(-) diff --git a/app/[lang]/(live)/(public)/hotelreservation/select-hotel/page.tsx b/app/[lang]/(live)/(public)/hotelreservation/select-hotel/page.tsx index 2b216d29a..579b07f93 100644 --- a/app/[lang]/(live)/(public)/hotelreservation/select-hotel/page.tsx +++ b/app/[lang]/(live)/(public)/hotelreservation/select-hotel/page.tsx @@ -1,11 +1,11 @@ import { serverClient } from "@/lib/trpc/server" -import tempHotelData from "@/server/routers/hotels/tempHotelData.json" import HotelCard from "@/components/HotelReservation/HotelCard" import HotelFilter from "@/components/HotelReservation/SelectHotel/HotelFilter" import { ChevronRightIcon } from "@/components/Icons" import StaticMap from "@/components/Maps/StaticMap" import Link from "@/components/TempDesignSystem/Link" +import Title from "@/components/TempDesignSystem/Text/Title" import { getIntl } from "@/i18n" import { setLang } from "@/i18n/serverContext" @@ -19,10 +19,7 @@ export default async function SelectHotelPage({ const intl = await getIntl() setLang(params.lang) - // TODO: Use real endpoint. const tempSearchTerm = "Stockholm" - const hotel = tempHotelData.data.attributes - const hotels = [hotel] const hotelFilters = await serverClient().hotel.filters.get({ hotelId: "879", @@ -30,16 +27,14 @@ export default async function SelectHotelPage({ const availability = await serverClient().hotel.availability.get({ cityId: "8ec4bba3-1c38-4606-82d1-bbe3f6738e54", - roomStayStartDate: "2024-11-01", - roomStayEndDate: "2024-11-02", + roomStayStartDate: "2024-11-02", + roomStayEndDate: "2024-11-03", adults: 1, }) - const filterAvailability = availability?.availability.data.filter( - (hotels) => hotels.attributes.status === "Available" - ) - - console.log(filterAvailability) + const filterAvailability = availability?.availability.data + .filter((hotels) => hotels.attributes.status === "Available") + .flatMap((hotels) => hotels.attributes) return (
@@ -58,9 +53,19 @@ export default async function SelectHotelPage({
- {hotels.map((hotel) => ( - - ))} + {filterAvailability?.length ? ( + filterAvailability.map((hotel) => ( + + )) + ) : ( + No hotels found + )}
) diff --git a/components/HotelReservation/HotelCard/hotelCard.module.css b/components/HotelReservation/HotelCard/hotelCard.module.css index 3db576744..e07444eb0 100644 --- a/components/HotelReservation/HotelCard/hotelCard.module.css +++ b/components/HotelReservation/HotelCard/hotelCard.module.css @@ -77,6 +77,7 @@ "image header" "image hotel" "image prices"; + grid-template-columns: 518px; overflow: hidden; width: 1050px; padding: 0; diff --git a/components/HotelReservation/HotelCard/index.tsx b/components/HotelReservation/HotelCard/index.tsx index 77d038105..f79681015 100644 --- a/components/HotelReservation/HotelCard/index.tsx +++ b/components/HotelReservation/HotelCard/index.tsx @@ -1,3 +1,5 @@ +import { serverClient } from "@/lib/trpc/server" + import { mapFacilityToIcon } from "@/components/ContentType/HotelPage/data" import { ChevronRightIcon, @@ -13,15 +15,28 @@ 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({ hotel }: HotelCardProps) { +export default async function HotelCard({ + checkInDate, + checkOutDate, + hotelId, + price, +}: HotelCardProps) { 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) .slice(0, 5) @@ -29,8 +44,8 @@ export default async function HotelCard({ hotel }: HotelCardProps) {
{hotel.hotelContent.images.metaData.altText} - {hotel.ratings?.tripAdvisor.rating} + {hotelData.hotel.ratings?.tripAdvisor.rating}
- {hotel.name} + {hotelData.hotel.name} - {`${hotel.address.streetAddress}, ${hotel.address.city}`} + {`${hotelData.hotel.address.streetAddress}, ${hotelData.hotel.address.city}`} - {`${hotel.location.distanceToCentre} ${intl.formatMessage({ id: "km to city center" })}`} + {`${hotelData.hotel.location.distanceToCentre} ${intl.formatMessage({ id: "km to city center" })}`}
- {sortedAmenities.map((facility) => { + {sortedAmenities?.map((facility) => { const IconComponent = mapFacilityToIcon(facility.name) return (
@@ -77,7 +92,9 @@ export default async function HotelCard({ hotel }: HotelCardProps) { {intl.formatMessage({ id: "Public price from" })} - 2820 SEK / night + + {price?.regularAmount} SEK / night + approx 280 eur
@@ -85,7 +102,9 @@ export default async function HotelCard({ hotel }: HotelCardProps) { {intl.formatMessage({ id: "Member price from" })} - 2820 SEK / night + + {price?.memberAmount} SEK / night + approx 280 eur