Feat/SW-2113 allow feature combinations * feat(SW-2113): Refactor features data to be fetched on filter room filter change * feat(SW-2113): added loading state * fix: now clear room selection when applying filter and room doesnt exists. And added room features to mobile summary * fix * fix: add package to price details * feat(SW-2113): added buttons to room filter * fix: active room * fix: remove console log * fix: added form and close handler to room package filter * fix: add restriction so you cannot select pet room with allergy room and vice versa * fix: fixes from review feedback * fix * fix: hide modify button if on nextcoming rooms if no selection is made, and adjust filter logic in togglePackage * fix: forgot to use roomFeatureCodes from input.. * fix: naming Approved-by: Simon.Emanuelsson
143 lines
4.0 KiB
TypeScript
143 lines
4.0 KiB
TypeScript
"use client"
|
|
import { useEffect, useRef, useState } from "react"
|
|
import { useIntl } from "react-intl"
|
|
|
|
import { useRatesStore } from "@/stores/select-rate"
|
|
|
|
import Button from "@/components/TempDesignSystem/Button"
|
|
import Caption from "@/components/TempDesignSystem/Text/Caption"
|
|
import Subtitle from "@/components/TempDesignSystem/Text/Subtitle"
|
|
import { formatPrice } from "@/utils/numberFormatting"
|
|
|
|
import { isBookingCodeRate } from "./isBookingCodeRate"
|
|
import { mapRate } from "./mapRate"
|
|
import Summary from "./Summary"
|
|
|
|
import styles from "./mobileSummary.module.css"
|
|
|
|
import type { MobileSummaryProps } from "@/types/components/hotelReservation/selectRate/rateSummary"
|
|
import type { RoomsAvailability } from "@/types/trpc/routers/hotel/roomAvailability"
|
|
|
|
export default function MobileSummary({
|
|
isAllRoomsSelected,
|
|
isUserLoggedIn,
|
|
totalPriceToShow,
|
|
}: MobileSummaryProps) {
|
|
const intl = useIntl()
|
|
const scrollY = useRef(0)
|
|
const [isSummaryOpen, setIsSummaryOpen] = useState(false)
|
|
|
|
const {
|
|
booking,
|
|
bookingRooms,
|
|
roomsAvailability,
|
|
rateSummary,
|
|
vat,
|
|
packages,
|
|
} = useRatesStore((state) => ({
|
|
booking: state.booking,
|
|
bookingRooms: state.booking.rooms,
|
|
roomsAvailability: state.roomsAvailability,
|
|
rateSummary: state.rateSummary,
|
|
vat: state.vat,
|
|
packages: state.packages,
|
|
}))
|
|
|
|
function toggleSummaryOpen() {
|
|
setIsSummaryOpen(!isSummaryOpen)
|
|
}
|
|
|
|
useEffect(() => {
|
|
if (isSummaryOpen) {
|
|
scrollY.current = window.scrollY
|
|
document.body.style.position = "fixed"
|
|
document.body.style.top = `-${scrollY.current}px`
|
|
document.body.style.width = "100%"
|
|
} else {
|
|
document.body.style.position = ""
|
|
document.body.style.top = ""
|
|
document.body.style.width = ""
|
|
window.scrollTo({
|
|
top: scrollY.current,
|
|
left: 0,
|
|
behavior: "instant",
|
|
})
|
|
}
|
|
|
|
return () => {
|
|
document.body.style.position = ""
|
|
document.body.style.top = ""
|
|
}
|
|
}, [isSummaryOpen])
|
|
|
|
const roomRateDefinitions = roomsAvailability?.find(
|
|
(ra): ra is RoomsAvailability => "rateDefinitions" in ra
|
|
)
|
|
if (!roomRateDefinitions) {
|
|
return null
|
|
}
|
|
|
|
const rooms = rateSummary.map((room, index) =>
|
|
room ? mapRate(room, index, bookingRooms, packages) : null
|
|
)
|
|
|
|
const containsBookingCodeRate = rateSummary.find(
|
|
(r) => r && isBookingCodeRate(r.product)
|
|
)
|
|
const showDiscounted = containsBookingCodeRate || isUserLoggedIn
|
|
|
|
return (
|
|
<div className={styles.wrapper} data-open={isSummaryOpen}>
|
|
<div className={styles.content}>
|
|
<div className={styles.summaryAccordion}>
|
|
<Summary
|
|
booking={booking}
|
|
rooms={rooms}
|
|
isMember={isUserLoggedIn}
|
|
totalPrice={totalPriceToShow}
|
|
vat={vat}
|
|
toggleSummaryOpen={toggleSummaryOpen}
|
|
/>
|
|
</div>
|
|
</div>
|
|
<div className={styles.bottomSheet}>
|
|
<button
|
|
data-open={isSummaryOpen}
|
|
onClick={(e) => {
|
|
e.preventDefault()
|
|
toggleSummaryOpen()
|
|
}}
|
|
className={styles.priceDetailsButton}
|
|
>
|
|
<Caption>{intl.formatMessage({ id: "Total price" })}</Caption>
|
|
<Subtitle
|
|
color={showDiscounted ? "red" : "uiTextHighContrast"}
|
|
className={styles.wrappedText}
|
|
>
|
|
{formatPrice(
|
|
intl,
|
|
totalPriceToShow.local.price,
|
|
totalPriceToShow.local.currency,
|
|
totalPriceToShow.local.additionalPrice,
|
|
totalPriceToShow.local.additionalPriceCurrency
|
|
)}
|
|
</Subtitle>
|
|
<Caption color="baseTextHighContrast" type="underline">
|
|
{intl.formatMessage({ id: "See details" })}
|
|
</Caption>
|
|
</button>
|
|
<Button
|
|
intent="primary"
|
|
theme="base"
|
|
size="large"
|
|
type="submit"
|
|
fullWidth
|
|
disabled={!isAllRoomsSelected}
|
|
>
|
|
{intl.formatMessage({ id: "Continue" })}
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|