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, value: BookingCodeFilterEnum.Discounted,
}, },
{ {
label: intl.formatMessage({ id: "Full price rooms" }), label: intl.formatMessage({ id: "Full-priced rooms" }),
value: BookingCodeFilterEnum.Regular, value: BookingCodeFilterEnum.Regular,
}, },
{ {
label: intl.formatMessage({ id: "See all" }), label: intl.formatMessage({ id: "All rooms" }),
value: BookingCodeFilterEnum.All, value: BookingCodeFilterEnum.All,
}, },
] ]

View File

@@ -44,6 +44,14 @@ export default function Campaign({
const night = intl.formatMessage({ id: "night" }).toUpperCase() 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) => { return campaign.map((product) => {
if (!product.public) { if (!product.public) {
return ( return (

View File

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

View File

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

View File

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

View File

@@ -48,6 +48,7 @@
"All hotels and offices": "All hotels and offices", "All hotels and offices": "All hotels and offices",
"All locations": "All locations", "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 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", "All-day breakfast": "All-day breakfast",
"Allergy-friendly room": "Allergy-friendly room", "Allergy-friendly room": "Allergy-friendly room",
"Already a friend?": "Already a friend?", "Already a friend?": "Already a friend?",
@@ -323,6 +324,7 @@
"From": "From", "From": "From",
"Full circle": "Full circle", "Full circle": "Full circle",
"Full price rooms": "Full price rooms", "Full price rooms": "Full price rooms",
"Full-priced rooms": "Full-priced rooms",
"Garage": "Garage", "Garage": "Garage",
"Get directions": "Get directions", "Get directions": "Get directions",
"Get hotel directions": "Get hotel directions", "Get hotel directions": "Get hotel directions",

View File

@@ -1,6 +1,7 @@
"use client" "use client"
import { useEffect } from "react" import { useEffect } from "react"
import { REDEMPTION } from "@/constants/booking"
import { trpc } from "@/lib/trpc/client" import { trpc } from "@/lib/trpc/client"
import { useRatesStore } from "@/stores/select-rate" import { useRatesStore } from "@/stores/select-rate"
@@ -17,17 +18,27 @@ export default function RoomProvider({
room, room,
}: RoomProviderProps) { }: RoomProviderProps) {
const lang = useLang() const lang = useLang()
const { activeRoom, booking, roomAvailability, selectedFilter } = const {
useRatesStore((state) => ({ activeRoom,
activeRoom: state.activeRoom, booking,
booking: state.booking, roomAvailability,
roomAvailability: state.roomsAvailability?.[idx], searchParams,
selectedFilter: state.rooms[idx].selectedFilter, 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 { appendRegularRates, ...actions } = room.actions
const roomNr = idx + 1 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) => const hasCorporateChequeOrVoucherRates = room.rooms.some((room) =>
room.code.some((product) => { room.code.some((product) => {
if ("corporateCheque" in product) { if ("corporateCheque" in product) {
@@ -48,7 +59,7 @@ export default function RoomProvider({
// duplicate data // duplicate data
const enabled = !!( const enabled = !!(
booking.bookingCode && booking.bookingCode &&
selectedFilter === BookingCodeFilterEnum.All && selectedFilter !== BookingCodeFilterEnum.Discounted &&
!dontShowRegularRates !dontShowRegularRates
) )
// Extra query needed to fetch regular rates upon user // 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 { BookingCodeFilterEnum } from "@/types/enums/bookingCodeFilter"
import { RateTypeEnum } from "@/types/enums/rateType" import { RateTypeEnum } from "@/types/enums/rateType"
import type { InitialState, RatesState } from "@/types/stores/rates" 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({ export function createRatesStore({
booking, booking,
@@ -169,12 +172,23 @@ export function createRatesStore({
) )
if (incomingRoom) { 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 { return {
...currentRoom, ...currentRoom,
campaign: [ campaign,
...currentRoom.campaign,
...incomingRoom.campaign,
],
products: [ products: [
...currentRoom.products, ...currentRoom.products,
...incomingRoom.products, ...incomingRoom.products,