Files
web/apps/scandic-web/components/Blocks/DynamicContent/Points/PointsToSpendCard/utils.ts
Anton Gunnarsson f79ff9b570 Merged in chore/cleanup-unused (pull request #3461)
chore: Cleanup unused vars, exports, types

* Cleanup some unused exports

* Remove more

* Readd CampaignPageIncludedHotelsRef

* Add alias comment to procedure exports

* Remove unused exports


Approved-by: Linus Flood
2026-01-22 12:34:07 +00:00

46 lines
1.0 KiB
TypeScript

import { dt } from "@scandic-hotels/common/dt"
import type { IntlShape } from "react-intl"
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(
{
id: "points.pointsToSpendCard.inDays",
defaultMessage: "In {days} days",
},
{
days: daysUntilExpiry,
}
)
} else {
return intl.formatMessage(
{
id: "points.pointsToSpendCard.onDate",
defaultMessage: "on {expiryDate}",
},
{
expiryDate: expiryDate.format("DD MMM YYYY"),
}
)
}
}