Files
web/packages/booking-flow/lib/components/PriceDetailsModal/PriceDetailsTable/Row/Price/Redemption.tsx
Anton Gunnarsson 16fbdb7ae0 Merged in fix/refactor-currency-display (pull request #3434)
fix(SW-3616): Handle EuroBonus point type everywhere

* Add tests to formatPrice

* formatPrice

* More work replacing config with api points type

* More work replacing config with api points type

* More fixing with currency

* maybe actually fixed it

* Fix MyStay

* Clean up

* Fix comments

* Merge branch 'master' into fix/refactor-currency-display

* Fix calculateTotalPrice for EB points + SF points + cash


Approved-by: Joakim Jäderberg
2026-01-15 09:32:17 +00:00

136 lines
3.3 KiB
TypeScript

"use client"
import { type IntlShape, useIntl } from "react-intl"
import { CurrencyEnum } from "@scandic-hotels/common/constants/currency"
import { PointType } from "@scandic-hotels/common/constants/pointType"
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 { SharedPriceRowProps } from "./price"
export interface RedemptionPriceType {
redemption?: {
additionalPricePerStay?: number
currency?: CurrencyEnum
pointsPerNight: number
pointsPerStay: number
pointsType: PointType
}
}
interface RedemptionPriceProps extends SharedPriceRowProps {
currency: CurrencyEnum
nights: number
price: RedemptionPriceType["redemption"]
}
export default function RedemptionPrice({
bedType,
currency,
nights,
packages,
price,
}: RedemptionPriceProps) {
const intl = useIntl()
if (!price) {
return null
}
const averagePriceTitle = intl.formatMessage({
id: "priceDetails.averagePricePerNight",
defaultMessage: "Average price per night",
})
const additionalPricePerStay = price.additionalPricePerStay
const averageAdditionalPricePerNight = additionalPricePerStay
? Math.ceil(additionalPricePerStay / nights)
: null
const actualCurrency = price.currency || currency
const formattedCurrency = getCurrencyText(
price.pointsPerStay,
actualCurrency,
price.pointsType,
intl
)
let averagePricePerNight = `${price.pointsPerNight} ${formattedCurrency}`
if (averageAdditionalPricePerNight) {
averagePricePerNight = `${averagePricePerNight} + ${averageAdditionalPricePerNight} ${formattedCurrency}`
}
return (
<>
<BoldRow
label={intl.formatMessage({
id: "priceDetails.roomCharge",
defaultMessage: "Room charge",
})}
value={formatPrice(
intl,
price.pointsPerStay,
currency,
additionalPricePerStay,
formattedCurrency,
price.pointsType
)}
/>
{nights > 1 ? (
<RegularRow label={averagePriceTitle} value={averagePricePerNight} />
) : null}
<BedTypeRow bedType={bedType} currency={currency} />
<PackagesRow packages={packages} />
</>
)
}
function getCurrencyText(
points: number,
currency: CurrencyEnum | undefined,
pointsType: PointType,
intl: IntlShape
) {
if (!currency) return currency
if (currency === CurrencyEnum.POINTS) {
switch (pointsType) {
case PointType.SCANDIC: {
return intl.formatMessage(
{
id: "price.numberOfScandicPoints",
defaultMessage:
"{numberOfScandicPoints, plural, one {Point} other {Points}}",
},
{
numberOfScandicPoints: points,
}
)
}
case PointType.EUROBONUS: {
return intl.formatMessage(
{
id: "price.numberOfEuroBonusPoints",
defaultMessage:
"{numberOfEuroBonusPoints, plural, one {EB Point} other {EB Points}}",
},
{
numberOfEuroBonusPoints: points,
}
)
}
default: {
const _exhaustiveCheck: never = pointsType
return currency
}
}
}
return currency
}