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