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:
47
packages/design-system/lib/components/currency-utils.ts
Normal file
47
packages/design-system/lib/components/currency-utils.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user