chore: Update to ESLint 9 * wip: apply codemod and upgrade swc plugin * Update eslint to 9 in scandic-web apply code mod to config fix existing lint issues * Remove uneccessary fixupConfigRules * Update eslint to 9 in design-system * Add lint turbo dependency * Move redis-api to eslint and prettier instead of biome * Simplify eslint configs * Clean up * Apply linting Approved-by: Linus Flood
97 lines
2.7 KiB
TypeScript
97 lines
2.7 KiB
TypeScript
import {
|
|
MaterialIcon,
|
|
type MaterialIconSetIconProps,
|
|
} from "@scandic-hotels/design-system/Icons/MaterialIcon"
|
|
|
|
import { ChildBedTypeEnum } from "@/constants/booking"
|
|
|
|
import type { JSX } from "react"
|
|
|
|
import { ChildBedMapEnum } from "@/types/components/bookingWidget/enums"
|
|
import {
|
|
RoomPackageCodeEnum,
|
|
type RoomPackageCodes,
|
|
} from "@/types/components/hotelReservation/selectRate/roomFilter"
|
|
import type { Child } from "@/types/components/hotelReservation/selectRate/selectRate"
|
|
import type { Packages } from "@/types/requests/packages"
|
|
|
|
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 bedTypeMap: Record<number, ChildBedTypeEnum> = {
|
|
[ChildBedMapEnum.IN_ADULTS_BED]: ChildBedTypeEnum.ParentsBed,
|
|
[ChildBedMapEnum.IN_CRIB]: ChildBedTypeEnum.Crib,
|
|
[ChildBedMapEnum.IN_EXTRA_BED]: ChildBedTypeEnum.ExtraBed,
|
|
[ChildBedMapEnum.UNKNOWN]: ChildBedTypeEnum.Unknown,
|
|
}
|
|
|
|
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 generateChildrenString(children: Child[]): string {
|
|
return `[${children
|
|
.map((child) => {
|
|
const age = child.age
|
|
const bedType = bedTypeMap[parseInt(child.bed.toString())]
|
|
return `${age}:${bedType}`
|
|
})
|
|
.join(",")}]`
|
|
}
|
|
|
|
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,
|
|
}
|
|
)
|
|
}
|