feat(SW-251): use response to render filters
This commit is contained in:
@@ -33,7 +33,7 @@ async function getAvailableHotels({
|
|||||||
const { availability } = getAvailableHotels
|
const { availability } = getAvailableHotels
|
||||||
|
|
||||||
const hotels = availability.map(async (hotel) => {
|
const hotels = availability.map(async (hotel) => {
|
||||||
const hotelData = await serverClient().hotel.hotel.get({
|
const hotelData = await serverClient().hotel.hotelData.get({
|
||||||
hotelId: hotel.hotelId.toString(),
|
hotelId: hotel.hotelId.toString(),
|
||||||
language: getLang(),
|
language: getLang(),
|
||||||
})
|
})
|
||||||
@@ -53,7 +53,6 @@ export default async function SelectHotelPage({
|
|||||||
setLang(params.lang)
|
setLang(params.lang)
|
||||||
|
|
||||||
const tempSearchTerm = "Stockholm"
|
const tempSearchTerm = "Stockholm"
|
||||||
|
|
||||||
const intl = await getIntl()
|
const intl = await getIntl()
|
||||||
|
|
||||||
const hotels = await getAvailableHotels({
|
const hotels = await getAvailableHotels({
|
||||||
@@ -64,9 +63,37 @@ export default async function SelectHotelPage({
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (!hotels) return null
|
if (!hotels) return null
|
||||||
|
|
||||||
if (hotels.some((item) => item?.hotelData === undefined)) return notFound()
|
if (hotels.some((item) => item?.hotelData === undefined)) return notFound()
|
||||||
|
|
||||||
|
const filters = hotels.flatMap((data) => data.hotelData?.detailedFacilities)
|
||||||
|
|
||||||
|
const filterId = [...new Set(filters.map((data) => data?.id))]
|
||||||
|
const filterList: {
|
||||||
|
name: string
|
||||||
|
id: number
|
||||||
|
applyToAllHotels: boolean
|
||||||
|
public: boolean
|
||||||
|
icon: string
|
||||||
|
sortOrder: number
|
||||||
|
code?: string
|
||||||
|
iconName?: string
|
||||||
|
}[] = filterId
|
||||||
|
.map((data) => filters.find((find) => find?.id === data))
|
||||||
|
.filter(
|
||||||
|
(
|
||||||
|
filter
|
||||||
|
): filter is {
|
||||||
|
name: string
|
||||||
|
id: number
|
||||||
|
applyToAllHotels: boolean
|
||||||
|
public: boolean
|
||||||
|
icon: string
|
||||||
|
sortOrder: number
|
||||||
|
code?: string
|
||||||
|
iconName?: string
|
||||||
|
} => filter !== undefined
|
||||||
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main className={styles.main}>
|
<main className={styles.main}>
|
||||||
<section className={styles.section}>
|
<section className={styles.section}>
|
||||||
@@ -82,7 +109,7 @@ export default async function SelectHotelPage({
|
|||||||
{intl.formatMessage({ id: "Show map" })}
|
{intl.formatMessage({ id: "Show map" })}
|
||||||
<ChevronRightIcon color="burgundy" />
|
<ChevronRightIcon color="burgundy" />
|
||||||
</Link>
|
</Link>
|
||||||
<HotelFilter />
|
<HotelFilter filters={filterList} />
|
||||||
</section>
|
</section>
|
||||||
<HotelCardListing hotelData={hotels} />
|
<HotelCardListing hotelData={hotels} />
|
||||||
</main>
|
</main>
|
||||||
|
|||||||
@@ -25,19 +25,16 @@ export default function HotelCard({ hotel }: HotelCardProps) {
|
|||||||
const { hotelData } = hotel
|
const { hotelData } = hotel
|
||||||
const { price } = hotel
|
const { price } = hotel
|
||||||
|
|
||||||
if (!hotelData) return null
|
const sortedAmenities = hotelData?.detailedFacilities
|
||||||
if (!price) return null
|
.sort((a, b) => b.sortOrder - a.sortOrder)
|
||||||
|
|
||||||
const sortedAmenities = hotelData.detailedFacilities
|
|
||||||
?.sort((a, b) => b.sortOrder - a.sortOrder)
|
|
||||||
.slice(0, 5)
|
.slice(0, 5)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<article className={styles.card}>
|
<article className={styles.card}>
|
||||||
<section className={styles.imageContainer}>
|
<section className={styles.imageContainer}>
|
||||||
<Image
|
<Image
|
||||||
src={hotelData.hotelContent.images.imageSizes.medium}
|
src={hotelData?.hotelContent.images.imageSizes.medium ?? ""}
|
||||||
alt={hotelData.hotelContent.images.metaData.altText}
|
alt={hotelData?.hotelContent.images.metaData.altText ?? ""}
|
||||||
width={300}
|
width={300}
|
||||||
height={200}
|
height={200}
|
||||||
className={styles.image}
|
className={styles.image}
|
||||||
@@ -45,20 +42,20 @@ export default function HotelCard({ hotel }: HotelCardProps) {
|
|||||||
<div className={styles.tripAdvisor}>
|
<div className={styles.tripAdvisor}>
|
||||||
<Chip intent="primary" className={styles.tripAdvisor}>
|
<Chip intent="primary" className={styles.tripAdvisor}>
|
||||||
<TripAdvisorIcon color="white" />
|
<TripAdvisorIcon color="white" />
|
||||||
{hotelData.ratings?.tripAdvisor.rating}
|
{hotelData?.ratings?.tripAdvisor.rating}
|
||||||
</Chip>
|
</Chip>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
<section className={styles.hotelInformation}>
|
<section className={styles.hotelInformation}>
|
||||||
<ScandicLogoIcon color="red" />
|
<ScandicLogoIcon color="red" />
|
||||||
<Title as="h4" textTransform="capitalize">
|
<Title as="h4" textTransform="capitalize">
|
||||||
{hotelData.name}
|
{hotelData?.name}
|
||||||
</Title>
|
</Title>
|
||||||
<Footnote color="textMediumContrast" className={styles.adress}>
|
<Footnote color="textMediumContrast" className={styles.adress}>
|
||||||
{`${hotelData.address?.streetAddress}, ${hotelData.address?.city}`}
|
{`${hotelData?.address?.streetAddress}, ${hotelData?.address?.city}`}
|
||||||
</Footnote>
|
</Footnote>
|
||||||
<Footnote color="textMediumContrast">
|
<Footnote color="textMediumContrast">
|
||||||
{`${hotelData.location.distanceToCentre} ${intl.formatMessage({ id: "km to city center" })}`}
|
{`${hotelData?.location.distanceToCentre} ${intl.formatMessage({ id: "km to city center" })}`}
|
||||||
</Footnote>
|
</Footnote>
|
||||||
</section>
|
</section>
|
||||||
<section className={styles.hotel}>
|
<section className={styles.hotel}>
|
||||||
|
|||||||
@@ -1,23 +1,28 @@
|
|||||||
import { getIntl } from "@/i18n"
|
"use client"
|
||||||
|
|
||||||
|
import { useIntl } from "react-intl"
|
||||||
|
|
||||||
import styles from "./hotelFilter.module.css"
|
import styles from "./hotelFilter.module.css"
|
||||||
|
|
||||||
export default async function HotelFilter() {
|
import { HotelFiltersProps } from "@/types/components/hotelReservation/selectHotel/hotelFilters"
|
||||||
const intl = await getIntl()
|
|
||||||
|
export default function HotelFilter({ filters }: HotelFiltersProps) {
|
||||||
|
const intl = useIntl()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<aside className={styles.container}>
|
<aside className={styles.container}>
|
||||||
<div className={styles.facilities}>
|
<div className={styles.facilities}>
|
||||||
{intl.formatMessage({ id: "Hotel facilities" })}
|
{intl.formatMessage({ id: "Hotel facilities" })}
|
||||||
</div>
|
<form>
|
||||||
<div className={styles.facilities}>
|
<ul>
|
||||||
{intl.formatMessage({ id: "Hotel surroundings" })}
|
{filters.map((data) => (
|
||||||
{/* {filters.hotelSurroundings.map((surroundings) => (
|
<li key={data?.id} className={styles.filter}>
|
||||||
<div key={surroundings} className={styles.filter}>
|
<input id={`${data?.id}`} name={data?.name} type="checkbox" />
|
||||||
<input id={surroundings} name={surroundings} type="checkbox" />
|
<label htmlFor={`${data?.id}`}>{data?.name}</label>
|
||||||
<label htmlFor={surroundings}>{surroundings}</label>
|
</li>
|
||||||
</div>
|
))}
|
||||||
))} */}
|
</ul>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</aside>
|
</aside>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ export const getRatesInputSchema = z.object({
|
|||||||
hotelId: z.string(),
|
hotelId: z.string(),
|
||||||
})
|
})
|
||||||
|
|
||||||
export const getPlaceholderInputSchema = z.object({
|
export const getlHotelDataInputSchema = z.object({
|
||||||
hotelId: z.string(),
|
hotelId: z.string(),
|
||||||
language: z.string(),
|
language: z.string(),
|
||||||
include: z
|
include: z
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import {
|
|||||||
import {
|
import {
|
||||||
getAvailabilityInputSchema,
|
getAvailabilityInputSchema,
|
||||||
getHotelInputSchema,
|
getHotelInputSchema,
|
||||||
getPlaceholderInputSchema,
|
getlHotelDataInputSchema,
|
||||||
getRatesInputSchema,
|
getRatesInputSchema,
|
||||||
} from "./input"
|
} from "./input"
|
||||||
import {
|
import {
|
||||||
@@ -55,10 +55,6 @@ const availabilityFailCounter = meter.createCounter(
|
|||||||
"trpc.hotel.availability-fail"
|
"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(
|
async function getContentstackData(
|
||||||
locale: string,
|
locale: string,
|
||||||
uid: string | null | undefined
|
uid: string | null | undefined
|
||||||
@@ -421,9 +417,9 @@ export const hotelQueryRouter = router({
|
|||||||
return validatedHotelData.data
|
return validatedHotelData.data
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
hotel: router({
|
hotelData: router({
|
||||||
get: serviceProcedure
|
get: serviceProcedure
|
||||||
.input(getPlaceholderInputSchema)
|
.input(getlHotelDataInputSchema)
|
||||||
.query(async ({ ctx, input }) => {
|
.query(async ({ ctx, input }) => {
|
||||||
const { hotelId, language, include } = input
|
const { hotelId, language, include } = input
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import { Hotel } from "@/types/hotel"
|
||||||
|
|
||||||
|
export type HotelFiltersProps = {
|
||||||
|
filters: Hotel["detailedFacilities"]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user