feat(SW-3225): Move ParkingInformation to design-system * Inline ParkingInformation types to remove trpc dependency * Move ParkingInformation to design-system * Move numberFormatting to common package * Add deps to external * Fix imports and i18n script * Add common as dependency * Merge branch 'master' into feat/sw-3225-move-parking-information-to-booking-flow Approved-by: Linus Flood
78 lines
1.9 KiB
TypeScript
78 lines
1.9 KiB
TypeScript
"use client"
|
|
import { useIntl } from "react-intl"
|
|
|
|
import { formatPrice } from "@scandic-hotels/common/utils/numberFormatting"
|
|
|
|
import BoldRow from "../Bold"
|
|
import RegularRow from "../Regular"
|
|
import BedTypeRow from "./BedType"
|
|
import PackagesRow from "./Packages"
|
|
|
|
import type { CurrencyEnum } from "@scandic-hotels/common/constants/currency"
|
|
|
|
import type { SharedPriceRowProps } from "./price"
|
|
|
|
export interface RegularPriceType {
|
|
regular?: {
|
|
currency: CurrencyEnum
|
|
pricePerNight: number
|
|
pricePerStay: number
|
|
regularPricePerStay: number
|
|
}
|
|
}
|
|
|
|
interface RegularPriceProps extends SharedPriceRowProps {
|
|
isMemberRate: boolean
|
|
price: RegularPriceType["regular"]
|
|
}
|
|
|
|
export default function RegularPrice({
|
|
bedType,
|
|
isMemberRate,
|
|
nights,
|
|
packages,
|
|
price,
|
|
}: RegularPriceProps) {
|
|
const intl = useIntl()
|
|
|
|
if (!price) {
|
|
return null
|
|
}
|
|
|
|
const averagePriceTitle = intl.formatMessage({
|
|
defaultMessage: "Average price per night",
|
|
})
|
|
|
|
const avgeragePricePerNight = formatPrice(
|
|
intl,
|
|
price.pricePerNight,
|
|
price.currency
|
|
)
|
|
|
|
const roomCharge = formatPrice(intl, price.pricePerStay, price.currency)
|
|
|
|
const regularPriceIsHigherThanPrice =
|
|
price.regularPricePerStay > price.pricePerStay
|
|
let regularCharge = undefined
|
|
if (regularPriceIsHigherThanPrice) {
|
|
regularCharge = formatPrice(intl, price.regularPricePerStay, price.currency)
|
|
}
|
|
const isDiscounted = isMemberRate || regularPriceIsHigherThanPrice
|
|
|
|
return (
|
|
<>
|
|
<BoldRow
|
|
label={intl.formatMessage({ defaultMessage: "Room charge" })}
|
|
value={roomCharge}
|
|
regularValue={regularCharge}
|
|
isDiscounted={isDiscounted}
|
|
/>
|
|
{nights > 1 ? (
|
|
<RegularRow label={averagePriceTitle} value={avgeragePricePerNight} />
|
|
) : null}
|
|
<BedTypeRow bedType={bedType} currency={price.currency} />
|
|
<PackagesRow packages={packages} />
|
|
</>
|
|
)
|
|
}
|