Files
web/apps/scandic-web/components/MyPages/LevelProgressCard/ProgressLevelWrapper.tsx
Chuma Mcphoy (We Ahead) c6da0fb8cb Merged in feat/LOY-316-Level-Progress-Card (pull request #2739)
Feat/LOY-316 Level Progress Card

* feat(LOY-315): Add MembershipOverviewCard

* refactor(LOY-315): abstract sasbooststatus

* feat(LOY-316): build out LevelProgressCard skeleton & variant styling

* feat(LOY-316): Add HighesMembershipCard

* feat(LOY-316): ProgressBarCard base

* refactor(LOY-315): highest level card misc fixes

* feat(LOY-316): Add progress component to design system

* fix(LOY-316): type check

* refactor(LOY-316): calculate currentEarnings correctly

* fix(LOY-316): sas icon showing when not boosted

* fix(LOY-316): css module

* refactor(LOY-316): Restructure components

* feat(LOY-316): Add marker pin 📍

* fix(LOY-316): strict equality checks

* fix(LOY-316): code review fixes

* chore(LOY-316): conditionally hide old section under flag

* feat(LOY-316): Add level progress card to my points page

* chore(LOY-316): marker label container height


Approved-by: Matilda Landström
2025-09-10 06:53:22 +00:00

59 lines
2.0 KiB
TypeScript

import { MembershipLevelEnum } from "@scandic-hotels/common/constants/membershipLevels"
import { serverClient } from "@/lib/trpc/server"
import ProgressLevelCard from "./ProgressLevelCard"
import type { ProgressLevelWrapperProps } from "./types"
export default async function ProgressLevelWrapper({
user,
}: ProgressLevelWrapperProps) {
const caller = await serverClient()
if (!user.membership || !user.membership.membershipLevel) {
return null
}
// NOTE: We currently rely on the CMS to get "required_points" for a given level,
// but API is working on including them in the Profile endpoint.
const [currentLevel, nextLevel] = await Promise.all([
caller.contentstack.loyaltyLevels.byLevel({
level: MembershipLevelEnum[user.membership.membershipLevel],
}),
user.membership.nextLevel && MembershipLevelEnum[user.membership.nextLevel]
? caller.contentstack.loyaltyLevels.byLevel({
level: MembershipLevelEnum[user.membership.nextLevel],
})
: null,
])
const pointsToNextLevel = user.membership.pointsRequiredToNextlevel
// Relying on user.loyalty.points.earned isn't suffice here as it isn't limited to loyalty-level specific earnings,
// nor limited to earnings in the current member year.
// TODO: API is working on adding a tierEarnings field which we'll be able to use for this.
// Once that's out we won't need the nextLevel call above.
const currentEarnings =
nextLevel?.required_points && pointsToNextLevel
? nextLevel?.required_points - pointsToNextLevel
: null
let pointsNeededToKeepLevel = null
if (currentEarnings !== null && currentLevel?.required_points) {
if (currentEarnings < currentLevel.required_points) {
pointsNeededToKeepLevel = currentLevel.required_points - currentEarnings
}
}
return (
<ProgressLevelCard
pointsToNextLevel={pointsToNextLevel}
pointsEarned={currentEarnings}
pointsNeededToKeepLevel={pointsNeededToKeepLevel}
/>
)
}