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
+65 -14
View File
@@ -1,4 +1,6 @@
import { CurrencyEnum } from "../constants/currency"
import { PointType } from "../constants/pointType"
import { logger } from "../logger"
import type { IntlShape } from "react-intl"
@@ -18,6 +20,7 @@ export function getSingleDecimal(n: Number | string) {
* @param currency - currency code
* @param additionalPrice - number (obtained in reward nights and Corporate cheque scenarios)
* @param additionalPriceCurrency - currency code (obtained in reward nights and Corporate cheque scenarios)
* @param pointsType - type of points when currency is points
* @returns localized and formatted number in string type with currency
*/
export function formatPrice(
@@ -25,7 +28,8 @@ export function formatPrice(
price: number,
currency: string | CurrencyEnum,
additionalPrice?: number,
additionalPriceCurrency?: string
additionalPriceCurrency?: string,
pointsType?: PointType | null
) {
const localizedPrice = intl.formatNumber(price, {
minimumFractionDigits: 0,
@@ -41,19 +45,66 @@ export function formatPrice(
formattedAdditionalPrice = ` + ${localizedAdditionalPrice} ${additionalPriceCurrency}`
}
const currencyText =
currency === CurrencyEnum.Voucher
? intl.formatMessage(
{
id: "price.numberOfVouchers",
defaultMessage:
"{numberOfVouchers, plural, one {Voucher} other {Vouchers}}",
},
{
numberOfVouchers: price,
}
)
: currency
const currencyText = getCurrencyText(intl, price, currency, pointsType)
return `${localizedPrice} ${currencyText}${formattedAdditionalPrice}`
}
function getCurrencyText(
intl: IntlShape,
price: number,
currency: string | CurrencyEnum,
pointsType?: PointType | null
) {
if (currency === CurrencyEnum.Voucher) {
return intl.formatMessage(
{
id: "price.numberOfVouchers",
defaultMessage:
"{numberOfVouchers, plural, one {Voucher} other {Vouchers}}",
},
{
numberOfVouchers: price,
}
)
}
if (currency === CurrencyEnum.POINTS) {
if (!pointsType) return currency
switch (pointsType) {
case PointType.SCANDIC: {
return intl.formatMessage(
{
id: "price.numberOfScandicPoints",
defaultMessage:
"{numberOfScandicPoints, plural, one {Point} other {Points}}",
},
{
numberOfScandicPoints: price,
}
)
}
case PointType.EUROBONUS: {
return intl.formatMessage(
{
id: "price.numberOfEuroBonusPoints",
defaultMessage:
"{numberOfEuroBonusPoints, plural, one {EB Point} other {EB Points}}",
},
{
numberOfEuroBonusPoints: price,
}
)
}
default: {
const _exhaustiveCheck: never = pointsType
void _exhaustiveCheck
logger.warn(`Unknown point type provided: ${pointsType}`)
return currency
}
}
}
return currency
}