fix(LOY-88): expiration date is now not defaulted to todays date if it's missing, instead nothing is shown
This commit is contained in:
@@ -10,35 +10,43 @@ import Card from "./Card"
|
||||
|
||||
import styles from "./surprises.module.css"
|
||||
|
||||
import type { Dayjs } from "dayjs"
|
||||
|
||||
import type { SlideProps } from "@/types/components/blocks/surprises"
|
||||
|
||||
export default function Slide({ surprise }: SlideProps) {
|
||||
const lang = useLang()
|
||||
const intl = useIntl()
|
||||
|
||||
const earliestExpirationDate = surprise.coupons?.reduce(
|
||||
(earliestDate, coupon) => {
|
||||
const expiresAt = dt(coupon.expiresAt)
|
||||
return earliestDate.isBefore(expiresAt) ? earliestDate : expiresAt
|
||||
},
|
||||
dt()
|
||||
)
|
||||
const earliestExpirationDate = surprise.coupons
|
||||
.map(({ expiresAt }) => expiresAt)
|
||||
.filter((expiresAt): expiresAt is string => !!expiresAt)
|
||||
.reduce((earliestDate: Dayjs | null, expiresAt) => {
|
||||
const expiresAtDate = dt(expiresAt)
|
||||
if (!earliestDate) {
|
||||
return expiresAtDate
|
||||
}
|
||||
|
||||
return earliestDate.isBefore(expiresAtDate) ? earliestDate : expiresAtDate
|
||||
}, null)
|
||||
|
||||
return (
|
||||
<Card title={surprise.label}>
|
||||
<Body textAlign="center">{surprise.description}</Body>
|
||||
<div className={styles.badge}>
|
||||
<Caption>
|
||||
{intl.formatMessage(
|
||||
{ id: "Valid through {expirationDate}" },
|
||||
{
|
||||
expirationDate: dt(earliestExpirationDate)
|
||||
.locale(lang)
|
||||
.format("D MMM YYYY"),
|
||||
}
|
||||
)}
|
||||
</Caption>
|
||||
</div>
|
||||
{earliestExpirationDate ? (
|
||||
<div className={styles.badge}>
|
||||
<Caption>
|
||||
{intl.formatMessage(
|
||||
{ id: "Valid through {expirationDate}" },
|
||||
{
|
||||
expirationDate: dt(earliestExpirationDate)
|
||||
.locale(lang)
|
||||
.format("D MMM YYYY"),
|
||||
}
|
||||
)}
|
||||
</Caption>
|
||||
</div>
|
||||
) : null}
|
||||
</Card>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user