chore: refactor points
This commit is contained in:
@@ -4,53 +4,18 @@ import { getIntl } from "@/i18n"
|
||||
|
||||
import styles from "./pointsColumn.module.css"
|
||||
|
||||
import type {
|
||||
NightsColumn,
|
||||
PointsColumn,
|
||||
PointsColumnProps,
|
||||
} from "@/types/components/myPages/points"
|
||||
import type { PointsColumnProps } from "@/types/components/myPages/points"
|
||||
|
||||
export const YourPointsColumn = ({ points }: PointsColumn) =>
|
||||
PointsColumn({
|
||||
points,
|
||||
title: "Your points to spend",
|
||||
subtitle: "as of today",
|
||||
})
|
||||
|
||||
export const NextLevelPointsColumn = ({ points, subtitle }: PointsColumn) =>
|
||||
PointsColumn({
|
||||
points,
|
||||
title: "Points needed to level up",
|
||||
subtitle,
|
||||
})
|
||||
|
||||
export const StayOnLevelColumn = ({ points, subtitle }: PointsColumn) =>
|
||||
PointsColumn({
|
||||
points,
|
||||
title: "Points needed to stay on level",
|
||||
subtitle,
|
||||
})
|
||||
|
||||
export const NextLevelNightsColumn = ({ nights, subtitle }: NightsColumn) =>
|
||||
PointsColumn({
|
||||
nights,
|
||||
title: "Nights needed to level up",
|
||||
subtitle,
|
||||
})
|
||||
|
||||
async function PointsColumn({
|
||||
points,
|
||||
nights,
|
||||
export async function PointsColumn({
|
||||
title,
|
||||
subtitle,
|
||||
value,
|
||||
}: PointsColumnProps) {
|
||||
const intl = await getIntl()
|
||||
|
||||
let number = "N/A"
|
||||
if (typeof points === "number") {
|
||||
number = intl.formatNumber(points)
|
||||
} else if (typeof nights === "number") {
|
||||
number = intl.formatNumber(nights)
|
||||
if (typeof value === "number") {
|
||||
number = intl.formatNumber(value)
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -61,16 +26,14 @@ async function PointsColumn({
|
||||
textAlign="center"
|
||||
className={styles.firstRow}
|
||||
>
|
||||
{intl.formatMessage({
|
||||
id: title,
|
||||
})}
|
||||
{title}
|
||||
</Body>
|
||||
<Title color="white" level="h2" textAlign="center">
|
||||
{number}
|
||||
</Title>
|
||||
{subtitle ? (
|
||||
<Body color="white" textAlign="center">
|
||||
{intl.formatMessage({ id: subtitle })}
|
||||
{subtitle}
|
||||
</Body>
|
||||
) : null}
|
||||
</article>
|
||||
|
||||
@@ -5,7 +5,7 @@ import { getIntl } from "@/i18n"
|
||||
import { getMembership } from "@/utils/user"
|
||||
|
||||
import PointsContainer from "./Container"
|
||||
import { NextLevelPointsColumn, YourPointsColumn } from "./PointsColumn"
|
||||
import { PointsColumn } from "./PointsColumn"
|
||||
|
||||
import type { UserProps } from "@/types/components/myPages/user"
|
||||
|
||||
@@ -23,11 +23,19 @@ export default async function Points({ user }: UserProps) {
|
||||
|
||||
return (
|
||||
<PointsContainer>
|
||||
<YourPointsColumn points={membership?.currentPoints} />
|
||||
<PointsColumn
|
||||
value={membership?.currentPoints}
|
||||
title={intl.formatMessage({ id: "Your points to spend" })}
|
||||
subtitle={intl.formatMessage({ id: "as of today" })}
|
||||
/>
|
||||
{nextLevel && (
|
||||
<NextLevelPointsColumn
|
||||
points={membership?.pointsRequiredToNextlevel}
|
||||
subtitle={`${intl.formatMessage({ id: "next level:" })} ${nextLevel.name}`}
|
||||
<PointsColumn
|
||||
value={membership?.pointsRequiredToNextlevel}
|
||||
title={intl.formatMessage({ id: "Points needed to level up" })}
|
||||
subtitle={intl.formatMessage(
|
||||
{ id: "next level: {nextLevel}" },
|
||||
{ nextLevel: nextLevel.name }
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
{/* TODO: Show NextLevelNightsColumn when nightsToTopTier data is correct from Antavo */}
|
||||
|
||||
Reference in New Issue
Block a user