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:
@@ -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({
|
||||
</p>
|
||||
</Typography>
|
||||
{sasPoints === null ? (
|
||||
<SkeletonShimmer width="10ch" height="20px" />
|
||||
<SkeletonShimmer
|
||||
width="10ch"
|
||||
height="20px"
|
||||
display="inline-block"
|
||||
/>
|
||||
) : (
|
||||
<Typography variant="Body/Paragraph/mdRegular">
|
||||
<p>
|
||||
@@ -132,7 +140,11 @@ async function TransferPointsFormContent({
|
||||
</p>
|
||||
</Typography>
|
||||
{scandicPoints === null ? (
|
||||
<SkeletonShimmer width="10ch" height="20px" />
|
||||
<SkeletonShimmer
|
||||
width="10ch"
|
||||
height="20px"
|
||||
display="inline-block"
|
||||
/>
|
||||
) : (
|
||||
<Typography variant="Body/Paragraph/mdRegular">
|
||||
<p>
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -28,6 +28,7 @@ export const sasMembershipSchema = z
|
||||
type: z.literal("SAS_EB"),
|
||||
tier: sasEurobonusTier,
|
||||
nextTier: sasEurobonusTier.nullish(),
|
||||
spendablePoints: z.number().nullish(),
|
||||
})
|
||||
.merge(commonMembershipSchema)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user