Feature/select rate vertical data flow * add fix from SW-2666 * use translations for room packages * move types to it's own file * Merge branch 'master' of bitbucket.org:scandic-swap/web into feature/select-rate-vertical-data-flow * merge * feature/select-rate: double rate for campaing rates * revert NODE_ENV check in Cookiebot script * revert testing values * fix(SW-3171): fix all filter selected in price details * fix(SW-3166): multiroom anchoring when changing filter * fix(SW-3172): check hotelType, show correct breakfast message * Merge branch 'feature/select-rate-vertical-data-flow' of bitbucket.org:scandic-swap/web into feature/select-rate-vertical-data-flow * fix: show special needs icons for subsequent roomTypes SW-3167 * fix: Display strike through text when logged in SW-3168 * fix: Reinstate the scrollToView behaviour when selecting a rate SW-3169 * merge * . * PR fixes * fix: don't return notFound() * . * always include defaults for room packages * merge * merge * merge * Remove floating h1 for new select-rate Approved-by: Anton Gunnarsson
120 lines
3.5 KiB
TypeScript
120 lines
3.5 KiB
TypeScript
import { type Dayjs, dt } from "@scandic-hotels/common/dt"
|
|
import {
|
|
MaterialIcon,
|
|
type MaterialIconSetIconProps,
|
|
} from "@scandic-hotels/design-system/Icons/MaterialIcon"
|
|
import { ChildBedMapEnum } from "@scandic-hotels/trpc/enums/childBedMapEnum"
|
|
import { ChildBedTypeEnum } from "@scandic-hotels/trpc/enums/childBedTypeEnum"
|
|
import { RoomPackageCodeEnum } from "@scandic-hotels/trpc/enums/roomFilter"
|
|
|
|
import type { specialAlertsSchema } from "@scandic-hotels/trpc/routers/hotels/schemas/hotel/specialAlerts"
|
|
import type { Package, Packages } from "@scandic-hotels/trpc/types/packages"
|
|
import type { JSX } from "react"
|
|
|
|
import { type RoomPackageCodes } from "@/types/components/hotelReservation/selectRate/roomFilter"
|
|
|
|
interface IconForFeatureCodeProps {
|
|
featureCode: RoomPackageCodes
|
|
}
|
|
export function IconForFeatureCode({
|
|
featureCode,
|
|
...props
|
|
}: IconForFeatureCodeProps & MaterialIconSetIconProps): JSX.Element {
|
|
switch (featureCode) {
|
|
case RoomPackageCodeEnum.ACCESSIBILITY_ROOM:
|
|
return <MaterialIcon icon="accessible" {...props} />
|
|
case RoomPackageCodeEnum.ALLERGY_ROOM:
|
|
return <MaterialIcon icon="mode_fan" {...props} />
|
|
case RoomPackageCodeEnum.PET_ROOM:
|
|
default:
|
|
return <MaterialIcon icon="pets" {...props} />
|
|
}
|
|
}
|
|
|
|
export const invertedBedTypeMap: Record<ChildBedTypeEnum, string> = {
|
|
[ChildBedTypeEnum.ParentsBed]: ChildBedMapEnum[ChildBedMapEnum.IN_ADULTS_BED],
|
|
[ChildBedTypeEnum.Crib]: ChildBedMapEnum[ChildBedMapEnum.IN_CRIB],
|
|
[ChildBedTypeEnum.ExtraBed]: ChildBedMapEnum[ChildBedMapEnum.IN_EXTRA_BED],
|
|
[ChildBedTypeEnum.Unknown]: ChildBedMapEnum[ChildBedMapEnum.UNKNOWN],
|
|
}
|
|
|
|
export function sumPackages(
|
|
packages: Pick<Package, "localPrice">[] | undefined | null
|
|
) {
|
|
if (!packages || !packages.length) {
|
|
return {
|
|
currency: undefined,
|
|
price: 0,
|
|
}
|
|
}
|
|
return packages.reduce(
|
|
(total, pkg) => {
|
|
total.price = total.price + pkg.localPrice.totalPrice
|
|
return total
|
|
},
|
|
{
|
|
currency: packages[0].localPrice.currency,
|
|
price: 0,
|
|
}
|
|
)
|
|
}
|
|
|
|
export function sumPackagesRequestedPrice(packages: Packages | null) {
|
|
if (!packages || !packages.length) {
|
|
return {
|
|
currency: undefined,
|
|
price: 0,
|
|
}
|
|
}
|
|
return packages.reduce(
|
|
(total, pkg) => {
|
|
total.price = total.price + pkg.requestedPrice.totalPrice
|
|
return total
|
|
},
|
|
{
|
|
currency: packages[0].requestedPrice.currency,
|
|
price: 0,
|
|
}
|
|
)
|
|
}
|
|
|
|
export function calculateVat(priceInclVat: number, vat: number) {
|
|
const vatPercentage = vat / 100
|
|
const priceExclVat = priceInclVat / (1 + vatPercentage)
|
|
const vatAmount = priceInclVat - priceExclVat
|
|
return {
|
|
priceExclVat,
|
|
vatAmount,
|
|
}
|
|
}
|
|
|
|
export function getHotelAlertsForBookingDates(
|
|
specialAlerts: Zod.infer<typeof specialAlertsSchema>,
|
|
fromDate: Date | Dayjs,
|
|
toDate: Date | Dayjs
|
|
) {
|
|
return specialAlerts.filter((alert) => {
|
|
if (alert.endDate && alert.startDate) {
|
|
const alertEndDate = dt(alert.endDate)
|
|
const alertStartDate = dt(alert.startDate)
|
|
|
|
const fromDateIsBetweenAlertDates = dt(fromDate).isBetween(
|
|
alertStartDate,
|
|
alertEndDate,
|
|
"date",
|
|
"[]"
|
|
)
|
|
const toDateIsBetweenAlertDates = dt(toDate).isBetween(
|
|
alertStartDate,
|
|
alertEndDate,
|
|
"date",
|
|
"[]"
|
|
)
|
|
const bookingSpanIsBetweenAlertDates =
|
|
fromDateIsBetweenAlertDates || toDateIsBetweenAlertDates
|
|
return bookingSpanIsBetweenAlertDates
|
|
}
|
|
return true
|
|
})
|
|
}
|