Merged in feat/sw-1313-show-sas-points (pull request #1682)

SW-1313 - Add support for getting SAS EB points

Approved-by: Joakim Jäderberg
This commit is contained in:
Anton Gunnarsson
2025-04-08 11:03:38 +00:00
parent d30cc7e2be
commit 5cb19dfccd
5 changed files with 62 additions and 13 deletions

View File

@@ -1,11 +1,12 @@
import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon" import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon"
import { Typography } from "@scandic-hotels/design-system/Typography" import { Typography } from "@scandic-hotels/design-system/Typography"
import { getProfileSafely } from "@/lib/trpc/memoizedRequests" import { getProfileWithExtendedPartnerData } from "@/lib/trpc/memoizedRequests"
import Image from "@/components/Image" import Image from "@/components/Image"
import SkeletonShimmer from "@/components/SkeletonShimmer" import SkeletonShimmer from "@/components/SkeletonShimmer"
import { getIntl } from "@/i18n" import { getIntl } from "@/i18n"
import { getEurobonusMembership } from "@/utils/user"
import { TransferPointsFormClient } from "./TransferPointsFormClient" import { TransferPointsFormClient } from "./TransferPointsFormClient"
@@ -13,14 +14,17 @@ import styles from "./transferPoints.module.css"
import type { Lang } from "@/constants/languages" import type { Lang } from "@/constants/languages"
const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms))
export async function TransferPointsForm({ lang }: { lang: Lang }) { export async function TransferPointsForm({ lang }: { lang: Lang }) {
const profile = await getProfileSafely() const profile = await getProfileWithExtendedPartnerData()
if (!profile) return null
const eurobonusMembership = getEurobonusMembership(profile?.loyalty)
if (!eurobonusMembership) return null
const scandicPoints = profile?.membership?.currentPoints ?? 0 const scandicPoints = profile?.membership?.currentPoints ?? 0
const sasPoints = eurobonusMembership.spendablePoints || 0
// TODO get from api // TODO get from api
await wait(1_000)
const sasPoints = 250_000
const exchangeRate = 2 const exchangeRate = 2
return ( return (
@@ -89,7 +93,11 @@ async function TransferPointsFormContent({
</p> </p>
</Typography> </Typography>
{sasPoints === null ? ( {sasPoints === null ? (
<SkeletonShimmer width="10ch" height="20px" /> <SkeletonShimmer
width="10ch"
height="20px"
display="inline-block"
/>
) : ( ) : (
<Typography variant="Body/Paragraph/mdRegular"> <Typography variant="Body/Paragraph/mdRegular">
<p> <p>
@@ -132,7 +140,11 @@ async function TransferPointsFormContent({
</p> </p>
</Typography> </Typography>
{scandicPoints === null ? ( {scandicPoints === null ? (
<SkeletonShimmer width="10ch" height="20px" /> <SkeletonShimmer
width="10ch"
height="20px"
display="inline-block"
/>
) : ( ) : (
<Typography variant="Body/Paragraph/mdRegular"> <Typography variant="Body/Paragraph/mdRegular">
<p> <p>

View File

@@ -8,7 +8,7 @@
rgba(255, 255, 255, 0) 100% rgba(255, 255, 255, 0) 100%
); );
} }
.shimmer { .shimmer.light {
--shimmer-background: rgba(217, 217, 217, 0.5); --shimmer-background: rgba(217, 217, 217, 0.5);
--shimmer: linear-gradient( --shimmer: linear-gradient(
90deg, 90deg,

View File

@@ -41,6 +41,12 @@ export const getProfileSafely = cache(
} }
) )
export const getProfileWithExtendedPartnerData = cache(
async function getMemoizedProfileWithPartnerData() {
return serverClient().user.getWithExtendedPartnerData()
}
)
export const getSavedPaymentCardsSafely = cache( export const getSavedPaymentCardsSafely = cache(
async function getMemoizedSavedPaymentCardsSafely( async function getMemoizedSavedPaymentCardsSafely(
input: GetSavedPaymentCardsInput input: GetSavedPaymentCardsInput

View File

@@ -28,6 +28,7 @@ export const sasMembershipSchema = z
type: z.literal("SAS_EB"), type: z.literal("SAS_EB"),
tier: sasEurobonusTier, tier: sasEurobonusTier,
nextTier: sasEurobonusTier.nullish(), nextTier: sasEurobonusTier.nullish(),
spendablePoints: z.number().nullish(),
}) })
.merge(commonMembershipSchema) .merge(commonMembershipSchema)

View File

@@ -82,18 +82,30 @@ const getCreditCardsFailCounter = meter.createCounter(
) )
export const getVerifiedUser = cache( export const getVerifiedUser = cache(
async ({ session }: { session: Session }) => { async ({
session,
includeExtendedPartnerData,
}: {
session: Session
includeExtendedPartnerData?: boolean
}) => {
const now = Date.now() const now = Date.now()
if (session.token.expires_at && session.token.expires_at < now) { if (session.token.expires_at && session.token.expires_at < now) {
return { error: true, cause: "token_expired" } as const return { error: true, cause: "token_expired" } as const
} }
getVerifiedUserCounter.add(1) getVerifiedUserCounter.add(1)
console.info("api.user.profile getVerifiedUser start", JSON.stringify({})) console.info("api.user.profile getVerifiedUser start", JSON.stringify({}))
const apiResponse = await api.get(api.endpoints.v2.Profile.profile, { const apiResponse = await api.get(
headers: { api.endpoints.v2.Profile.profile,
Authorization: `Bearer ${session.token.access_token}`, {
headers: {
Authorization: `Bearer ${session.token.access_token}`,
},
}, },
}) includeExtendedPartnerData
? { includes: "extendedPartnerInformation" }
: {}
)
if (!apiResponse.ok) { if (!apiResponse.ok) {
const text = await apiResponse.text() const text = await apiResponse.text()
@@ -318,6 +330,24 @@ export const userQueryRouter = router({
return parsedUser(data.data, true) return parsedUser(data.data, true)
}), }),
getWithExtendedPartnerData: safeProtectedProcedure.query(
async function getUser({ ctx }) {
if (!isValidSession(ctx.session)) {
return null
}
const data = await getVerifiedUser({
session: ctx.session,
includeExtendedPartnerData: true,
})
if (!data || "error" in data) {
return null
}
return parsedUser(data.data, true)
}
),
name: safeProtectedProcedure.query(async function ({ ctx }) { name: safeProtectedProcedure.query(async function ({ ctx }) {
if (!isValidSession(ctx.session)) { if (!isValidSession(ctx.session)) {
return null return null