feat: SW-2028 Points validation redemption city search
This commit is contained in:
@@ -18,6 +18,7 @@ import Link from "@/components/TempDesignSystem/Link"
|
||||
import Body from "@/components/TempDesignSystem/Text/Body"
|
||||
import Caption from "@/components/TempDesignSystem/Text/Caption"
|
||||
import Subtitle from "@/components/TempDesignSystem/Text/Subtitle"
|
||||
import { Tooltip } from "@/components/TempDesignSystem/Tooltip"
|
||||
import { mapApiImagesToGalleryImages } from "@/utils/imageGallery"
|
||||
import { getSingleDecimal } from "@/utils/numberFormatting"
|
||||
|
||||
@@ -43,6 +44,7 @@ function HotelCard({
|
||||
state = "default",
|
||||
type = HotelCardListingTypeEnum.PageListing,
|
||||
bookingCode = "",
|
||||
userPoints,
|
||||
}: HotelCardProps) {
|
||||
const params = useParams()
|
||||
const lang = params.lang as Lang
|
||||
@@ -72,6 +74,15 @@ function HotelCard({
|
||||
availability.productType?.member?.rateType === RateTypeEnum.Regular
|
||||
const price = availability.productType
|
||||
|
||||
const userHasEnoughPoints =
|
||||
userPoints !== undefined
|
||||
? !!price?.redemptions?.some(
|
||||
(r) => r.localPrice.pointsPerStay < userPoints
|
||||
)
|
||||
: false
|
||||
|
||||
const notEnoughPointsLabel = intl.formatMessage({ id: "Not enough points" })
|
||||
|
||||
return (
|
||||
<article
|
||||
className={classNames}
|
||||
@@ -207,21 +218,39 @@ function HotelCard({
|
||||
))}
|
||||
</div>
|
||||
) : null}
|
||||
<Button
|
||||
asChild
|
||||
theme="base"
|
||||
intent="primary"
|
||||
size="small"
|
||||
className={styles.button}
|
||||
>
|
||||
<Link
|
||||
href={`${selectRate(lang)}?hotel=${hotel.operaId}`}
|
||||
color="none"
|
||||
keepSearchParams
|
||||
{userPoints !== undefined && !userHasEnoughPoints ? (
|
||||
<Tooltip
|
||||
arrow="left"
|
||||
position="bottom"
|
||||
text={notEnoughPointsLabel}
|
||||
>
|
||||
{intl.formatMessage({ id: "See rooms" })}
|
||||
</Link>
|
||||
</Button>
|
||||
<Button
|
||||
theme="base"
|
||||
intent="primary"
|
||||
size="small"
|
||||
className={styles.button}
|
||||
disabled
|
||||
>
|
||||
{notEnoughPointsLabel}
|
||||
</Button>
|
||||
</Tooltip>
|
||||
) : (
|
||||
<Button
|
||||
asChild
|
||||
theme="base"
|
||||
intent="primary"
|
||||
size="small"
|
||||
className={styles.button}
|
||||
>
|
||||
<Link
|
||||
href={`${selectRate(lang)}?hotel=${hotel.operaId}`}
|
||||
color="none"
|
||||
keepSearchParams
|
||||
>
|
||||
{intl.formatMessage({ id: "See rooms" })}
|
||||
</Link>
|
||||
</Button>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -30,6 +30,7 @@ import { RateTypeEnum } from "@/types/enums/rateType"
|
||||
export default function HotelCardListing({
|
||||
hotelData,
|
||||
type = HotelCardListingTypeEnum.PageListing,
|
||||
userPoints,
|
||||
}: HotelCardListingProps) {
|
||||
const { data: session } = useSession()
|
||||
const isUserLoggedIn = isValidClientSession(session)
|
||||
@@ -121,6 +122,7 @@ export default function HotelCardListing({
|
||||
}
|
||||
type={type}
|
||||
bookingCode={bookingCode}
|
||||
userPoints={userPoints}
|
||||
/>
|
||||
</div>
|
||||
))
|
||||
|
||||
@@ -246,6 +246,14 @@ export async function getHotels(
|
||||
return hotels
|
||||
}
|
||||
|
||||
export async function getUserPoints() {
|
||||
const membershipCard = await serverClient().user.safeMembershipLevel()
|
||||
if (!membershipCard) {
|
||||
return undefined
|
||||
}
|
||||
return membershipCard.currentPoints
|
||||
}
|
||||
|
||||
const hotelSurroundingsFilterNames = [
|
||||
"Hotel surroundings",
|
||||
"Hotel omgivelser",
|
||||
|
||||
@@ -23,7 +23,7 @@ import { convertObjToSearchParams } from "@/utils/url"
|
||||
|
||||
import HotelCardListing from "../HotelCardListing"
|
||||
import BookingCodeFilter from "./BookingCodeFilter"
|
||||
import { getFiltersFromHotels, getHotels } from "./helpers"
|
||||
import { getFiltersFromHotels, getHotels, getUserPoints } from "./helpers"
|
||||
import HotelCount from "./HotelCount"
|
||||
import HotelFilter from "./HotelFilter"
|
||||
import HotelSorter from "./HotelSorter"
|
||||
@@ -76,6 +76,11 @@ export default async function SelectHotel({
|
||||
!!redemption
|
||||
)
|
||||
|
||||
let userPoints
|
||||
if (redemption) {
|
||||
userPoints = await getUserPoints()
|
||||
}
|
||||
|
||||
const arrivalDate = new Date(selectHotelParams.fromDate)
|
||||
const departureDate = new Date(selectHotelParams.toDate)
|
||||
|
||||
@@ -247,7 +252,10 @@ export default async function SelectHotel({
|
||||
isAllUnavailable={isAllUnavailable}
|
||||
operaId={hotels?.[0]?.hotel.operaId}
|
||||
/>
|
||||
<HotelCardListing hotelData={hotels} />
|
||||
<HotelCardListing
|
||||
hotelData={hotels}
|
||||
userPoints={userPoints ? userPoints : undefined}
|
||||
/>
|
||||
</div>
|
||||
</main>
|
||||
<Suspense key={`${suspenseKey}-tracking`} fallback={null}>
|
||||
|
||||
Reference in New Issue
Block a user