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
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
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"),
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user