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}>
|
||||
|
||||
@@ -539,6 +539,7 @@
|
||||
"Non refundable": "Ikke-refunderbart",
|
||||
"Non-refundable": "Ikke-refunderbart",
|
||||
"Nordic Swan Ecolabel": "Svanemærket",
|
||||
"Not enough points": "Ikke nok point",
|
||||
"Not found": "Ikke fundet",
|
||||
"Not included": "Ikke inkluderet",
|
||||
"Number of charging points for electric cars: {number}": "Antal ladepunkter til elbiler: {number}",
|
||||
|
||||
@@ -540,6 +540,7 @@
|
||||
"Non refundable": "Nicht erstattungsfähig",
|
||||
"Non-refundable": "Nicht erstattungsfähig",
|
||||
"Nordic Swan Ecolabel": "Nordic Swan Ecolabel",
|
||||
"Not enough points": "Nicht genügend Punkte",
|
||||
"Not found": "Nicht gefunden",
|
||||
"Not included": "Nicht inbegriffen",
|
||||
"Number of charging points for electric cars: {number}": "Anzahl der Ladestationen für Elektroautos: {number}",
|
||||
|
||||
@@ -538,6 +538,7 @@
|
||||
"Non refundable": "Non refundable",
|
||||
"Non-refundable": "Non-refundable",
|
||||
"Nordic Swan Ecolabel": "Nordic Swan Ecolabel",
|
||||
"Not enough points": "Not enough points",
|
||||
"Not found": "Not found",
|
||||
"Not included": "Not included",
|
||||
"Number of charging points for electric cars: {number}": "Number of charging points for electric cars: {number}",
|
||||
|
||||
@@ -539,6 +539,7 @@
|
||||
"Non refundable": "Ei palautettavissa",
|
||||
"Non-refundable": "Ei palautettavissa",
|
||||
"Nordic Swan Ecolabel": "Ympäristömerkki Miljömärkt",
|
||||
"Not enough points": "Pisteet eivät riitä",
|
||||
"Not found": "Ei löydetty",
|
||||
"Not included": "Ei sisälly",
|
||||
"Number of charging points for electric cars: {number}": "Sähköautojen latauspisteiden määrä: {number}",
|
||||
|
||||
@@ -538,6 +538,7 @@
|
||||
"Non refundable": "Ikke-refunderbart",
|
||||
"Non-refundable": "Ikke-refunderbart",
|
||||
"Nordic Swan Ecolabel": "Svanemerket",
|
||||
"Not enough points": "Ikke nok poeng",
|
||||
"Not found": "Ikke funnet",
|
||||
"Not included": "Ikke inkludert",
|
||||
"Number of charging points for electric cars: {number}": "Antall ladepunkter for elbiler: {number}",
|
||||
|
||||
@@ -538,6 +538,7 @@
|
||||
"Non refundable": "Ej återbetalningsbar",
|
||||
"Non-refundable": "Ej återbetalningsbar",
|
||||
"Nordic Swan Ecolabel": "Svanenmärkt",
|
||||
"Not enough points": "Inte tillräckligt antal poäng",
|
||||
"Not found": "Hittades inte",
|
||||
"Not included": "Ej inkluderat",
|
||||
"Number of charging points for electric cars: {number}": "Antal laddplatser för elbilar: {number}",
|
||||
|
||||
@@ -15,6 +15,7 @@ export type HotelData = {
|
||||
export type HotelCardListingProps = {
|
||||
hotelData: HotelResponse[]
|
||||
type?: HotelCardListingTypeEnum
|
||||
userPoints?: number
|
||||
}
|
||||
|
||||
export interface NullableHotelData extends Omit<HotelData, "hotelData"> {
|
||||
|
||||
@@ -7,4 +7,5 @@ export type HotelCardProps = {
|
||||
type?: HotelCardListingTypeEnum
|
||||
state?: "default" | "active"
|
||||
bookingCode?: string | null
|
||||
userPoints?: number
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user