Fix/BOOK-662 handle overlapping dates timezone * fix(BOOK-662): handle overlapping dates alerts * fix(BOOK-662): handle overlapping dates alerts * fix(BOOK-662): add test same dates Approved-by: Anton Gunnarsson
36 lines
1.2 KiB
TypeScript
36 lines
1.2 KiB
TypeScript
import { z } from "zod"
|
|
|
|
import { AlertTypeEnum } from "@scandic-hotels/common/constants/alert"
|
|
import { dt } from "@scandic-hotels/common/dt"
|
|
import { nullableStringValidator } from "@scandic-hotels/common/utils/zod/stringValidator"
|
|
|
|
const specialAlertSchema = z.object({
|
|
description: nullableStringValidator,
|
|
displayInBookingFlow: z.boolean().default(false),
|
|
endDate: nullableStringValidator,
|
|
startDate: nullableStringValidator,
|
|
title: nullableStringValidator,
|
|
type: nullableStringValidator,
|
|
})
|
|
|
|
export const specialAlertsSchema = z
|
|
.array(specialAlertSchema)
|
|
.nullish()
|
|
// Filter out alerts with no title and no description since they won't have any visible content
|
|
// We're filtering on dates on the hotel page itself
|
|
.transform((arr) =>
|
|
arr ? arr.filter((alert) => alert?.description || alert?.title) : []
|
|
)
|
|
.transform((alerts) =>
|
|
alerts.map((alert, idx) => ({
|
|
heading: alert.title || null,
|
|
id: `alert-${alert.type}-${idx}`,
|
|
name: alert.type,
|
|
text: alert.description || null,
|
|
type: AlertTypeEnum.Info,
|
|
displayInBookingFlow: alert.displayInBookingFlow,
|
|
endDate: dt.utc(alert.endDate).toISOString(),
|
|
startDate: dt.utc(alert.startDate).toISOString(),
|
|
}))
|
|
)
|