Files
Niclas Edenvin 3a958c4dd1 Merged in fix/sw-1897-member-price-modal (pull request #1856)
fix(sw-1897): show member price modal immediately

* fix(sw-1897): show member price modal immediately

* Make checkbox fully controlled

* Remove action in the store that wasn't used


Approved-by: Hrishikesh Vaipurkar
2025-04-25 09:55:24 +00:00

117 lines
3.0 KiB
TypeScript

"use client"
import { useState } from "react"
import { useIntl } from "react-intl"
import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon"
import Checkbox from "@/components/TempDesignSystem/Form/Checkbox"
import Caption from "@/components/TempDesignSystem/Text/Caption"
import { useRoomContext } from "@/contexts/Details/Room"
import { formatPrice } from "@/utils/numberFormatting"
import MemberPriceModal from "../../MemberPriceModal"
import styles from "./joinScandicFriendsCard.module.css"
import type { JoinScandicFriendsCardProps } from "@/types/components/hotelReservation/enterDetails/details"
import { CurrencyEnum } from "@/types/enums/currency"
export default function JoinScandicFriendsCard({
name = "join",
}: JoinScandicFriendsCardProps) {
const intl = useIntl()
const {
room,
roomNr,
actions: { updateJoin },
} = useRoomContext()
const [isMemberPriceModalOpen, setIsMemberPriceModalOpen] = useState(false)
function onChange(event: { target: { value: boolean } }) {
updateJoin(event.target.value)
if (event.target.value) {
setIsMemberPriceModalOpen(true)
}
}
if (!("member" in room.roomRate) || !room.roomRate.member) {
return null
}
const list = [
{
title: intl.formatMessage({
defaultMessage: "Earn bonus nights & points",
}),
},
{
title: intl.formatMessage({
defaultMessage: "Get member benefits & offers",
}),
},
{
title: intl.formatMessage({
defaultMessage: "Join at no cost",
}),
},
]
const saveOnJoiningLabel = intl.formatMessage(
{
defaultMessage: "Pay the member price of {amount} for Room {roomNr}",
},
{
amount: formatPrice(
intl,
room.roomRate.member.localPrice.pricePerStay ?? 0,
room.roomRate.member.localPrice.currency ?? CurrencyEnum.Unknown
),
roomNr,
}
)
return (
<div className={styles.cardContainer}>
<Checkbox
name={name}
className={styles.checkBox}
registerOptions={{ onChange, value: room.guest.join }}
>
<div>
<Caption type="label" textTransform="uppercase" color="red">
{saveOnJoiningLabel}
</Caption>
<Caption color="uiTextHighContrast">
{intl.formatMessage({
defaultMessage:
"I promise to join Scandic Friends before checking in",
})}
</Caption>
</div>
</Checkbox>
<div className={styles.list}>
{list.map((item) => (
<Caption
key={item.title}
className={styles.listItem}
color="uiTextPlaceholder"
>
<MaterialIcon
icon="check"
size={20}
color="Icon/Interactive/Placeholder"
/>
{item.title}
</Caption>
))}
</div>
<MemberPriceModal
isOpen={isMemberPriceModalOpen}
setIsOpen={setIsMemberPriceModalOpen}
/>
</div>
)
}