feat(sw-453): fixed pr comments and default filter
This commit is contained in:
@@ -17,7 +17,7 @@ import { getIconForFeatureCode } from "../utils"
|
||||
import styles from "./roomFilter.module.css"
|
||||
|
||||
import {
|
||||
RoomFilterProps,
|
||||
type RoomFilterProps,
|
||||
RoomPackageCodeEnum,
|
||||
} from "@/types/components/hotelReservation/selectRate/roomFilter"
|
||||
|
||||
@@ -47,8 +47,8 @@ export default function RoomFilter({
|
||||
})
|
||||
|
||||
const { watch, getValues, handleSubmit } = methods
|
||||
const petFriendly = watch(RoomPackageCodeEnum.PETR)
|
||||
const allergyFriendly = watch(RoomPackageCodeEnum.ALLG)
|
||||
const petFriendly = watch(RoomPackageCodeEnum.PET_ROOM)
|
||||
const allergyFriendly = watch(RoomPackageCodeEnum.ALLERGY_ROOM)
|
||||
|
||||
const selectedFilters = useMemo(() => getValues(), [getValues])
|
||||
|
||||
@@ -104,8 +104,10 @@ export default function RoomFilter({
|
||||
key={option.code}
|
||||
label={intl.formatMessage({ id: option.description })}
|
||||
disabled={
|
||||
(option.code === RoomPackageCodeEnum.ALLG && petFriendly) ||
|
||||
(option.code === RoomPackageCodeEnum.PETR && allergyFriendly)
|
||||
(option.code === RoomPackageCodeEnum.ALLERGY_ROOM &&
|
||||
petFriendly) ||
|
||||
(option.code === RoomPackageCodeEnum.PET_ROOM &&
|
||||
allergyFriendly)
|
||||
}
|
||||
selected={getValues(option.code)}
|
||||
Icon={getIconForFeatureCode(option.code)}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { differenceInCalendarDays } from "date-fns"
|
||||
import { useIntl } from "react-intl"
|
||||
|
||||
import Button from "@/components/TempDesignSystem/Button"
|
||||
@@ -27,12 +28,12 @@ export default function RateSummary({
|
||||
} = rateSummary
|
||||
const priceToShow = isUserLoggedIn ? member : publicRate
|
||||
|
||||
const isPetRoomSelect = features.some(
|
||||
(feature) => feature.code === RoomPackageCodeEnum.PETR
|
||||
const isPetRoomSelected = features.some(
|
||||
(feature) => feature.code === RoomPackageCodeEnum.PET_ROOM
|
||||
)
|
||||
|
||||
const petRoomPackage = packages.find(
|
||||
(pkg) => pkg.code === RoomPackageCodeEnum.PETR
|
||||
(pkg) => pkg.code === RoomPackageCodeEnum.PET_ROOM
|
||||
)
|
||||
|
||||
const petRoomPrice = petRoomPackage?.calculatedPrice ?? null
|
||||
@@ -40,9 +41,7 @@ export default function RateSummary({
|
||||
|
||||
const checkInDate = new Date(roomsAvailability.checkInDate)
|
||||
const checkOutDate = new Date(roomsAvailability.checkOutDate)
|
||||
const nights = Math.ceil(
|
||||
(checkOutDate.getTime() - checkInDate.getTime()) / (1000 * 60 * 60 * 24)
|
||||
)
|
||||
const nights = differenceInCalendarDays(checkOutDate, checkInDate)
|
||||
|
||||
return (
|
||||
<div className={styles.summary}>
|
||||
@@ -94,7 +93,7 @@ export default function RateSummary({
|
||||
)}
|
||||
</Footnote>
|
||||
</div>
|
||||
{isPetRoomSelect && (
|
||||
{isPetRoomSelected && (
|
||||
<div className={styles.petInfo}>
|
||||
<Body color="uiTextHighContrast" textTransform="bold">
|
||||
+ {petRoomPrice} {petRoomCurrency}
|
||||
|
||||
@@ -27,20 +27,18 @@ export default function RoomCard({
|
||||
}: RoomCardProps) {
|
||||
const intl = useIntl()
|
||||
|
||||
// TODO: Update string when API has decided
|
||||
const rateTypes = {
|
||||
saveRate: "NonCancellable",
|
||||
changeRate: "Modifiable",
|
||||
flexRate: "CancellableBefore6PM",
|
||||
const rates = {
|
||||
saveRate: rateDefinitions.find(
|
||||
(rate) => rate.cancellationRule === "NonCancellable"
|
||||
),
|
||||
changeRate: rateDefinitions.find(
|
||||
(rate) => rate.cancellationRule === "Modifiable"
|
||||
),
|
||||
flexRate: rateDefinitions.find(
|
||||
(rate) => rate.cancellationRule === "CancellableBefore6PM"
|
||||
),
|
||||
}
|
||||
|
||||
const rates = Object.fromEntries(
|
||||
Object.entries(rateTypes).map(([key, rule]) => [
|
||||
key,
|
||||
rateDefinitions.find((rate) => rate.cancellationRule === rule),
|
||||
])
|
||||
)
|
||||
|
||||
function findProductForRate(rate: RateDefinition | undefined) {
|
||||
return rate
|
||||
? roomConfiguration.products.find(
|
||||
|
||||
@@ -8,8 +8,8 @@ import getHotelReservationQueryParams from "./utils"
|
||||
|
||||
import styles from "./roomSelection.module.css"
|
||||
|
||||
import { RoomSelectionProps } from "@/types/components/hotelReservation/selectRate/roomSelection"
|
||||
import { Rate } from "@/types/components/hotelReservation/selectRate/selectRate"
|
||||
import type { RoomSelectionProps } from "@/types/components/hotelReservation/selectRate/roomSelection"
|
||||
import type { Rate } from "@/types/components/hotelReservation/selectRate/selectRate"
|
||||
|
||||
export default function RoomSelection({
|
||||
roomsAvailability,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use client"
|
||||
|
||||
import { useCallback,useState } from "react"
|
||||
import { useCallback, useState } from "react"
|
||||
|
||||
import { RoomsAvailability } from "@/server/routers/hotels/output"
|
||||
|
||||
@@ -9,8 +9,7 @@ import RoomSelection from "../RoomSelection"
|
||||
|
||||
import styles from "./rooms.module.css"
|
||||
|
||||
import { RoomPackageCodes } from "@/types/components/hotelReservation/selectRate/roomFilter"
|
||||
import { RoomSelectionProps } from "@/types/components/hotelReservation/selectRate/roomSelection"
|
||||
import type { RoomSelectionProps } from "@/types/components/hotelReservation/selectRate/roomSelection"
|
||||
|
||||
export default function Rooms({
|
||||
roomsAvailability,
|
||||
@@ -18,26 +17,35 @@ export default function Rooms({
|
||||
user,
|
||||
packages,
|
||||
}: RoomSelectionProps) {
|
||||
const [rooms, setRooms] = useState<RoomsAvailability>(roomsAvailability)
|
||||
const defaultRooms = roomsAvailability.roomConfigurations.filter(
|
||||
(room) => room.features.length === 0
|
||||
)
|
||||
const [rooms, setRooms] = useState<RoomsAvailability>({
|
||||
...roomsAvailability,
|
||||
roomConfigurations: defaultRooms,
|
||||
})
|
||||
|
||||
console.log(rooms)
|
||||
|
||||
const handleFilter = useCallback(
|
||||
(filter: Record<string, boolean | undefined>) => {
|
||||
const selectedCodes = Object.keys(filter).filter((key) => filter[key])
|
||||
|
||||
if (selectedCodes.length === 0) {
|
||||
setRooms(roomsAvailability)
|
||||
setRooms({
|
||||
...roomsAvailability,
|
||||
roomConfigurations: defaultRooms,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
const filteredRooms = roomsAvailability.roomConfigurations.filter(
|
||||
(room) =>
|
||||
room.features.some((feature) =>
|
||||
selectedCodes.includes(feature.code as RoomPackageCodes)
|
||||
)
|
||||
room.features.some((feature) => selectedCodes.includes(feature.code))
|
||||
)
|
||||
setRooms({ ...roomsAvailability, roomConfigurations: filteredRooms })
|
||||
},
|
||||
[roomsAvailability]
|
||||
[roomsAvailability, defaultRooms]
|
||||
)
|
||||
|
||||
return (
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import { AllergyIcon,PetsIcon, WheelchairIcon } from "@/components/Icons"
|
||||
import { AllergyIcon, PetsIcon, WheelchairIcon } from "@/components/Icons"
|
||||
|
||||
import {
|
||||
RoomPackageCodeEnum,
|
||||
RoomPackageCodes,
|
||||
type RoomPackageCodes,
|
||||
} from "@/types/components/hotelReservation/selectRate/roomFilter"
|
||||
|
||||
export function getIconForFeatureCode(featureCode: RoomPackageCodes) {
|
||||
switch (featureCode) {
|
||||
case RoomPackageCodeEnum.ACCE:
|
||||
case RoomPackageCodeEnum.ACCESSIBILITY_ROOM:
|
||||
return WheelchairIcon
|
||||
case RoomPackageCodeEnum.ALLG:
|
||||
case RoomPackageCodeEnum.ALLERGY_ROOM:
|
||||
return AllergyIcon
|
||||
case RoomPackageCodeEnum.PETR:
|
||||
case RoomPackageCodeEnum.PET_ROOM:
|
||||
return PetsIcon
|
||||
default:
|
||||
return PetsIcon
|
||||
|
||||
Reference in New Issue
Block a user