From 3f6e2ca06e885dcf8493b192d79e9b4407fb50dc Mon Sep 17 00:00:00 2001 From: Fredrik Thorsson Date: Wed, 4 Sep 2024 13:44:16 +0200 Subject: [PATCH 01/14] feat(SW-251): set up filter route --- .../hotelreservation/select-hotel/page.tsx | 24 +++-- .../SelectHotel/HotelFilter/index.tsx | 12 +-- server/routers/hotels/input.ts | 4 +- server/routers/hotels/output.ts | 30 +++++-- server/routers/hotels/query.ts | 88 +++++++++++++++++-- 5 files changed, 129 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 6d350b61c..1352fbdcd 100644 --- a/app/[lang]/(live)/(public)/hotelreservation/select-hotel/page.tsx +++ b/app/[lang]/(live)/(public)/hotelreservation/select-hotel/page.tsx @@ -20,18 +20,28 @@ export default async function SelectHotelPage({ setLang(params.lang) const tempSearchTerm = "Stockholm" - const hotelFilters = await serverClient().hotel.filters.get({ - hotelId: "879", + const getHotelFitlers = await serverClient().hotel.filters.get({ + language: params.lang, + country: "Sweden", + city: "Halmstad", }) - const availableHotels = await serverClient().hotel.availability.get({ + if (!getHotelFitlers) return null + + console.log(getHotelFitlers.data) + + const getAvailableHotels = await serverClient().hotel.availability.get({ cityId: "8ec4bba3-1c38-4606-82d1-bbe3f6738e54", roomStayStartDate: "2024-11-02", roomStayEndDate: "2024-11-03", adults: 1, }) - if (!availableHotels) return null + if (!getAvailableHotels) return null + + const { availability } = getAvailableHotels + + console.log(availability) return (
@@ -48,11 +58,11 @@ export default async function SelectHotelPage({ {intl.formatMessage({ id: "Show map" })} - + {/* */}
- {availableHotels.availability.length ? ( - availableHotels.availability.map((hotel) => ( + {availability.length ? ( + availability.map((hotel) => (
{formatMessage({ id: "Room facilities" })} - {filters.roomFacilities.map((roomFilter) => ( + {/* {filters.roomFacilities.map((roomFilter) => (
- ))} + ))} */}
{formatMessage({ id: "Hotel facilities" })} - {filters.hotelFacilities.map((hotelFilter) => ( + {/* {filters.hotelFacilities.map((hotelFilter) => (
- ))} + ))} */}
{formatMessage({ id: "Hotel surroundings" })} - {filters.hotelSurroundings.map((surroundings) => ( + {/* {filters.hotelSurroundings.map((surroundings) => (
- ))} + ))} */}
) diff --git a/server/routers/hotels/input.ts b/server/routers/hotels/input.ts index 562a0e608..51106963b 100644 --- a/server/routers/hotels/input.ts +++ b/server/routers/hotels/input.ts @@ -22,5 +22,7 @@ export const getRatesInputSchema = z.object({ }) export const getFiltersInputSchema = z.object({ - hotelId: z.string(), + language: z.string(), + country: z.string(), + city: z.string(), }) diff --git a/server/routers/hotels/output.ts b/server/routers/hotels/output.ts index 192bab55c..39ccaeaf4 100644 --- a/server/routers/hotels/output.ts +++ b/server/routers/hotels/output.ts @@ -554,11 +554,29 @@ export const getRatesSchema = z.array(rate) export type Rate = z.infer -const hotelFilter = z.object({ - roomFacilities: z.array(z.string()), - hotelFacilities: z.array(z.string()), - hotelSurroundings: z.array(z.string()), +const hotelFilterSchema = z.object({ + data: z.array( + z.object({ + attributes: z.object({ + name: z.string(), + operaId: z.string(), + isPublished: z.boolean(), + cityId: z.string(), + cityName: z.string(), + ratings: ratingsSchema, + address: addressSchema, + location: locationSchema, + hotelContent: hotelContentSchema, + detailedFacilities: z.array(detailedFacilitySchema), + isActive: z.boolean(), + }), + id: z.string(), + language: z.unknown(), + hotelInformationSystemId: z.number(), + type: z.string(), + }) + ), }) -export const getFiltersSchema = hotelFilter -export type HotelFilter = z.infer +export const getHotelFilterSchema = hotelFilterSchema +export type HotelFilter = z.infer diff --git a/server/routers/hotels/query.ts b/server/routers/hotels/query.ts index b35ed7cd2..69aa9ad59 100644 --- a/server/routers/hotels/query.ts +++ b/server/routers/hotels/query.ts @@ -33,8 +33,8 @@ import { } from "./input" import { getAvailabilitySchema, - getFiltersSchema, getHotelDataSchema, + getHotelFilterSchema, getRatesSchema, roomSchema, } from "./output" @@ -57,6 +57,10 @@ const availabilityFailCounter = meter.createCounter( "trpc.hotel.availability-fail" ) +const filterCounter = meter.createCounter("trcp.hotel.filter") +const filterSuccessCounter = meter.createCounter("trcp.hotel.filter-success") +const filterFailCounter = meter.createCounter("trcp.hotel.filter-fail") + async function getContentstackData( locale: string, uid: string | null | undefined @@ -420,31 +424,97 @@ export const hotelQueryRouter = router({ }), }), filters: router({ - get: publicProcedure + get: serviceProcedure .input(getFiltersInputSchema) .query(async ({ input, ctx }) => { - console.info("api.hotels.filters start", JSON.stringify({})) + const { language, country, city } = input + const params: Record = { + language, + country, + city, + } - if (!tempFilterData) { + filterCounter.add(1, { + language, + country, + city, + }) + console.info( + "api.hotels.filters start", + JSON.stringify({ + query: { params }, + }) + ) + + const apiResponse = await api.get( + api.endpoints.v1.hotels, + { + headers: { + Authorization: `Bearer ${ctx.serviceToken}`, + }, + }, + params + ) + + if (!apiResponse.ok) { + const text = await apiResponse.text() + filterFailCounter.add(1, { + language, + country, + city, + error_type: "http_error", + error: JSON.stringify({ + status: apiResponse.status, + statusText: apiResponse.statusText, + text, + }), + }) console.error( "api.hotels.filters error", - JSON.stringify({ error: null }) + JSON.stringify({ + query: { + params, + }, + error: { + status: apiResponse.status, + statusText: apiResponse.statusText, + text, + }, + }) ) - //Can't return null here since consuming component does not handle null yet - // return null + return null } - const validateFilterData = getFiltersSchema.safeParse(tempFilterData) + + const apiJson = await apiResponse.json() + const validateFilterData = getHotelFilterSchema.safeParse(apiJson) if (!validateFilterData.success) { + filterFailCounter.add(1, { + language, + country, + city, + error_type: "validation_error", + error: JSON.stringify(validateFilterData.error), + }) console.error( "api.hotels.filters validation error", JSON.stringify({ + query: { params }, error: validateFilterData.error, }) ) throw badRequestError() } - console.info("api.hotels.rates success", JSON.stringify({})) + + filterSuccessCounter.add(1, { + language, + country, + city, + }) + console.info( + "api.hotels.fuilters success", + JSON.stringify({ query: { params: params } }) + ) return validateFilterData.data }), }), From 6089af764a7c2b189bb9b07e6a70b462f0d12dfb Mon Sep 17 00:00:00 2001 From: Fredrik Thorsson Date: Wed, 4 Sep 2024 15:57:32 +0200 Subject: [PATCH 02/14] feat(SW-251): filter request --- .../hotelreservation/select-hotel/page.tsx | 6 +---- .../SelectHotel/HotelFilter/index.tsx | 5 ++++- server/routers/hotels/output.ts | 8 ++++--- server/routers/hotels/query.ts | 15 +++++++++++-- server/routers/hotels/tempFilterData.json | 22 ------------------- .../selectHotel/hotelFilterProps.ts | 7 ++++-- 6 files changed, 28 insertions(+), 35 deletions(-) delete mode 100644 server/routers/hotels/tempFilterData.json diff --git a/app/[lang]/(live)/(public)/hotelreservation/select-hotel/page.tsx b/app/[lang]/(live)/(public)/hotelreservation/select-hotel/page.tsx index 1352fbdcd..cb2e8cd43 100644 --- a/app/[lang]/(live)/(public)/hotelreservation/select-hotel/page.tsx +++ b/app/[lang]/(live)/(public)/hotelreservation/select-hotel/page.tsx @@ -23,13 +23,11 @@ export default async function SelectHotelPage({ const getHotelFitlers = await serverClient().hotel.filters.get({ language: params.lang, country: "Sweden", - city: "Halmstad", + city: "Helsingborg", }) if (!getHotelFitlers) return null - console.log(getHotelFitlers.data) - const getAvailableHotels = await serverClient().hotel.availability.get({ cityId: "8ec4bba3-1c38-4606-82d1-bbe3f6738e54", roomStayStartDate: "2024-11-02", @@ -41,8 +39,6 @@ export default async function SelectHotelPage({ const { availability } = getAvailableHotels - console.log(availability) - return (
diff --git a/components/HotelReservation/SelectHotel/HotelFilter/index.tsx b/components/HotelReservation/SelectHotel/HotelFilter/index.tsx index 84984b9d7..fe7b98fe9 100644 --- a/components/HotelReservation/SelectHotel/HotelFilter/index.tsx +++ b/components/HotelReservation/SelectHotel/HotelFilter/index.tsx @@ -4,7 +4,10 @@ import styles from "./hotelFilter.module.css" import { HotelFilterProps } from "@/types/components/hotelReservation/selectHotel/hotelFilterProps" -export default async function HotelFilter({ filters }: HotelFilterProps) { +export default async function HotelFilter({ + hotelId, + filters, +}: HotelFilterProps) { const { formatMessage } = await getIntl() return ( diff --git a/server/routers/hotels/output.ts b/server/routers/hotels/output.ts index 39ccaeaf4..a72d08c3a 100644 --- a/server/routers/hotels/output.ts +++ b/server/routers/hotels/output.ts @@ -145,7 +145,7 @@ const hotelContentSchema = z.object({ restaurantsOverviewPageLinkText: z.string(), restaurantsOverviewPageLink: z.string(), restaurantsContentDescriptionShort: z.string(), - restaurantsContentDescriptionMedium: z.string(), + restaurantsContentDescriptionMedium: z.string().optional(), }), }) @@ -551,7 +551,6 @@ const rate = z.object({ }) export const getRatesSchema = z.array(rate) - export type Rate = z.infer const hotelFilterSchema = z.object({ @@ -566,7 +565,7 @@ const hotelFilterSchema = z.object({ ratings: ratingsSchema, address: addressSchema, location: locationSchema, - hotelContent: hotelContentSchema, + hotelContent: hotelContentSchema.optional(), detailedFacilities: z.array(detailedFacilitySchema), isActive: z.boolean(), }), @@ -580,3 +579,6 @@ const hotelFilterSchema = z.object({ export const getHotelFilterSchema = hotelFilterSchema export type HotelFilter = z.infer +export type HotelId = HotelFilter["data"][number]["id"] +export type HotelFilters = + HotelFilter["data"][number]["attributes"]["detailedFacilities"] diff --git a/server/routers/hotels/query.ts b/server/routers/hotels/query.ts index 69aa9ad59..54a97be78 100644 --- a/server/routers/hotels/query.ts +++ b/server/routers/hotels/query.ts @@ -38,7 +38,6 @@ import { getRatesSchema, roomSchema, } from "./output" -import tempFilterData from "./tempFilterData.json" import tempRatesData from "./tempRatesData.json" import { HotelBlocksTypenameEnum } from "@/types/components/hotelPage/enums" @@ -515,7 +514,19 @@ export const hotelQueryRouter = router({ "api.hotels.fuilters success", JSON.stringify({ query: { params: params } }) ) - return validateFilterData.data + + const hotelData = validateFilterData.data.data + const filters = hotelData.flatMap( + (data) => data.attributes.detailedFacilities + ) + const unieqId = [...new Set(filters.map((data) => data.id))] + + return { + hotelId: hotelData.map((data) => data.id), + filters: unieqId.map((data) => + filters.find((find) => find.id === data) + ), + } }), }), }) diff --git a/server/routers/hotels/tempFilterData.json b/server/routers/hotels/tempFilterData.json deleted file mode 100644 index e58bdf50b..000000000 --- a/server/routers/hotels/tempFilterData.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "roomFacilities": ["Balcony", "Bathub", "View", "Conntecting doors"], - "hotelFacilities": [ - "Parking inside", - "Parking outside", - "Parking electric", - "Sauna", - "Pool", - "Restaurant", - "Bar", - "Sky/rooftop bar", - "Gym", - "Coworking" - ], - "hotelSurroundings": [ - "Beach", - "Lake or sea", - "Hiking", - "Mountains", - "Golf course" - ] -} diff --git a/types/components/hotelReservation/selectHotel/hotelFilterProps.ts b/types/components/hotelReservation/selectHotel/hotelFilterProps.ts index e100131ba..709e9378d 100644 --- a/types/components/hotelReservation/selectHotel/hotelFilterProps.ts +++ b/types/components/hotelReservation/selectHotel/hotelFilterProps.ts @@ -1,3 +1,6 @@ -import { HotelFilter } from "@/server/routers/hotels/output" +import { HotelFilters, HotelId } from "@/server/routers/hotels/output" -export type HotelFilterProps = { filters: HotelFilter } +export type HotelFilterProps = { + hotelId: HotelId + filters: HotelFilters +} From 024a095dc65e8e1b55750ea849f8624cfb626aec Mon Sep 17 00:00:00 2001 From: Fredrik Thorsson Date: Thu, 5 Sep 2024 13:25:46 +0200 Subject: [PATCH 03/14] feat(SW-251): check for undefined --- .../hotelreservation/select-hotel/page.tsx | 4 +++- .../SelectHotel/HotelFilter/index.tsx | 19 +++++++------------ server/routers/hotels/query.ts | 10 +++++----- .../selectHotel/hotelFilterProps.ts | 3 +-- 4 files changed, 16 insertions(+), 20 deletions(-) diff --git a/app/[lang]/(live)/(public)/hotelreservation/select-hotel/page.tsx b/app/[lang]/(live)/(public)/hotelreservation/select-hotel/page.tsx index cb2e8cd43..1a75c56f5 100644 --- a/app/[lang]/(live)/(public)/hotelreservation/select-hotel/page.tsx +++ b/app/[lang]/(live)/(public)/hotelreservation/select-hotel/page.tsx @@ -28,6 +28,8 @@ export default async function SelectHotelPage({ if (!getHotelFitlers) return null + const { filters } = getHotelFitlers + const getAvailableHotels = await serverClient().hotel.availability.get({ cityId: "8ec4bba3-1c38-4606-82d1-bbe3f6738e54", roomStayStartDate: "2024-11-02", @@ -54,7 +56,7 @@ export default async function SelectHotelPage({ {intl.formatMessage({ id: "Show map" })} - {/* */} +
{availability.length ? ( diff --git a/components/HotelReservation/SelectHotel/HotelFilter/index.tsx b/components/HotelReservation/SelectHotel/HotelFilter/index.tsx index fe7b98fe9..f002c83b9 100644 --- a/components/HotelReservation/SelectHotel/HotelFilter/index.tsx +++ b/components/HotelReservation/SelectHotel/HotelFilter/index.tsx @@ -4,25 +4,20 @@ import styles from "./hotelFilter.module.css" import { HotelFilterProps } from "@/types/components/hotelReservation/selectHotel/hotelFilterProps" -export default async function HotelFilter({ - hotelId, - filters, -}: HotelFilterProps) { +export default async function HotelFilter({ filters }: HotelFilterProps) { const { formatMessage } = await getIntl() + console.log(filters) + return (
{availability.length ? ( diff --git a/components/HotelReservation/HotelCard/index.tsx b/components/HotelReservation/HotelCard/index.tsx index 43cf56a03..0f37287f1 100644 --- a/components/HotelReservation/HotelCard/index.tsx +++ b/components/HotelReservation/HotelCard/index.tsx @@ -1,3 +1,4 @@ +import { serverClient } from "@/lib/trpc/server" import tempHotelData from "@/server/routers/hotels/tempHotelData.json" import { mapFacilityToIcon } from "@/components/ContentType/HotelPage/data" @@ -15,6 +16,7 @@ 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" @@ -31,7 +33,16 @@ export default async function HotelCard({ // TODO: Use real endpoint. const hotel = tempHotelData.data.attributes - const sortedAmenities = hotel.detailedFacilities + const hotelResponse = await serverClient().hotel.hotel.get({ + hotelId: hotelId.toString(), + language: getLang(), + }) + + if (!hotelResponse) return null + + const { data } = hotelResponse + + const sortedAmenities = data.attributes.detailedFacilities .sort((a, b) => b.sortOrder - a.sortOrder) .slice(0, 5) @@ -39,8 +50,8 @@ export default async function HotelCard({
{hotel.hotelContent.images.metaData.altText} - {hotel.ratings?.tripAdvisor.rating} + {data.attributes.ratings?.tripAdvisor.rating}
@@ -58,10 +69,10 @@ export default async function HotelCard({ {hotel.name} - {`${hotel.address.streetAddress}, ${hotel.address.city}`} + {`${data.attributes.address.streetAddress}, ${data.attributes.address.city}`} - {`${hotel.location.distanceToCentre} ${intl.formatMessage({ id: "km to city center" })}`} + {`${data.attributes.location.distanceToCentre} ${intl.formatMessage({ id: "km to city center" })}`}
diff --git a/components/HotelReservation/SelectHotel/HotelFilter/index.tsx b/components/HotelReservation/SelectHotel/HotelFilter/index.tsx index f002c83b9..81230461d 100644 --- a/components/HotelReservation/SelectHotel/HotelFilter/index.tsx +++ b/components/HotelReservation/SelectHotel/HotelFilter/index.tsx @@ -2,28 +2,13 @@ import { getIntl } from "@/i18n" import styles from "./hotelFilter.module.css" -import { HotelFilterProps } from "@/types/components/hotelReservation/selectHotel/hotelFilterProps" - -export default async function HotelFilter({ filters }: HotelFilterProps) { +export default async function HotelFilter() { const { formatMessage } = await getIntl() - console.log(filters) - return (
- {hotel.name} + {hotelData.name} - {`${data.attributes.address.streetAddress}, ${data.attributes.address.city}`} + {`${hotelData.address?.streetAddress}, ${hotelData.address?.city}`} - {`${data.attributes.location.distanceToCentre} ${intl.formatMessage({ id: "km to city center" })}`} + {`${hotelData.location.distanceToCentre} ${intl.formatMessage({ id: "km to city center" })}`}
- {sortedAmenities.map((facility) => { + {sortedAmenities?.map((facility) => { const IconComponent = mapFacilityToIcon(facility.name) return (
diff --git a/components/HotelReservation/HotelCardListing/hotelCardListing.module.css b/components/HotelReservation/HotelCardListing/hotelCardListing.module.css new file mode 100644 index 000000000..be62321df --- /dev/null +++ b/components/HotelReservation/HotelCardListing/hotelCardListing.module.css @@ -0,0 +1,5 @@ +.hotelCards { + display: flex; + flex-direction: column; + gap: var(--Spacing-x4); +} diff --git a/components/HotelReservation/HotelCardListing/index.tsx b/components/HotelReservation/HotelCardListing/index.tsx new file mode 100644 index 000000000..2af4f0b9c --- /dev/null +++ b/components/HotelReservation/HotelCardListing/index.tsx @@ -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 ( +
+ {hotelData && hotelData.length ? ( + hotelData.map((hotel) => ( + + )) + ) : ( + HallÄ + )} +
+ ) +} diff --git a/components/HotelReservation/SelectHotel/HotelFilter/index.tsx b/components/HotelReservation/SelectHotel/HotelFilter/index.tsx index 81230461d..cc171f654 100644 --- a/components/HotelReservation/SelectHotel/HotelFilter/index.tsx +++ b/components/HotelReservation/SelectHotel/HotelFilter/index.tsx @@ -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 (
- {hotelData.name} + {hotelData?.name} - {`${hotelData.address?.streetAddress}, ${hotelData.address?.city}`} + {`${hotelData?.address?.streetAddress}, ${hotelData?.address?.city}`} - {`${hotelData.location.distanceToCentre} ${intl.formatMessage({ id: "km to city center" })}`} + {`${hotelData?.location.distanceToCentre} ${intl.formatMessage({ id: "km to city center" })}`}
diff --git a/components/HotelReservation/SelectHotel/HotelFilter/index.tsx b/components/HotelReservation/SelectHotel/HotelFilter/index.tsx index cc171f654..a3a993aee 100644 --- a/components/HotelReservation/SelectHotel/HotelFilter/index.tsx +++ b/components/HotelReservation/SelectHotel/HotelFilter/index.tsx @@ -1,23 +1,28 @@ -import { getIntl } from "@/i18n" +"use client" + +import { useIntl } from "react-intl" import styles from "./hotelFilter.module.css" -export default async function HotelFilter() { - const intl = await getIntl() +import { HotelFiltersProps } from "@/types/components/hotelReservation/selectHotel/hotelFilters" + +export default function HotelFilter({ filters }: HotelFiltersProps) { + const intl = useIntl() return ( ) diff --git a/server/routers/hotels/input.ts b/server/routers/hotels/input.ts index a89c55dc2..416d41eee 100644 --- a/server/routers/hotels/input.ts +++ b/server/routers/hotels/input.ts @@ -21,7 +21,7 @@ export const getRatesInputSchema = z.object({ hotelId: z.string(), }) -export const getPlaceholderInputSchema = z.object({ +export const getlHotelDataInputSchema = z.object({ hotelId: z.string(), language: z.string(), include: z diff --git a/server/routers/hotels/query.ts b/server/routers/hotels/query.ts index 1532d1690..5f8ae5dd9 100644 --- a/server/routers/hotels/query.ts +++ b/server/routers/hotels/query.ts @@ -28,7 +28,7 @@ import { import { getAvailabilityInputSchema, getHotelInputSchema, - getPlaceholderInputSchema, + getlHotelDataInputSchema, getRatesInputSchema, } from "./input" import { @@ -55,10 +55,6 @@ const availabilityFailCounter = meter.createCounter( "trpc.hotel.availability-fail" ) -const filterCounter = meter.createCounter("trcp.hotel.filter") -const filterSuccessCounter = meter.createCounter("trcp.hotel.filter-success") -const filterFailCounter = meter.createCounter("trcp.hotel.filter-fail") - async function getContentstackData( locale: string, uid: string | null | undefined @@ -421,9 +417,9 @@ export const hotelQueryRouter = router({ return validatedHotelData.data }), }), - hotel: router({ + hotelData: router({ get: serviceProcedure - .input(getPlaceholderInputSchema) + .input(getlHotelDataInputSchema) .query(async ({ ctx, input }) => { const { hotelId, language, include } = input diff --git a/types/components/hotelReservation/selectHotel/hotelFilters.ts b/types/components/hotelReservation/selectHotel/hotelFilters.ts new file mode 100644 index 000000000..1be84f63d --- /dev/null +++ b/types/components/hotelReservation/selectHotel/hotelFilters.ts @@ -0,0 +1,5 @@ +import { Hotel } from "@/types/hotel" + +export type HotelFiltersProps = { + filters: Hotel["detailedFacilities"] +} From 98b903b314e01a36e13ea3972b76a28be6c0e97a Mon Sep 17 00:00:00 2001 From: Fredrik Thorsson Date: Wed, 11 Sep 2024 16:19:59 +0200 Subject: [PATCH 07/14] feat(SW-251): add input --- .../(public)/hotelreservation/select-hotel/page.tsx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/[lang]/(live)/(public)/hotelreservation/select-hotel/page.tsx b/app/[lang]/(live)/(public)/hotelreservation/select-hotel/page.tsx index 032ff30f0..634c4cf1c 100644 --- a/app/[lang]/(live)/(public)/hotelreservation/select-hotel/page.tsx +++ b/app/[lang]/(live)/(public)/hotelreservation/select-hotel/page.tsx @@ -20,12 +20,20 @@ async function getAvailableHotels({ roomStayStartDate, roomStayEndDate, adults, + children, + promotionCode, + attachedProfileId, + reservationProfileType, }: AvailabilityInput): Promise { const getAvailableHotels = await serverClient().hotel.availability.get({ cityId: cityId, roomStayStartDate: roomStayStartDate, roomStayEndDate: roomStayEndDate, adults: adults, + children: children, + promotionCode: promotionCode, + attachedProfileId: attachedProfileId, + reservationProfileType: reservationProfileType, }) if (!getAvailableHotels) return null From 297fdfab5742c087e890827618bda01e4c4c866d Mon Sep 17 00:00:00 2001 From: Fredrik Thorsson Date: Wed, 11 Sep 2024 16:29:50 +0200 Subject: [PATCH 08/14] feat(SW-251): add error text --- components/HotelReservation/HotelCardListing/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/HotelReservation/HotelCardListing/index.tsx b/components/HotelReservation/HotelCardListing/index.tsx index 2af4f0b9c..a98e0e906 100644 --- a/components/HotelReservation/HotelCardListing/index.tsx +++ b/components/HotelReservation/HotelCardListing/index.tsx @@ -18,7 +18,7 @@ export default function HotelCardListing({ hotelData }: HotelCardListingProps) { )) ) : ( - HallÄ + No hotels found )}
) From d338fee8a90d46c10375a129dc38ede2839f9e24 Mon Sep 17 00:00:00 2001 From: Fredrik Thorsson Date: Wed, 11 Sep 2024 16:34:08 +0200 Subject: [PATCH 09/14] feat(Sw-251): rename file --- components/HotelReservation/SelectHotel/HotelFilter/index.tsx | 2 +- .../selectHotel/{hotelFilters.ts => hotelFiltersProps.ts} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename types/components/hotelReservation/selectHotel/{hotelFilters.ts => hotelFiltersProps.ts} (100%) diff --git a/components/HotelReservation/SelectHotel/HotelFilter/index.tsx b/components/HotelReservation/SelectHotel/HotelFilter/index.tsx index a3a993aee..52bf5a7fe 100644 --- a/components/HotelReservation/SelectHotel/HotelFilter/index.tsx +++ b/components/HotelReservation/SelectHotel/HotelFilter/index.tsx @@ -4,7 +4,7 @@ import { useIntl } from "react-intl" import styles from "./hotelFilter.module.css" -import { HotelFiltersProps } from "@/types/components/hotelReservation/selectHotel/hotelFilters" +import { HotelFiltersProps } from "@/types/components/hotelReservation/selectHotel/hotelFiltersProps" export default function HotelFilter({ filters }: HotelFiltersProps) { const intl = useIntl() diff --git a/types/components/hotelReservation/selectHotel/hotelFilters.ts b/types/components/hotelReservation/selectHotel/hotelFiltersProps.ts similarity index 100% rename from types/components/hotelReservation/selectHotel/hotelFilters.ts rename to types/components/hotelReservation/selectHotel/hotelFiltersProps.ts From 21ff8f8b5d920f71ba93589fc5d2e15785791946 Mon Sep 17 00:00:00 2001 From: Fredrik Thorsson Date: Wed, 11 Sep 2024 16:41:29 +0200 Subject: [PATCH 10/14] feat(SW-251): update logging texts --- server/routers/hotels/output.ts | 2 +- server/routers/hotels/query.ts | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/server/routers/hotels/output.ts b/server/routers/hotels/output.ts index ff7437b2a..1eba75ea0 100644 --- a/server/routers/hotels/output.ts +++ b/server/routers/hotels/output.ts @@ -145,7 +145,7 @@ const hotelContentSchema = z.object({ restaurantsOverviewPageLinkText: z.string(), restaurantsOverviewPageLink: z.string(), restaurantsContentDescriptionShort: z.string(), - restaurantsContentDescriptionMedium: z.string().optional(), + restaurantsContentDescriptionMedium: z.string(), }), }) diff --git a/server/routers/hotels/query.ts b/server/routers/hotels/query.ts index 5f8ae5dd9..fe92fa109 100644 --- a/server/routers/hotels/query.ts +++ b/server/routers/hotels/query.ts @@ -438,7 +438,7 @@ export const hotelQueryRouter = router({ include, }) console.info( - "api.hotels.hotel start", + "api.hotels.hotelData start", JSON.stringify({ query: { hotelId, params } }) ) @@ -466,7 +466,7 @@ export const hotelQueryRouter = router({ }), }) console.error( - "api.hotels.hotel error", + "api.hotels.hotelData error", JSON.stringify({ query: { hotelId, params }, error: { @@ -492,7 +492,7 @@ export const hotelQueryRouter = router({ }) console.error( - "api.hotels.hotel validation error", + "api.hotels.hotelData validation error", JSON.stringify({ query: { hotelId, params }, error: validateHotelData.error, @@ -507,7 +507,7 @@ export const hotelQueryRouter = router({ include, }) console.info( - "api.hotels.hotel success", + "api.hotels.hotelData success", JSON.stringify({ query: { hotelId, params: params }, }) From 85460e95e57408490ee7d386bf29ff5fb7e895c2 Mon Sep 17 00:00:00 2001 From: Fredrik Thorsson Date: Thu, 12 Sep 2024 13:48:27 +0200 Subject: [PATCH 11/14] feat(SW-251): type assertion --- .../hotelreservation/select-hotel/page.tsx | 18 ++++++++---------- .../HotelReservation/HotelCard/index.tsx | 16 ++++++++-------- .../HotelCardListing/index.tsx | 4 +--- .../SelectHotel/HotelFilter/index.tsx | 13 +++++++++++-- .../selectHotel/hotelCardListingProps.ts | 2 +- 5 files changed, 29 insertions(+), 24 deletions(-) diff --git a/app/[lang]/(live)/(public)/hotelreservation/select-hotel/page.tsx b/app/[lang]/(live)/(public)/hotelreservation/select-hotel/page.tsx index 634c4cf1c..4e5f85841 100644 --- a/app/[lang]/(live)/(public)/hotelreservation/select-hotel/page.tsx +++ b/app/[lang]/(live)/(public)/hotelreservation/select-hotel/page.tsx @@ -1,5 +1,4 @@ import { serverClient } from "@/lib/trpc/server" -import { notFound } from "@/server/errors/next" import HotelCardListing from "@/components/HotelReservation/HotelCardListing" import HotelFilter from "@/components/HotelReservation/SelectHotel/HotelFilter" @@ -24,7 +23,7 @@ async function getAvailableHotels({ promotionCode, attachedProfileId, reservationProfileType, -}: AvailabilityInput): Promise { +}: AvailabilityInput): Promise { const getAvailableHotels = await serverClient().hotel.availability.get({ cityId: cityId, roomStayStartDate: roomStayStartDate, @@ -36,7 +35,7 @@ async function getAvailableHotels({ reservationProfileType: reservationProfileType, }) - if (!getAvailableHotels) return null + if (!getAvailableHotels) throw new Error() const { availability } = getAvailableHotels @@ -46,8 +45,10 @@ async function getAvailableHotels({ language: getLang(), }) + if (!hotelData) throw new Error() + return { - hotelData: hotelData?.data.attributes, + hotelData: hotelData.data.attributes, price: hotel.bestPricePerNight, } }) @@ -70,12 +71,9 @@ export default async function SelectHotelPage({ adults: 1, }) - if (!hotels) return null - if (hotels.some((item) => item?.hotelData === undefined)) return notFound() + const filters = hotels.flatMap((data) => data.hotelData.detailedFacilities) - const filters = hotels.flatMap((data) => data.hotelData?.detailedFacilities) - - const filterId = [...new Set(filters.map((data) => data?.id))] + const filterId = [...new Set(filters.map((data) => data.id))] const filterList: { name: string id: number @@ -86,7 +84,7 @@ export default async function SelectHotelPage({ code?: string iconName?: string }[] = filterId - .map((data) => filters.find((find) => find?.id === data)) + .map((data) => filters.find((find) => find.id === data)) .filter( ( filter diff --git a/components/HotelReservation/HotelCard/index.tsx b/components/HotelReservation/HotelCard/index.tsx index 83d830515..76d702b98 100644 --- a/components/HotelReservation/HotelCard/index.tsx +++ b/components/HotelReservation/HotelCard/index.tsx @@ -25,7 +25,7 @@ export default function HotelCard({ hotel }: HotelCardProps) { const { hotelData } = hotel const { price } = hotel - const sortedAmenities = hotelData?.detailedFacilities + const sortedAmenities = hotelData.detailedFacilities .sort((a, b) => b.sortOrder - a.sortOrder) .slice(0, 5) @@ -33,8 +33,8 @@ export default function HotelCard({ hotel }: HotelCardProps) {
{hotelData?.hotelContent.images.metaData.altText - {hotelData?.ratings?.tripAdvisor.rating} + {hotelData.ratings?.tripAdvisor.rating}
- {hotelData?.name} + {hotelData.name} - {`${hotelData?.address?.streetAddress}, ${hotelData?.address?.city}`} + {`${hotelData.address.streetAddress}, ${hotelData.address.city}`} - {`${hotelData?.location.distanceToCentre} ${intl.formatMessage({ id: "km to city center" })}`} + {`${hotelData.location.distanceToCentre} ${intl.formatMessage({ id: "km to city center" })}`}
- {sortedAmenities?.map((facility) => { + {sortedAmenities.map((facility) => { const IconComponent = mapFacilityToIcon(facility.name) return (
diff --git a/components/HotelReservation/HotelCardListing/index.tsx b/components/HotelReservation/HotelCardListing/index.tsx index a98e0e906..8a3da1dba 100644 --- a/components/HotelReservation/HotelCardListing/index.tsx +++ b/components/HotelReservation/HotelCardListing/index.tsx @@ -9,13 +9,11 @@ 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 (
{hotelData && hotelData.length ? ( hotelData.map((hotel) => ( - + )) ) : ( No hotels found diff --git a/components/HotelReservation/SelectHotel/HotelFilter/index.tsx b/components/HotelReservation/SelectHotel/HotelFilter/index.tsx index 52bf5a7fe..f10191cec 100644 --- a/components/HotelReservation/SelectHotel/HotelFilter/index.tsx +++ b/components/HotelReservation/SelectHotel/HotelFilter/index.tsx @@ -9,6 +9,10 @@ import { HotelFiltersProps } from "@/types/components/hotelReservation/selectHot export default function HotelFilter({ filters }: HotelFiltersProps) { const intl = useIntl() + function handleOnChange() { + // TODO: Update URL with selected values + } + return (