Merged in feature/SW-3616-partner-points-my-stay (pull request #3407)

Feature/SW-3616 partner points my stay

* feat(SW-3616): display partner points in my stays

* null check roomPointType

* Lowercase POINTS in my stay

* include other than Scandic points when displaying price details modal


Approved-by: Anton Gunnarsson
This commit is contained in:
Joakim Jäderberg
2026-01-12 09:24:04 +00:00
parent d371d45fd2
commit 488a396cfa
5 changed files with 260 additions and 29 deletions

View File

@@ -6,7 +6,16 @@ import type { IntlShape } from "react-intl"
import type { Room } from "@/types/stores/my-stay"
export function calculateTotalPrice(
rooms: Room[],
rooms: Pick<
Room,
| "cheques"
| "vouchers"
| "roomPoints"
| "roomPointType"
| "totalPoints"
| "totalPrice"
| "isCancelled"
>[],
currency: CurrencyEnum,
intl: IntlShape,
allRoomsAreCancelled: boolean
@@ -20,55 +29,77 @@ export function calculateTotalPrice(
if (room.cheques) {
total.cheques = total.cheques + room.cheques
}
if (room.vouchers) {
total.vouchers = total.vouchers + room.vouchers
}
if (room.totalPoints) {
total.points = total.points + room.totalPoints
if (
room.roomPoints &&
room.roomPointType &&
room.roomPointType !== "Scandic"
) {
total.partnerPoints = total.partnerPoints + room.roomPoints
total.partnerPointsCurrency = room.roomPointType ?? null
}
if (room.totalPoints) {
total.scandicFriendsPoints =
total.scandicFriendsPoints + room.totalPoints
}
// room.totalPrice is a negative value when
// its a vouchers booking (╯°□°)╯︵ ┻━┻
if (room.totalPrice > 0) {
total.cash = total.cash + room.totalPrice
}
return total
},
{
cash: 0,
cheques: 0,
points: 0,
scandicFriendsPoints: 0,
partnerPoints: 0,
partnerPointsCurrency: null as Room["roomPointType"],
vouchers: 0,
}
)
let totalPrice = ""
const priceParts: string[] = []
if (totals.vouchers) {
const appendTotalPrice = totalPrice ? `${totalPrice} + ` : ""
totalPrice = `${appendTotalPrice}${totals.vouchers} ${intl.formatMessage(
{
id: "price.numberOfVouchers",
defaultMessage:
"{numberOfVouchers, plural, one {Voucher} other {Vouchers}}",
},
{
numberOfVouchers: totals.vouchers,
}
)}`
}
if (totals.cheques) {
totalPrice = `${totals.cheques} ${CurrencyEnum.CC}`
}
if (totals.points) {
const appendTotalPrice = totalPrice ? `${totalPrice} + ` : ""
totalPrice = `${appendTotalPrice}${totals.points} ${CurrencyEnum.POINTS}`
}
if (totals.cash) {
const appendTotalPrice = totalPrice ? `${totalPrice} + ` : ""
const cashPrice = formatPrice(intl, totals.cash, currency)
totalPrice = `${appendTotalPrice}${cashPrice}`
priceParts.push(
`${totals.vouchers} ${intl.formatMessage(
{
id: "price.numberOfVouchers",
defaultMessage:
"{numberOfVouchers, plural, one {Voucher} other {Vouchers}}",
},
{
numberOfVouchers: totals.vouchers,
}
)}`
)
}
return totalPrice
if (totals.cheques) {
priceParts.push(`${totals.cheques} ${CurrencyEnum.CC}`)
}
if (totals.scandicFriendsPoints) {
priceParts.push(`${totals.scandicFriendsPoints} ${CurrencyEnum.POINTS}`)
}
if (totals.partnerPoints) {
priceParts.push(`${totals.partnerPoints} ${totals.partnerPointsCurrency}`)
}
if (totals.cash) {
const cashPrice = formatPrice(intl, totals.cash, currency)
priceParts.push(cashPrice)
}
return priceParts.join(" + ")
}
export function calculateTotalPoints(