Files
web/packages/design-system/lib/components/currency-utils.ts
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

48 lines
1.3 KiB
TypeScript

import { CurrencyEnum } from "@scandic-hotels/common/constants/currency"
import { PointType } from "@scandic-hotels/common/constants/pointType"
import { logger } from "@scandic-hotels/common/logger"
import { IntlShape } from "react-intl"
export function getCurrencyText(
intl: IntlShape,
currency: string,
price: number,
pointsType?: PointType | null
) {
if (currency !== CurrencyEnum.POINTS) return currency
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
}
}
}