feat (SW-2864): Move booking router to trpc package * Add env to trpc package * Add eslint to trpc package * Apply lint rules * Use direct imports from trpc package * Add lint-staged config to trpc * Move lang enum to common * Restructure trpc package folder structure * WIP first step * update internal imports in trpc * Fix most errors in scandic-web Just 100 left... * Move Props type out of trpc * Fix CategorizedFilters types * Move more schemas in hotel router * Fix deps * fix getNonContentstackUrls * Fix import error * Fix entry error handling * Fix generateMetadata metrics * Fix alertType enum * Fix duplicated types * lint:fix * Merge branch 'master' into feat/sw-2863-move-contentstack-router-to-trpc-package * Fix broken imports * Move booking router to trpc package * Merge branch 'master' into feat/sw-2864-move-hotels-router-to-trpc-package Approved-by: Linus Flood
86 lines
2.5 KiB
TypeScript
86 lines
2.5 KiB
TypeScript
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 { 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: Packages | 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,
|
|
}
|
|
}
|