diff --git a/apps/scandic-web/components/Blocks/DynamicContent/SAS/TransferPoints/TransferPointsForm.tsx b/apps/scandic-web/components/Blocks/DynamicContent/SAS/TransferPoints/TransferPointsForm.tsx index 2f4e2f797..922d1b4b1 100644 --- a/apps/scandic-web/components/Blocks/DynamicContent/SAS/TransferPoints/TransferPointsForm.tsx +++ b/apps/scandic-web/components/Blocks/DynamicContent/SAS/TransferPoints/TransferPointsForm.tsx @@ -1,11 +1,12 @@ import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon" 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 SkeletonShimmer from "@/components/SkeletonShimmer" import { getIntl } from "@/i18n" +import { getEurobonusMembership } from "@/utils/user" import { TransferPointsFormClient } from "./TransferPointsFormClient" @@ -13,14 +14,17 @@ import styles from "./transferPoints.module.css" import type { Lang } from "@/constants/languages" -const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)) 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 sasPoints = eurobonusMembership.spendablePoints || 0 // TODO get from api - await wait(1_000) - const sasPoints = 250_000 const exchangeRate = 2 return ( @@ -89,7 +93,11 @@ async function TransferPointsFormContent({

{sasPoints === null ? ( - + ) : (

@@ -132,7 +140,11 @@ async function TransferPointsFormContent({

{scandicPoints === null ? ( - + ) : (

diff --git a/apps/scandic-web/components/SkeletonShimmer/skeleton.module.css b/apps/scandic-web/components/SkeletonShimmer/skeleton.module.css index f71015692..4adf0dfbe 100644 --- a/apps/scandic-web/components/SkeletonShimmer/skeleton.module.css +++ b/apps/scandic-web/components/SkeletonShimmer/skeleton.module.css @@ -8,7 +8,7 @@ rgba(255, 255, 255, 0) 100% ); } -.shimmer { +.shimmer.light { --shimmer-background: rgba(217, 217, 217, 0.5); --shimmer: linear-gradient( 90deg, diff --git a/apps/scandic-web/lib/trpc/memoizedRequests/index.ts b/apps/scandic-web/lib/trpc/memoizedRequests/index.ts index b80bbf780..16deee137 100644 --- a/apps/scandic-web/lib/trpc/memoizedRequests/index.ts +++ b/apps/scandic-web/lib/trpc/memoizedRequests/index.ts @@ -41,6 +41,12 @@ export const getProfileSafely = cache( } ) +export const getProfileWithExtendedPartnerData = cache( + async function getMemoizedProfileWithPartnerData() { + return serverClient().user.getWithExtendedPartnerData() + } +) + export const getSavedPaymentCardsSafely = cache( async function getMemoizedSavedPaymentCardsSafely( input: GetSavedPaymentCardsInput diff --git a/apps/scandic-web/server/routers/user/output.ts b/apps/scandic-web/server/routers/user/output.ts index 73385702a..7cf4d71b9 100644 --- a/apps/scandic-web/server/routers/user/output.ts +++ b/apps/scandic-web/server/routers/user/output.ts @@ -28,6 +28,7 @@ export const sasMembershipSchema = z type: z.literal("SAS_EB"), tier: sasEurobonusTier, nextTier: sasEurobonusTier.nullish(), + spendablePoints: z.number().nullish(), }) .merge(commonMembershipSchema) diff --git a/apps/scandic-web/server/routers/user/query.ts b/apps/scandic-web/server/routers/user/query.ts index 8a4137ac0..87f8eea95 100644 --- a/apps/scandic-web/server/routers/user/query.ts +++ b/apps/scandic-web/server/routers/user/query.ts @@ -82,18 +82,30 @@ const getCreditCardsFailCounter = meter.createCounter( ) export const getVerifiedUser = cache( - async ({ session }: { session: Session }) => { + async ({ + session, + includeExtendedPartnerData, + }: { + session: Session + includeExtendedPartnerData?: boolean + }) => { const now = Date.now() if (session.token.expires_at && session.token.expires_at < now) { return { error: true, cause: "token_expired" } as const } getVerifiedUserCounter.add(1) console.info("api.user.profile getVerifiedUser start", JSON.stringify({})) - const apiResponse = await api.get(api.endpoints.v2.Profile.profile, { - headers: { - Authorization: `Bearer ${session.token.access_token}`, + const apiResponse = await api.get( + api.endpoints.v2.Profile.profile, + { + headers: { + Authorization: `Bearer ${session.token.access_token}`, + }, }, - }) + includeExtendedPartnerData + ? { includes: "extendedPartnerInformation" } + : {} + ) if (!apiResponse.ok) { const text = await apiResponse.text() @@ -318,6 +330,24 @@ export const userQueryRouter = router({ 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 }) { if (!isValidSession(ctx.session)) { return null