feat(SW-508): contract changes for hotel alerts

This commit is contained in:
Erik Tiekstra
2024-11-07 13:52:22 +01:00
parent 52ae49246f
commit de5d80ec92
3 changed files with 25 additions and 24 deletions

View File

@@ -91,7 +91,7 @@ export default function HotelInfoCard({ hotelData }: HotelInfoCardProps) {
</div> </div>
</section> </section>
)} )}
{hotelAttributes?.meta?.specialAlerts.map((alert) => { {hotelAttributes?.specialAlerts.map((alert) => {
return ( return (
<div className={styles.hotelAlert} key={`wrapper_${alert.id}`}> <div className={styles.hotelAlert} key={`wrapper_${alert.id}`}>
<Alert <Alert

View File

@@ -312,22 +312,24 @@ const socialMediaSchema = z.object({
facebook: z.string().optional(), facebook: z.string().optional(),
}) })
const metaSpecialAlertSchema = z.object({ const specialAlertSchema = z.object({
type: z.string(), type: z.string(),
title: z.string().optional(), title: z.string().optional(),
description: z.string().optional(), description: z.string().optional(),
displayInBookingFlow: z.boolean(), displayInBookingFlow: z.boolean(),
startDate: z.string(), startDate: z.string().optional(),
endDate: z.string(), endDate: z.string().optional(),
}) })
const metaSchema = z.object({ const specialAlertsSchema = z
specialAlerts: z .array(specialAlertSchema)
.array(metaSpecialAlertSchema)
.transform((data) => { .transform((data) => {
const now = dt().utc().format("YYYY-MM-DD") const now = dt().utc().format("YYYY-MM-DD")
const filteredAlerts = data.filter((alert) => { const filteredAlerts = data.filter((alert) => {
const shouldShowNow = alert.startDate <= now && alert.endDate >= now const shouldShowNow =
alert.startDate && alert.endDate
? alert.startDate <= now && alert.endDate >= now
: true
const hasText = alert.description || alert.title const hasText = alert.description || alert.title
return shouldShowNow && hasText return shouldShowNow && hasText
}) })
@@ -338,8 +340,7 @@ const metaSchema = z.object({
text: alert.description || null, text: alert.description || null,
})) }))
}) })
.default([]), .default([])
})
const relationshipsSchema = z.object({ const relationshipsSchema = z.object({
restaurants: z.object({ restaurants: z.object({
@@ -425,7 +426,7 @@ export const getHotelDataSchema = z.object({
parking: z.array(parkingSchema), parking: z.array(parkingSchema),
specialNeedGroups: z.array(specialNeedGroupSchema), specialNeedGroups: z.array(specialNeedGroupSchema),
socialMedia: socialMediaSchema, socialMedia: socialMediaSchema,
meta: metaSchema.optional(), specialAlerts: specialAlertsSchema,
isActive: z.boolean(), isActive: z.boolean(),
conferencesAndMeetings: facilitySchema.optional(), conferencesAndMeetings: facilitySchema.optional(),
healthAndWellness: facilitySchema.optional(), healthAndWellness: facilitySchema.optional(),

View File

@@ -294,7 +294,7 @@ export const hotelQueryRouter = router({
const hotelAttributes = hotelData.data.attributes const hotelAttributes = hotelData.data.attributes
const images = hotelAttributes.gallery?.smallerImages const images = hotelAttributes.gallery?.smallerImages
const hotelAlerts = hotelAttributes.meta?.specialAlerts || [] const hotelAlerts = hotelAttributes.specialAlerts
const roomCategories = included const roomCategories = included
? included.filter((item) => item.type === "roomcategories") ? included.filter((item) => item.type === "roomcategories")