Merged in feat/membership-information (pull request #233)
Feat(WEB-307) Display correct membership information * fix: fix typo * chore: update fetch of user membership * chore: update components to use api data * chore: remove lang as static value * fix: adapt to dev updates * fix: adapt to code from dev * fix: break out MembershipLevel into its a React component * fix: add enum to zod validation * refactor: rename tier to level * refactor: remove unnecessary casts * refactor: change toString() to hideEmpty=false * refactor: remove toString() * refactor: remove hideEmpty from title and subtitle * fix: update currentLevel with data * fix: fix from rebase Approved-by: Michael Zetterberg
This commit is contained in:
committed by
Michael Zetterberg
parent
aca9221ea6
commit
9931d9edef
@@ -1,3 +1,4 @@
|
||||
import { MembershipLevelEnum } from "@/constants/membershipLevels"
|
||||
import { serverClient } from "@/lib/trpc/server"
|
||||
|
||||
import Header from "@/components/SectionHeader"
|
||||
@@ -6,43 +7,58 @@ import Link from "@/components/TempDesignSystem/Link"
|
||||
import BiroScript from "@/components/TempDesignSystem/Text/BiroScript"
|
||||
import Title from "@/components/TempDesignSystem/Text/Title"
|
||||
import { getIntl } from "@/i18n"
|
||||
import { getMembershipLevelObject } from "@/utils/membershipLevel"
|
||||
import { getMembership } from "@/utils/user"
|
||||
|
||||
import styles from "./current.module.css"
|
||||
|
||||
import { AccountPageComponentProps } from "@/types/components/myPages/myPage/accountPage"
|
||||
import type { AccountPageComponentProps } from "@/types/components/myPages/myPage/accountPage"
|
||||
import type { LangParams } from "@/types/params"
|
||||
|
||||
export default async function CurrentBenefitsBlock({
|
||||
title,
|
||||
subtitle,
|
||||
link,
|
||||
}: AccountPageComponentProps) {
|
||||
lang,
|
||||
}: AccountPageComponentProps & LangParams) {
|
||||
const user = await serverClient().user.get()
|
||||
const { formatMessage } = await getIntl()
|
||||
// TODO: level should be fetched from the `user` object once available
|
||||
// TAKE NOTE: we need clarification on how benefits stack from different levels
|
||||
// in order to determine if a benefit is specific to a level or if it is a cumulative benefit
|
||||
// we might have to add a new boolean property "exclusive" or similar
|
||||
const userLevel = 1
|
||||
if (!user) {
|
||||
return null
|
||||
}
|
||||
const membership = getMembership(user.memberships)
|
||||
if (!membership) {
|
||||
// TODO: handle this case?
|
||||
return null
|
||||
}
|
||||
|
||||
const currentLevel = Array.of(...Array(3).keys())
|
||||
const currentLevel = getMembershipLevelObject(
|
||||
user.memberships[0].membershipLevel as MembershipLevelEnum,
|
||||
lang
|
||||
)
|
||||
if (!currentLevel) {
|
||||
// TODO: handle this case?
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<section className={styles.container}>
|
||||
<Header title={title} link={link} subtitle={subtitle} />
|
||||
<Grids.Scrollable>
|
||||
{currentLevel.map((benefit) => (
|
||||
<Link className={styles.card} href="#" key={benefit}>
|
||||
{currentLevel.benefits.map((benefit, idx) => (
|
||||
<Link className={styles.card} href="#" key={`${currentLevel}-${idx}`}>
|
||||
<BiroScript
|
||||
className={styles.script}
|
||||
color="primaryLightOnSurfaceAccent"
|
||||
type="two"
|
||||
>
|
||||
{formatMessage({ id: "As our Close Friend" })}
|
||||
{formatMessage({ id: "As our" })} {currentLevel.name}
|
||||
</BiroScript>
|
||||
<Title as="h5" level="h3" textAlign="center">
|
||||
{formatMessage({
|
||||
id: "Free soft drink voucher for the kids when staying",
|
||||
})}
|
||||
{benefit.title}
|
||||
</Title>
|
||||
</Link>
|
||||
))}
|
||||
|
||||
Reference in New Issue
Block a user