feat(LOY-336): Add PointsToSpendCard * feat(LOY-366): Add PointsToSpendCard * feat(LOY-336): Add Expiring Points Table Sidepeek * fix(LOY-336): Hide old section * fix(LOY-336): description mobile styling * chore(LOY-336): css cleanup Approved-by: Matilda Landström
44 lines
955 B
TypeScript
44 lines
955 B
TypeScript
import { dt } from "@scandic-hotels/common/dt"
|
|
|
|
import type { IntlShape } from "react-intl"
|
|
|
|
export const DAYS_UNTIL_EXPIRY_WARNING = 30
|
|
|
|
/**
|
|
* Get expiry label for points based on the expiry date.
|
|
* @returns The formatted expiry date text or empty string if no expiry date
|
|
*/
|
|
export function getExpiryLabel(
|
|
pointsExpiryDate: string | undefined,
|
|
intl: IntlShape,
|
|
lang: string
|
|
): string {
|
|
if (!pointsExpiryDate) {
|
|
return ""
|
|
}
|
|
|
|
const now = dt()
|
|
const expiryDate = dt(pointsExpiryDate).locale(lang)
|
|
const daysUntilExpiry = expiryDate.diff(now, "days")
|
|
|
|
if (daysUntilExpiry <= DAYS_UNTIL_EXPIRY_WARNING) {
|
|
return intl.formatMessage(
|
|
{
|
|
defaultMessage: "In {days} days",
|
|
},
|
|
{
|
|
days: daysUntilExpiry,
|
|
}
|
|
)
|
|
} else {
|
|
return intl.formatMessage(
|
|
{
|
|
defaultMessage: "on {expiryDate}",
|
|
},
|
|
{
|
|
expiryDate: expiryDate.format("DD MMM YYYY"),
|
|
}
|
|
)
|
|
}
|
|
}
|