feat(SW-176): filter in route
This commit is contained in:
@@ -11,7 +11,6 @@ import { setLang } from "@/i18n/serverContext"
|
||||
|
||||
import styles from "./page.module.css"
|
||||
|
||||
import { AvailabilityEnum } from "@/types/components/hotelReservation/selectHotel/selectHotel"
|
||||
import { LangParams, PageArgs } from "@/types/params"
|
||||
|
||||
export default async function SelectHotelPage({
|
||||
@@ -25,20 +24,14 @@ export default async function SelectHotelPage({
|
||||
hotelId: "879",
|
||||
})
|
||||
|
||||
const availabilityResponse = await serverClient().hotel.availability.get({
|
||||
const availableHotels = await serverClient().hotel.availability.get({
|
||||
cityId: "8ec4bba3-1c38-4606-82d1-bbe3f6738e54",
|
||||
roomStayStartDate: "2024-11-02",
|
||||
roomStayEndDate: "2024-11-03",
|
||||
adults: 1,
|
||||
})
|
||||
|
||||
if (!availabilityResponse) return null
|
||||
|
||||
const { availability } = availabilityResponse
|
||||
|
||||
const availableHotels = availability.data
|
||||
.filter((hotels) => hotels.attributes.status === AvailabilityEnum.Available)
|
||||
.flatMap((hotels) => hotels.attributes)
|
||||
if (!availableHotels) return null
|
||||
|
||||
console.log(availableHotels)
|
||||
|
||||
@@ -59,8 +52,8 @@ export default async function SelectHotelPage({
|
||||
<HotelFilter filters={hotelFilters} />
|
||||
</section>
|
||||
<section className={styles.hotelCards}>
|
||||
{availableHotels.length ? (
|
||||
availableHotels.map((hotel) => (
|
||||
{availableHotels.availability.length ? (
|
||||
availableHotels.availability.map((hotel) => (
|
||||
<HotelCard
|
||||
key={hotel.hotelId}
|
||||
checkInDate={hotel.checkInDate}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { serverClient } from "@/lib/trpc/server"
|
||||
import tempHotelData from "@/server/routers/hotels/tempHotelData.json"
|
||||
|
||||
import { mapFacilityToIcon } from "@/components/ContentType/HotelPage/data"
|
||||
@@ -16,7 +15,6 @@ 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"
|
||||
|
||||
@@ -90,7 +88,7 @@ export default async function HotelCard({
|
||||
{intl.formatMessage({ id: "Public price from" })}
|
||||
</Chip>
|
||||
<Caption color="textMediumContrast">
|
||||
{price?.regularAmount} SEK / night
|
||||
{price?.regularAmount} SEK / {intl.formatMessage({ id: "night" })}
|
||||
</Caption>
|
||||
<Footnote color="textMediumContrast">approx 280 eur</Footnote>
|
||||
</div>
|
||||
@@ -100,7 +98,7 @@ export default async function HotelCard({
|
||||
{intl.formatMessage({ id: "Member price from" })}
|
||||
</Chip>
|
||||
<Caption color="textMediumContrast">
|
||||
{price?.memberAmount} SEK / night
|
||||
{price?.memberAmount} SEK / {intl.formatMessage({ id: "night" })}
|
||||
</Caption>
|
||||
<Footnote color="textMediumContrast">approx 280 eur</Footnote>
|
||||
</div>
|
||||
|
||||
@@ -470,7 +470,7 @@ export const getHotelDataSchema = z.object({
|
||||
|
||||
const occupancySchema = z.object({
|
||||
adults: z.number(),
|
||||
children: z.number(),
|
||||
children: z.number().optional(),
|
||||
})
|
||||
|
||||
const bestPricePerStaySchema = z.object({
|
||||
@@ -512,7 +512,7 @@ const availabilitySchema = z.object({
|
||||
attributes: z.object({
|
||||
checkInDate: z.string(),
|
||||
checkOutDate: z.string(),
|
||||
occupancy: occupancySchema.optional(),
|
||||
occupancy: occupancySchema,
|
||||
status: z.string(),
|
||||
hotelId: z.number(),
|
||||
ratePlanSet: z.string().optional(),
|
||||
|
||||
@@ -37,6 +37,8 @@ import {
|
||||
import tempFilterData from "./tempFilterData.json"
|
||||
import tempRatesData from "./tempRatesData.json"
|
||||
|
||||
import { AvailabilityEnum } from "@/types/components/hotelReservation/selectHotel/selectHotel"
|
||||
|
||||
const meter = metrics.getMeter("trpc.hotels")
|
||||
const getHotelCounter = meter.createCounter("trpc.hotel.get")
|
||||
const getHotelSuccessCounter = meter.createCounter("trpc.hotel.get-success")
|
||||
@@ -234,24 +236,16 @@ export const hotelQueryRouter = router({
|
||||
attachedProfileId,
|
||||
} = input
|
||||
// TODO: remove undefined type from params
|
||||
const params: Record<string, string | number | undefined> = {
|
||||
const params: Record<string, string | number> = {
|
||||
roomStayStartDate,
|
||||
roomStayEndDate,
|
||||
adults,
|
||||
children,
|
||||
promotionCode,
|
||||
reservationProfileType,
|
||||
attachedProfileId,
|
||||
}
|
||||
availabilityCounter.add(1, {
|
||||
cityId,
|
||||
roomStayStartDate,
|
||||
roomStayEndDate,
|
||||
adults,
|
||||
children,
|
||||
promotionCode,
|
||||
reservationProfileType,
|
||||
attachedProfileId,
|
||||
})
|
||||
console.info(
|
||||
"api.hotels.availability start",
|
||||
@@ -260,7 +254,6 @@ export const hotelQueryRouter = router({
|
||||
const apiResponse = await api.get(
|
||||
`${api.endpoints.v0.availability}/${cityId}`,
|
||||
{
|
||||
cache: "no-store",
|
||||
headers: {
|
||||
Authorization: `Bearer ${ctx.serviceToken}`,
|
||||
},
|
||||
@@ -274,10 +267,6 @@ export const hotelQueryRouter = router({
|
||||
roomStayStartDate,
|
||||
roomStayEndDate,
|
||||
adults,
|
||||
children,
|
||||
promotionCode,
|
||||
reservationProfileType,
|
||||
attachedProfileId,
|
||||
error_type: "http_error",
|
||||
error: JSON.stringify({
|
||||
status: apiResponse.status,
|
||||
@@ -307,10 +296,6 @@ export const hotelQueryRouter = router({
|
||||
roomStayStartDate,
|
||||
roomStayEndDate,
|
||||
adults,
|
||||
children,
|
||||
promotionCode,
|
||||
reservationProfileType,
|
||||
attachedProfileId,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validateAvailabilityData.error),
|
||||
})
|
||||
@@ -328,18 +313,20 @@ export const hotelQueryRouter = router({
|
||||
roomStayStartDate,
|
||||
roomStayEndDate,
|
||||
adults,
|
||||
children,
|
||||
promotionCode,
|
||||
reservationProfileType,
|
||||
attachedProfileId,
|
||||
})
|
||||
console.info(
|
||||
"api.hotels.availability success",
|
||||
JSON.stringify({
|
||||
query: { cityId, params: params },
|
||||
})
|
||||
)
|
||||
return {
|
||||
availability: validateAvailabilityData.data,
|
||||
availability: validateAvailabilityData.data.data
|
||||
.filter(
|
||||
(hotels) =>
|
||||
hotels.attributes.status === AvailabilityEnum.Available
|
||||
)
|
||||
.flatMap((hotels) => hotels.attributes),
|
||||
}
|
||||
}),
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user