fix: apply logic for full prices filter

This commit is contained in:
Simon Emanuelsson
2025-04-03 10:09:59 +02:00
committed by Michael Zetterberg
parent 3942ab1ff4
commit 8a7c55edff
8 changed files with 65 additions and 19 deletions

View File

@@ -29,11 +29,11 @@ export default function BookingCodeFilter() {
value: BookingCodeFilterEnum.Discounted,
},
{
label: intl.formatMessage({ id: "Full price rooms" }),
label: intl.formatMessage({ id: "Full-priced rooms" }),
value: BookingCodeFilterEnum.Regular,
},
{
label: intl.formatMessage({ id: "See all" }),
label: intl.formatMessage({ id: "All rooms" }),
value: BookingCodeFilterEnum.All,
},
]

View File

@@ -44,6 +44,14 @@ export default function Campaign({
const night = intl.formatMessage({ id: "night" }).toUpperCase()
if (selectedFilter === BookingCodeFilterEnum.Discounted) {
campaign = campaign.filter((product) => product.bookingCode)
}
if (selectedFilter === BookingCodeFilterEnum.Regular) {
campaign = campaign.filter((product) => !product.bookingCode)
}
return campaign.map((product) => {
if (!product.public) {
return (

View File

@@ -17,6 +17,7 @@ import {
import { calculatePricePerNightPriceProduct } from "./totalPricePerNight"
import type { SharedRateCardProps } from "@/types/components/hotelReservation/selectRate/rates"
import { BookingCodeFilterEnum } from "@/types/enums/bookingCodeFilter"
import type { CodeProduct } from "@/types/trpc/routers/hotel/roomAvailability"
interface CodeProps extends SharedRateCardProps {
@@ -31,11 +32,15 @@ export default function Code({
roomTypeCode,
}: CodeProps) {
const intl = useIntl()
const { roomNr, selectedRate } = useRoomContext()
const { roomNr, selectedFilter, selectedRate } = useRoomContext()
const bookingCode = useRatesStore((state) => state.booking.bookingCode)
const rateTitles = useRateTitles()
const night = intl.formatMessage({ id: "night" }).toUpperCase()
if (selectedFilter === BookingCodeFilterEnum.Regular) {
return null
}
return code.map((product) => {
let bannerText = ""
if (product.rateDefinition.breakfastIncluded) {

View File

@@ -25,6 +25,7 @@ export default function Redemptions({
if (
selectedFilter === BookingCodeFilterEnum.Discounted ||
selectedFilter === BookingCodeFilterEnum.Regular ||
!redemptions.length
) {
return null

View File

@@ -58,11 +58,16 @@ export default function Rates({
roomTypeCode,
}
const showAllRates = selectedFilter === BookingCodeFilterEnum.All
const showRegularRates = selectedFilter === BookingCodeFilterEnum.Regular
const hasBookingCodeRates = !!(campaign.length || code.length)
const hasRegularRates = !!regular.length
const notDiscountedPrice = showAllRates || showRegularRates
const notDiscountedAndHasRates =
notDiscountedPrice && hasBookingCodeRates && hasRegularRates
const isFetchingAndOnlyShowingRegularRates =
isFetchingAdditionalRate && !showRegularRates
const showDivider =
(showAllRates && hasBookingCodeRates && hasRegularRates) ||
isFetchingAdditionalRate
notDiscountedAndHasRates || isFetchingAndOnlyShowingRegularRates
return (
<>

View File

@@ -48,6 +48,7 @@
"All hotels and offices": "All hotels and offices",
"All locations": "All locations",
"All our breakfast buffets offer gluten free, vegan, and allergy-friendly options.": "All our breakfast buffets offer gluten free, vegan, and allergy-friendly options.",
"All rooms": "All rooms",
"All-day breakfast": "All-day breakfast",
"Allergy-friendly room": "Allergy-friendly room",
"Already a friend?": "Already a friend?",
@@ -323,6 +324,7 @@
"From": "From",
"Full circle": "Full circle",
"Full price rooms": "Full price rooms",
"Full-priced rooms": "Full-priced rooms",
"Garage": "Garage",
"Get directions": "Get directions",
"Get hotel directions": "Get hotel directions",

View File

@@ -1,6 +1,7 @@
"use client"
import { useEffect } from "react"
import { REDEMPTION } from "@/constants/booking"
import { trpc } from "@/lib/trpc/client"
import { useRatesStore } from "@/stores/select-rate"
@@ -17,17 +18,27 @@ export default function RoomProvider({
room,
}: RoomProviderProps) {
const lang = useLang()
const { activeRoom, booking, roomAvailability, selectedFilter } =
useRatesStore((state) => ({
activeRoom: state.activeRoom,
booking: state.booking,
roomAvailability: state.roomsAvailability?.[idx],
selectedFilter: state.rooms[idx].selectedFilter,
}))
const {
activeRoom,
booking,
roomAvailability,
searchParams,
selectedFilter,
} = useRatesStore((state) => ({
activeRoom: state.activeRoom,
booking: state.booking,
roomAvailability: state.roomsAvailability?.[idx],
searchParams: state.searchParams,
selectedFilter: state.rooms[idx].selectedFilter,
}))
const { appendRegularRates, ...actions } = room.actions
const roomNr = idx + 1
const hasRedemptionRates = room.rooms.some((room) => room.redemptions.length)
const redemptionSearch = searchParams.has("searchType")
? searchParams.get("searchType") === REDEMPTION
: false
const hasRedemptionRates =
redemptionSearch || room.rooms.some((room) => room.redemptions.length)
const hasCorporateChequeOrVoucherRates = room.rooms.some((room) =>
room.code.some((product) => {
if ("corporateCheque" in product) {
@@ -48,7 +59,7 @@ export default function RoomProvider({
// duplicate data
const enabled = !!(
booking.bookingCode &&
selectedFilter === BookingCodeFilterEnum.All &&
selectedFilter !== BookingCodeFilterEnum.Discounted &&
!dontShowRegularRates
)
// Extra query needed to fetch regular rates upon user

View File

@@ -15,7 +15,10 @@ import { RoomPackageCodeEnum } from "@/types/components/hotelReservation/selectR
import { BookingCodeFilterEnum } from "@/types/enums/bookingCodeFilter"
import { RateTypeEnum } from "@/types/enums/rateType"
import type { InitialState, RatesState } from "@/types/stores/rates"
import type { RoomConfiguration } from "@/types/trpc/routers/hotel/roomAvailability"
import type {
PriceProduct,
RoomConfiguration,
} from "@/types/trpc/routers/hotel/roomAvailability"
export function createRatesStore({
booking,
@@ -169,12 +172,23 @@ export function createRatesStore({
)
if (incomingRoom) {
let campaign = currentRoom.campaign
if (incomingRoom.campaign.length) {
const newCampaign = [
...campaign,
...incomingRoom.campaign,
].reduce((cpns, cpn) => {
if (cpns.has(cpn.rateDefinition.rateCode)) {
return cpns
}
cpns.set(cpn.rateDefinition.rateCode, cpn)
return cpns
}, new Map<string, PriceProduct>())
campaign = Array.from(newCampaign.values())
}
return {
...currentRoom,
campaign: [
...currentRoom.campaign,
...incomingRoom.campaign,
],
campaign,
products: [
...currentRoom.products,
...incomingRoom.products,