Files
web/apps/scandic-web/components/HotelReservation/MyStay/Rooms/TotalPrice/index.tsx
Pontus Dreij b48053b8b4 Merged in feat(SW-2083)-missing-booking-codes-scenarios-my-stay (pull request #1680)
Feat(SW-2083) missing booking codes scenarios my stay

* feat(SW-2083) Show points instead of reward nights

* feat(SW-2083) added support for cheque and voucher for totalPrice


Approved-by: Niclas Edenvin
2025-03-31 11:42:47 +00:00

74 lines
1.9 KiB
TypeScript

"use client"
import { useIntl } from "react-intl"
import { Typography } from "@scandic-hotels/design-system/Typography"
import { useMyStayRoomDetailsStore } from "@/stores/my-stay/myStayRoomDetailsStore"
import { useMyStayTotalPriceStore } from "@/stores/my-stay/myStayTotalPrice"
import Points from "../../Points"
import Price from "../../Price"
import styles from "./totalPrice.module.css"
import type { PriceType } from "@/types/components/hotelReservation/myStay/myStay"
export type Variant =
| "Title/Subtitle/lg"
| "Title/Subtitle/md"
| "Body/Paragraph/mdBold"
interface TotalPriceProps {
variant: Variant
type?: PriceType
}
export default function TotalPrice({
variant,
type = "money",
}: TotalPriceProps) {
const totalPrice = useMyStayTotalPriceStore((state) => state.totalPrice)
const totalPoints = useMyStayTotalPriceStore((state) => state.totalPoints)
const bookedRoom = useMyStayRoomDetailsStore((state) => state.bookedRoom)
const { vouchers, cheques } = bookedRoom
const intl = useIntl()
if (type === "money") {
return <Price price={totalPrice} variant={variant} />
}
if (type === "voucher") {
return (
<Typography variant={variant}>
<p>
{intl.formatMessage({ id: "{count} voucher" }, { count: vouchers })}
</p>
</Typography>
)
}
if (type === "cheque") {
return (
<div className={styles.totalPrice}>
<Typography variant={variant}>
<p>{cheques} CC + </p>
</Typography>
<Price price={totalPrice} variant={variant} />
</div>
)
}
if (totalPrice && totalPrice > 0 && type === "points") {
return (
<div className={styles.totalPrice}>
<Points points={totalPoints} variant={variant} /> +{" "}
<Price price={totalPrice} variant={variant} />
</div>
)
}
return <Points points={totalPoints} variant={variant} />
}