feat: filters work together
This commit is contained in:
committed by
Michael Zetterberg
parent
31370fe711
commit
d72c84d949
@@ -6,7 +6,7 @@ import {
|
||||
getBreakfastPackages,
|
||||
getHotel,
|
||||
getProfileSafely,
|
||||
getSelectedRoomsAvailability,
|
||||
getSelectedRoomsAvailabilityEnterDetails,
|
||||
} from "@/lib/trpc/memoizedRequests"
|
||||
|
||||
import HotelHeader from "@/components/HotelReservation/EnterDetails/Header"
|
||||
@@ -61,7 +61,7 @@ export default async function DetailsPage({
|
||||
void getBreakfastPackages(breakfastInput)
|
||||
void getProfileSafely()
|
||||
|
||||
const roomsAvailability = await getSelectedRoomsAvailability({
|
||||
const roomsAvailability = await getSelectedRoomsAvailabilityEnterDetails({
|
||||
booking,
|
||||
lang,
|
||||
})
|
||||
|
||||
@@ -79,6 +79,7 @@ export default function useModifyStay({
|
||||
const data = await utils.hotel.availability.myStay.fetch({
|
||||
booking: {
|
||||
fromDate: formValues.checkInDate,
|
||||
toDate: formValues.checkOutDate,
|
||||
hotelId: bookedRoom.hotelId,
|
||||
room: {
|
||||
adults: bookedRoom.adults,
|
||||
@@ -87,7 +88,6 @@ export default function useModifyStay({
|
||||
rateCode: bookedRoom.rateDefinition.rateCode,
|
||||
roomTypeCode: bookedRoom.roomTypeCode,
|
||||
},
|
||||
toDate: formValues.checkOutDate,
|
||||
},
|
||||
lang,
|
||||
})
|
||||
|
||||
@@ -21,7 +21,6 @@ import { getTotalPrice } from "./utils"
|
||||
import styles from "./rateSummary.module.css"
|
||||
|
||||
import type { RateSummaryProps } from "@/types/components/hotelReservation/selectRate/rateSummary"
|
||||
import { RoomPackageCodeEnum } from "@/types/components/hotelReservation/selectRate/roomFilter"
|
||||
import { RateEnum } from "@/types/enums/rate"
|
||||
import { RateTypeEnum } from "@/types/enums/rateType"
|
||||
|
||||
@@ -265,15 +264,12 @@ export default function RateSummary({ isUserLoggedIn }: RateSummaryProps) {
|
||||
return total
|
||||
}
|
||||
|
||||
const hasSelectedPetRoom = roomPackages.find(
|
||||
(pkg) => pkg.code === RoomPackageCodeEnum.PET_ROOM
|
||||
)
|
||||
if (!hasSelectedPetRoom) {
|
||||
return total + price
|
||||
}
|
||||
return (
|
||||
total + price + hasSelectedPetRoom.localPrice.totalPrice
|
||||
const selectedPackagesPrice = roomPackages.reduce(
|
||||
(acc, pkg) => acc + pkg.localPrice.totalPrice,
|
||||
0
|
||||
)
|
||||
|
||||
return total + price + selectedPackagesPrice
|
||||
}, 0),
|
||||
currency: mainRoomCurrency,
|
||||
}}
|
||||
|
||||
@@ -16,7 +16,6 @@ import { useRoomContext } from "@/contexts/SelectRate/Room"
|
||||
|
||||
import styles from "./selectedRoomPanel.module.css"
|
||||
|
||||
import { RoomPackageCodeEnum } from "@/types/components/hotelReservation/selectRate/roomFilter"
|
||||
import { CurrencyEnum } from "@/types/enums/currency"
|
||||
import { RateEnum } from "@/types/enums/rate"
|
||||
|
||||
@@ -70,13 +69,11 @@ export default function SelectedRoomPanel() {
|
||||
return null
|
||||
}
|
||||
|
||||
let petRoomPrice = 0
|
||||
const petRoomPackageSelected = selectedPackages.find(
|
||||
(pkg) => pkg.code === RoomPackageCodeEnum.PET_ROOM
|
||||
const selectedPackagesPrice = selectedPackages.reduce(
|
||||
(total, pkg) => total + pkg.localPrice.totalPrice,
|
||||
0
|
||||
)
|
||||
if (petRoomPackageSelected) {
|
||||
petRoomPrice = petRoomPackageSelected.localPrice.totalPrice / nights
|
||||
}
|
||||
const selectedPackagesPricePerNight = selectedPackagesPrice / nights
|
||||
|
||||
const night = intl.formatMessage({ id: "night" })
|
||||
let selectedProduct
|
||||
@@ -87,10 +84,10 @@ export default function SelectedRoomPanel() {
|
||||
selectedRate.product.member
|
||||
) {
|
||||
const { localPrice } = selectedRate.product.member
|
||||
selectedProduct = `${localPrice.pricePerNight + petRoomPrice} ${localPrice.currency} / ${night}`
|
||||
selectedProduct = `${localPrice.pricePerNight + selectedPackagesPricePerNight} ${localPrice.currency} / ${night}`
|
||||
} else if ("public" in selectedRate.product && selectedRate.product.public) {
|
||||
const { localPrice } = selectedRate.product.public
|
||||
selectedProduct = `${localPrice.pricePerNight + petRoomPrice} ${localPrice.currency} / ${night}`
|
||||
selectedProduct = `${localPrice.pricePerNight + selectedPackagesPricePerNight} ${localPrice.currency} / ${night}`
|
||||
} else if ("corporateCheque" in selectedRate.product) {
|
||||
const { localPrice } = selectedRate.product.corporateCheque
|
||||
selectedProduct = `${localPrice.numberOfCheques} ${CurrencyEnum.CC}`
|
||||
|
||||
@@ -63,26 +63,25 @@ export default function BookingCodeFilter() {
|
||||
appendRegularRates(room?.roomConfigurations)
|
||||
}
|
||||
|
||||
const hideFilterDespiteBookingCode =
|
||||
rooms.length &&
|
||||
rooms.every((room) =>
|
||||
room.products.every((product) => {
|
||||
const isRedemption = Array.isArray(product)
|
||||
if (isRedemption) {
|
||||
return true
|
||||
}
|
||||
const isCorporateCheque =
|
||||
product.rateDefinition?.rateType === RateTypeEnum.CorporateCheque
|
||||
const isVoucher =
|
||||
product.rateDefinition?.rateType === RateTypeEnum.Voucher
|
||||
return isCorporateCheque || isVoucher
|
||||
})
|
||||
)
|
||||
const hideFilter = rooms.some((room) =>
|
||||
room.products.some((product) => {
|
||||
const isRedemption = Array.isArray(product)
|
||||
if (isRedemption) {
|
||||
return true
|
||||
}
|
||||
|
||||
if (
|
||||
(booking.bookingCode && hideFilterDespiteBookingCode) ||
|
||||
!booking.bookingCode
|
||||
) {
|
||||
switch (product.rateDefinition.rateType) {
|
||||
case RateTypeEnum.Arb:
|
||||
case RateTypeEnum.CorporateCheque:
|
||||
case RateTypeEnum.Voucher:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
if (hideFilter || !booking.bookingCode) {
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import type { SymbolCodepoints } from "react-material-symbols"
|
||||
import type { MaterialSymbolProps } from "react-material-symbols"
|
||||
|
||||
import { RoomPackageCodeEnum } from "@/types/components/hotelReservation/selectRate/roomFilter"
|
||||
import type { PackageEnum } from "@/types/requests/packages"
|
||||
|
||||
export function getIconNameByPackageCode(
|
||||
packageCode: PackageEnum
|
||||
): SymbolCodepoints {
|
||||
): MaterialSymbolProps["icon"] {
|
||||
switch (packageCode) {
|
||||
case RoomPackageCodeEnum.PET_ROOM:
|
||||
return "pets"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { SymbolCodepoints } from "react-material-symbols"
|
||||
import type { MaterialSymbolProps } from "react-material-symbols"
|
||||
|
||||
export function getBedIconName(name: string): SymbolCodepoints {
|
||||
export function getBedIconName(name: string): MaterialSymbolProps["icon"] {
|
||||
const iconMappings = [
|
||||
{
|
||||
icon: "bed",
|
||||
@@ -25,5 +25,5 @@ export function getBedIconName(name: string): SymbolCodepoints {
|
||||
]
|
||||
|
||||
const icon = iconMappings.find((icon) => icon.texts.includes(name))
|
||||
return icon ? (icon.icon as SymbolCodepoints) : "single_bed"
|
||||
return icon ? (icon.icon as MaterialSymbolProps["icon"]) : "single_bed"
|
||||
}
|
||||
|
||||
@@ -608,7 +608,7 @@
|
||||
"Pet room charge including VAT": "Gebyr for kæledyrsværelse inkl. moms",
|
||||
"Pet-friendly": "Kæledyrsvenlig",
|
||||
"Pet-friendly rooms have an additional fee of 20 EUR per stay": "Kæledyrsrum har en ekstra gebyr på 20 EUR per ophold",
|
||||
"Pet-friendly rooms include a charge of approx. <b>{price}/stay</b>": "Kæledyrsvenlige værelser inkluderer et gebyr på ca. <b>{price}</b>/ophold",
|
||||
"Pet-friendly rooms include a charge of approx. <b>{price}/stay</b>": "Kæledyrsvenlige værelser inkluderer et gebyr på ca. <b>{price}/ophold</b>",
|
||||
"Phone": "Telefon",
|
||||
"Phone is required": "Telefonnummer er påkrævet",
|
||||
"Phone number": "Telefonnummer",
|
||||
|
||||
@@ -607,7 +607,7 @@
|
||||
"Pet room charge including VAT": "Haustierzimmergebühr inkl. MwSt.",
|
||||
"Pet-friendly": "Haustierfreundlich",
|
||||
"Pet-friendly rooms have an additional fee of 20 EUR per stay": "Haustierzimmer haben einen zusätzlichen Preis von 20 EUR pro Aufenthalt",
|
||||
"Pet-friendly rooms include a charge of approx. <b>{price}/stay</b>": "Für haustierfreundliche Zimmer fällt eine Gebühr von ca. <b>{price}</b>/Aufenthalt an.",
|
||||
"Pet-friendly rooms include a charge of approx. <b>{price}/stay</b>": "Für haustierfreundliche Zimmer fällt eine Gebühr von ca. <b>{price}/Aufenthalt an.</b>",
|
||||
"Phone": "Telefon",
|
||||
"Phone is required": "Telefon ist erforderlich",
|
||||
"Phone number": "Telefonnummer",
|
||||
|
||||
@@ -606,7 +606,7 @@
|
||||
"Pet room charge including VAT": "Lemmikkihuoneen maksu sis. ALV",
|
||||
"Pet-friendly": "Lemmikkiystävällinen",
|
||||
"Pet-friendly rooms have an additional fee of 20 EUR per stay": "Lemmikkihuoneen lisäkustannus on 20 EUR per majoitus",
|
||||
"Pet-friendly rooms include a charge of approx. <b>{price}/stay</b>": "Lemmikkiystävälliset huoneet sisältävät n. <b>{price}</b>/yöpyminen",
|
||||
"Pet-friendly rooms include a charge of approx. <b>{price}/stay</b>": "Lemmikkiystävälliset huoneet sisältävät n. <b>{price}/yöpyminen</b>",
|
||||
"Phone": "Puhelin",
|
||||
"Phone is required": "Puhelin vaaditaan",
|
||||
"Phone number": "Puhelinnumero",
|
||||
|
||||
@@ -605,7 +605,7 @@
|
||||
"Pet room charge including VAT": "Kjæledyrromsgebyr inkl. MVA",
|
||||
"Pet-friendly": "Dyrevennlig",
|
||||
"Pet-friendly rooms have an additional fee of 20 EUR per stay": "Kjæledyrsrom har en tilleggsavgift på 20 EUR per opphold",
|
||||
"Pet-friendly rooms include a charge of approx. <b>{price}/stay</b>": "Kjæledyrvennlige rom inkluderer en kostnad på ca. <b>{price}</b>/opphold",
|
||||
"Pet-friendly rooms include a charge of approx. <b>{price}/stay</b>": "Kjæledyrvennlige rom inkluderer en kostnad på ca. <b>{price}/opphold</b>",
|
||||
"Phone": "Telefon",
|
||||
"Phone is required": "Telefon kreves",
|
||||
"Phone number": "Telefonnummer",
|
||||
|
||||
@@ -605,7 +605,7 @@
|
||||
"Pet room charge including VAT": "Avgift för husdjursrum inkl. moms",
|
||||
"Pet-friendly": "Husdjursvänlig",
|
||||
"Pet-friendly rooms have an additional fee of 20 EUR per stay": "Husdjursrum har en extra avgift på 20 EUR per vistelse",
|
||||
"Pet-friendly rooms include a charge of approx. <b>{price}/stay</b>": "Husdjursvänliga rum har en avgift på ca. <b>{price}/vistelse",
|
||||
"Pet-friendly rooms include a charge of approx. <b>{price}/stay</b>": "Husdjursvänliga rum har en avgift på ca. <b>{price}/vistelse</b>",
|
||||
"Phone": "Telefon",
|
||||
"Phone is required": "Telefonnummer är obligatorisk",
|
||||
"Phone number": "Telefonnummer",
|
||||
|
||||
@@ -339,7 +339,7 @@ export const getJumpToData = cache(async function getMemoizedJumpToData() {
|
||||
return null
|
||||
})
|
||||
|
||||
export const getSelectedRoomsAvailability = cache(
|
||||
export const getSelectedRoomsAvailabilityEnterDetails = cache(
|
||||
async function getMemoizedSelectedRoomsAvailability(
|
||||
input: RoomsAvailabilityExtendedInputSchema
|
||||
) {
|
||||
|
||||
@@ -1252,12 +1252,12 @@ export async function getRoomsAvailability(
|
||||
|
||||
const cacheClient = await getCacheClient()
|
||||
const availabilityResponses = await Promise.allSettled(
|
||||
rooms.map(async (room: RoomsAvailabilityInputRoom) => {
|
||||
rooms.map((room: RoomsAvailabilityInputRoom) => {
|
||||
const cacheKey = {
|
||||
...baseCacheKey,
|
||||
room,
|
||||
}
|
||||
return await cacheClient.cacheOrGet(
|
||||
return cacheClient.cacheOrGet(
|
||||
stringify(cacheKey),
|
||||
async function () {
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user