Files
web/apps/scandic-web/components/Blocks/DynamicContent/Points/PointsToSpendCard/utils.ts
Chuma Mcphoy (We Ahead) 6a9d598b97 Merged in feat/LOY-336-Points-to-Spend-Card (pull request #2830)
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
2025-09-22 10:16:40 +00:00

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"),
}
)
}
}