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
This commit is contained in:
Anton Gunnarsson
2026-01-15 09:32:17 +00:00
parent c61ddaf94d
commit 16fbdb7ae0
59 changed files with 729 additions and 282 deletions

View File

@@ -26,7 +26,8 @@ export default function LargeRow({
price.local.price,
price.local.currency,
price.local.additionalPrice,
price.local.additionalPriceCurrency
price.local.additionalPriceCurrency,
price.local.pointsType
)
const regularPrice = price.local.regularPrice
? formatPrice(
@@ -34,7 +35,8 @@ export default function LargeRow({
price.local.regularPrice,
price.local.currency,
price.local.additionalPrice,
price.local.additionalPriceCurrency
price.local.additionalPriceCurrency,
price.local.pointsType
)
: null

View File

@@ -1,16 +1,15 @@
"use client"
import { useIntl } from "react-intl"
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 { useGetPointsCurrency } from "../../../../../bookingFlowConfig/bookingFlowConfigContext"
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 RedemptionPriceType {
@@ -19,11 +18,12 @@ export interface RedemptionPriceType {
currency?: CurrencyEnum
pointsPerNight: number
pointsPerStay: number
pointsType: PointType
}
}
interface RedemptionPriceProps extends SharedPriceRowProps {
currency: string
currency: CurrencyEnum
nights: number
price: RedemptionPriceType["redemption"]
}
@@ -36,7 +36,6 @@ export default function RedemptionPrice({
price,
}: RedemptionPriceProps) {
const intl = useIntl()
const pointsCurrency = useGetPointsCurrency()
if (!price) {
return null
@@ -53,10 +52,17 @@ export default function RedemptionPrice({
? Math.ceil(additionalPricePerStay / nights)
: null
const additionalCurrency = price.currency ?? currency
let averagePricePerNight = `${price.pointsPerNight} ${pointsCurrency}`
const actualCurrency = price.currency || currency
const formattedCurrency = getCurrencyText(
price.pointsPerStay,
actualCurrency,
price.pointsType,
intl
)
let averagePricePerNight = `${price.pointsPerNight} ${formattedCurrency}`
if (averageAdditionalPricePerNight) {
averagePricePerNight = `${averagePricePerNight} + ${averageAdditionalPricePerNight} ${additionalCurrency}`
averagePricePerNight = `${averagePricePerNight} + ${averageAdditionalPricePerNight} ${formattedCurrency}`
}
return (
@@ -69,9 +75,10 @@ export default function RedemptionPrice({
value={formatPrice(
intl,
price.pointsPerStay,
pointsCurrency,
currency,
additionalPricePerStay,
additionalCurrency
formattedCurrency,
price.pointsType
)}
/>
{nights > 1 ? (
@@ -82,3 +89,47 @@ export default function RedemptionPrice({
</>
)
}
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
}

View File

@@ -17,7 +17,6 @@ interface VatProps {
const noVatCurrencies = [
CurrencyEnum.CC,
CurrencyEnum.POINTS,
CurrencyEnum.EUROBONUS,
CurrencyEnum.Voucher,
CurrencyEnum.Unknown,
]

View File

@@ -119,7 +119,7 @@ export default function PriceDetailsTable({
return (
<table className={styles.priceDetailsTable}>
{rooms.map((room, idx) => {
let currency = ""
let currency: CurrencyEnum = defaultCurrency
let chequePrice: CorporateChequePriceType["corporateCheque"] | undefined
if ("corporateCheque" in room.price && room.price.corporateCheque) {
chequePrice = room.price.corporateCheque
@@ -151,10 +151,6 @@ export default function PriceDetailsTable({
voucherPrice = room.price.voucher
}
if (!currency) {
currency = defaultCurrency
}
if (!price && !voucherPrice && !chequePrice && !redemptionPrice) {
return null
}