Feat/lokalise rebuild * chore(lokalise): update translation ids * chore(lokalise): easier to switch between projects * chore(lokalise): update translation ids * . * . * . * . * . * . * chore(lokalise): update translation ids * chore(lokalise): update translation ids * . * . * . * chore(lokalise): update translation ids * chore(lokalise): update translation ids * . * . * chore(lokalise): update translation ids * chore(lokalise): update translation ids * chore(lokalise): new translations * merge * switch to errors for missing id's * merge * sync translations Approved-by: Linus Flood
46 lines
1.0 KiB
TypeScript
46 lines
1.0 KiB
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(
|
|
{
|
|
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"),
|
|
}
|
|
)
|
|
}
|
|
}
|