feat(BOOK-747): show extra cost alert if reward night or voucher * feat(BOOK-747): show extra cost alert if reward night or voucher * feat(BOOK-747): use enum * feat(BOOK-747): refactor * feat(BOOK-747): add underline to trigger text Approved-by: Anton Gunnarsson
130 lines
4.5 KiB
TypeScript
130 lines
4.5 KiB
TypeScript
import { Typography } from "../../Typography"
|
|
import { RatePointsOption, RateTermDetails } from "../types"
|
|
|
|
import { RadioGroup } from "react-aria-components"
|
|
|
|
import { Radio } from "../../Radio"
|
|
import styles from "../rate-card.module.css"
|
|
import { variants } from "../variants"
|
|
import { MaterialIcon } from "../../Icons/MaterialIcon"
|
|
import { getCurrencyText } from "../../currency-utils"
|
|
import TermModal from "../TermModal"
|
|
import { useIntl } from "react-intl"
|
|
|
|
interface PointsRateCardProps {
|
|
rateTitle: string
|
|
paymentTerm: string
|
|
bannerText: string
|
|
rates: RatePointsOption[]
|
|
selectedRate: string | undefined
|
|
onRateSelect: (value: string) => void
|
|
isNotEnoughPoints?: boolean
|
|
notEnoughPointsText?: string
|
|
rateTermDetails: RateTermDetails[]
|
|
id: string
|
|
roomTypeCode: string
|
|
}
|
|
|
|
export default function PointsRateCard({
|
|
rateTitle,
|
|
paymentTerm,
|
|
bannerText,
|
|
id,
|
|
rates,
|
|
selectedRate,
|
|
isNotEnoughPoints,
|
|
notEnoughPointsText,
|
|
onRateSelect,
|
|
roomTypeCode,
|
|
rateTermDetails,
|
|
}: PointsRateCardProps) {
|
|
const classNames = variants({
|
|
variant: "Points",
|
|
})
|
|
|
|
const intl = useIntl()
|
|
|
|
return (
|
|
<div className={classNames}>
|
|
<Typography variant="Label/xsBold">
|
|
<p className={styles.banner}>{bannerText}</p>
|
|
</Typography>
|
|
<div className={styles.container}>
|
|
<header>
|
|
<Typography variant="Tag/sm">
|
|
<h3 className={styles.title}>
|
|
<TermModal
|
|
rateTitle={rateTitle}
|
|
paymentTerm={paymentTerm}
|
|
rateTermDetails={rateTermDetails}
|
|
/>
|
|
{rateTitle}
|
|
<span className={styles.textSecondary}>
|
|
{/* eslint-disable-next-line formatjs/no-literal-string-in-jsx */}
|
|
{` / ${paymentTerm}`}
|
|
</span>
|
|
</h3>
|
|
</Typography>
|
|
</header>
|
|
<div className={styles.content}>
|
|
<RadioGroup
|
|
/* eslint-disable-next-line formatjs/no-literal-string-in-jsx */
|
|
aria-label={`${rateTitle} / ${paymentTerm}`}
|
|
aria-describedby={roomTypeCode}
|
|
value={selectedRate ? selectedRate : null} // default to null for focus to land on the first radio on tab, undefined set tabIndex to -1
|
|
onChange={onRateSelect}
|
|
>
|
|
{rates.map((rate, index) => (
|
|
<div key={index} className={styles.rateRow}>
|
|
<Radio
|
|
value={rate.rateCode}
|
|
isDisabled={rate.isDisabled || isNotEnoughPoints}
|
|
id={`${id}-${rate.rateCode}`}
|
|
>
|
|
<div className={styles.pointsRow}>
|
|
<Typography variant="Title/Subtitle/md">
|
|
<p>
|
|
{/* eslint-disable-next-line formatjs/no-literal-string-in-jsx */}
|
|
{`${rate.points} `}
|
|
<Typography variant="Body/Supporting text (caption)/smBold">
|
|
<span>
|
|
{/* eslint-disable-next-line formatjs/no-literal-string-in-jsx */}
|
|
{`${getCurrencyText(intl, rate.currency, rate.points, rate.pointsType)} ${rate.additionalPrice ? " + " : ""}`}
|
|
</span>
|
|
</Typography>
|
|
</p>
|
|
</Typography>
|
|
{rate.additionalPrice && (
|
|
<Typography variant="Title/Subtitle/md">
|
|
<p>
|
|
{/* eslint-disable-next-line formatjs/no-literal-string-in-jsx */}
|
|
{`${rate.additionalPrice.price} `}
|
|
<Typography variant="Body/Supporting text (caption)/smBold">
|
|
<span>{rate.additionalPrice.currency}</span>
|
|
</Typography>
|
|
</p>
|
|
</Typography>
|
|
)}
|
|
</div>
|
|
</Radio>
|
|
</div>
|
|
))}
|
|
</RadioGroup>
|
|
</div>
|
|
{isNotEnoughPoints ? (
|
|
<footer className={styles.footer}>
|
|
<Typography variant="Body/Supporting text (caption)/smBold">
|
|
<p className={styles.notEnoughPoints}>
|
|
<span className={styles.filledIcon}>
|
|
<MaterialIcon icon="info" isFilled size={20} />
|
|
</span>
|
|
{notEnoughPointsText}
|
|
</p>
|
|
</Typography>
|
|
</footer>
|
|
) : null}
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|