Fix/linting * fix import issues and add lint check no-extraneous-dependencies * fix use type HotelType instead of string Approved-by: Anton Gunnarsson
142 lines
4.2 KiB
TypeScript
142 lines
4.2 KiB
TypeScript
import { cx } from 'class-variance-authority'
|
|
import { useIntl } from 'react-intl'
|
|
|
|
import Body from '../../Body'
|
|
import Caption from '../../Caption'
|
|
import { Divider } from '../../Divider'
|
|
import Subtitle from '../../Subtitle'
|
|
import { RateTypeEnum } from '@scandic-hotels/common/constants/rateType'
|
|
|
|
import styles from './hotelPriceCard.module.css'
|
|
|
|
type Price = {
|
|
pricePerStay: number
|
|
pricePerNight: number
|
|
currency: string
|
|
}
|
|
|
|
export type PriceCardProps = {
|
|
productTypePrices: {
|
|
rateType: RateTypeEnum
|
|
localPrice: Price
|
|
requestedPrice?: Price
|
|
}
|
|
isMemberPrice?: boolean
|
|
className?: string
|
|
}
|
|
|
|
export function HotelPriceCard({
|
|
productTypePrices,
|
|
isMemberPrice = false,
|
|
className,
|
|
}: PriceCardProps) {
|
|
const intl = useIntl()
|
|
const isRegularOrPublicPromotionRate =
|
|
productTypePrices.rateType === RateTypeEnum.Regular ||
|
|
productTypePrices.rateType === RateTypeEnum.PublicPromotion
|
|
|
|
return (
|
|
<dl className={cx(styles.priceCard, className)}>
|
|
{isRegularOrPublicPromotionRate &&
|
|
(isMemberPrice ? (
|
|
<div className={styles.priceRow}>
|
|
<dt>
|
|
<Caption color="red">
|
|
{intl.formatMessage({
|
|
defaultMessage: 'Member price',
|
|
})}
|
|
</Caption>
|
|
</dt>
|
|
</div>
|
|
) : (
|
|
<div className={styles.priceRow}>
|
|
<dt>
|
|
<Caption color="uiTextHighContrast">
|
|
{intl.formatMessage({
|
|
defaultMessage: 'Standard price',
|
|
})}
|
|
</Caption>
|
|
</dt>
|
|
</div>
|
|
))}
|
|
<div className={styles.priceRow}>
|
|
<dt>
|
|
<Caption
|
|
type="bold"
|
|
color={isMemberPrice ? 'red' : 'uiTextHighContrast'}
|
|
>
|
|
{intl.formatMessage({
|
|
defaultMessage: 'From',
|
|
})}
|
|
</Caption>
|
|
</dt>
|
|
<dd>
|
|
<div className={styles.price}>
|
|
<Subtitle
|
|
type="two"
|
|
color={isMemberPrice ? 'red' : 'uiTextHighContrast'}
|
|
>
|
|
{productTypePrices.localPrice.pricePerNight}
|
|
</Subtitle>
|
|
<Body
|
|
color={isMemberPrice ? 'red' : 'uiTextHighContrast'}
|
|
textTransform="bold"
|
|
>
|
|
{productTypePrices.localPrice.currency}
|
|
{/* eslint-disable-next-line formatjs/no-literal-string-in-jsx */}
|
|
<span className={styles.perNight}>
|
|
/
|
|
{intl.formatMessage({
|
|
defaultMessage: 'night',
|
|
})}
|
|
</span>
|
|
</Body>
|
|
</div>
|
|
</dd>
|
|
</div>
|
|
{productTypePrices?.requestedPrice && (
|
|
<div className={styles.priceRow}>
|
|
<dt>
|
|
<Caption color="uiTextMediumContrast">
|
|
{intl.formatMessage({
|
|
defaultMessage: 'Approx.',
|
|
})}
|
|
</Caption>
|
|
</dt>
|
|
<dd>
|
|
<Caption color={'uiTextMediumContrast'}>
|
|
{/* eslint-disable-next-line formatjs/no-literal-string-in-jsx */}
|
|
{`${productTypePrices.requestedPrice.pricePerNight} `}
|
|
{productTypePrices.requestedPrice.currency}
|
|
</Caption>
|
|
</dd>
|
|
</div>
|
|
)}
|
|
{productTypePrices.localPrice.pricePerStay !==
|
|
productTypePrices.localPrice.pricePerNight &&
|
|
// Handle undefined scenarios
|
|
productTypePrices.localPrice.pricePerNight && (
|
|
<>
|
|
<Divider className={styles.divider} />
|
|
<div className={styles.priceRow}>
|
|
<dt>
|
|
<Caption color="uiTextMediumContrast">
|
|
{intl.formatMessage({
|
|
defaultMessage: 'Total',
|
|
})}
|
|
</Caption>
|
|
</dt>
|
|
<dd>
|
|
<Caption color={'uiTextMediumContrast'}>
|
|
{/* eslint-disable-next-line formatjs/no-literal-string-in-jsx */}
|
|
{`${productTypePrices.localPrice.pricePerStay} `}
|
|
{productTypePrices.localPrice.currency}
|
|
</Caption>
|
|
</dd>
|
|
</div>
|
|
</>
|
|
)}
|
|
</dl>
|
|
)
|
|
}
|