feat(SW-791): make confirmation page dynamic

This commit is contained in:
Simon Emanuelsson
2024-11-06 16:31:03 +01:00
parent e6a70a0a8a
commit 0897a398ee
35 changed files with 983 additions and 577 deletions

View File

@@ -381,11 +381,54 @@ const merchantInformationSchema = z.object({
}),
})
const hotelFacilityDetailSchema = z
.object({
description: z.string(),
heading: z.string(),
})
.optional()
/** Possibly more values */
const hotelFacilityDetailsSchema = z.object({
breakfast: hotelFacilityDetailSchema,
checkout: hotelFacilityDetailSchema,
gym: hotelFacilityDetailSchema,
internet: hotelFacilityDetailSchema,
laundry: hotelFacilityDetailSchema,
luggage: hotelFacilityDetailSchema,
shop: hotelFacilityDetailSchema,
telephone: hotelFacilityDetailSchema,
})
const hotelInformationSchema = z
.object({
description: z.string(),
heading: z.string(),
link: z.string().optional(),
})
.optional()
const hotelInformationsSchema = z.object({
accessibility: hotelInformationSchema,
safety: hotelInformationSchema,
sustainability: hotelInformationSchema,
})
const hotelFactsSchema = z.object({
checkin: checkinSchema,
ecoLabels: ecoLabelsSchema,
hotelFacilityDetail: hotelFacilityDetailsSchema.default({}),
hotelInformation: hotelInformationsSchema.default({}),
interior: interiorSchema,
receptionHours: receptionHoursSchema,
yearBuilt: z.string(),
})
// NOTE: Find schema at: https://aks-test.scandichotels.com/hotel/swagger/v1/index.html
export const getHotelDataSchema = z.object({
data: z.object({
id: z.string(),
type: z.string(), // No enum here but the standard return appears to be "hotels".
type: z.literal("hotels"), // No enum here but the standard return appears to be "hotels".
language: z.string().transform((val) => {
const lang = toLang(val)
if (!lang) {
@@ -394,44 +437,41 @@ export const getHotelDataSchema = z.object({
return lang
}),
attributes: z.object({
name: z.string(),
operaId: z.string(),
keywords: z.array(z.string()),
isPublished: z.boolean(),
accessibilityElevatorPitchText: z.string().optional(),
address: addressSchema,
cityId: z.string(),
cityName: z.string(),
ratings: ratingsSchema,
address: addressSchema,
conferencesAndMeetings: facilitySchema.optional(),
contactInformation: contactInformationSchema,
hotelFacts: z.object({
checkin: checkinSchema,
ecoLabels: ecoLabelsSchema,
interior: interiorSchema,
receptionHours: receptionHoursSchema,
yearBuilt: z.string(),
}),
location: locationSchema,
hotelContent: hotelContentSchema,
detailedFacilities: z
.array(detailedFacilitySchema)
.transform((facilities) =>
facilities.sort((a, b) => b.sortOrder - a.sortOrder)
),
gallery: gallerySchema.optional(),
healthAndWellness: facilitySchema.optional(),
healthFacilities: z.array(healthFacilitySchema),
hotelContent: hotelContentSchema,
hotelFacts: hotelFactsSchema,
hotelRoomElevatorPitchText: z.string().optional(),
hotelType: z.string().optional(),
isActive: z.boolean(),
isPublished: z.boolean(),
keywords: z.array(z.string()),
location: locationSchema,
merchantInformationData: merchantInformationSchema,
rewardNight: rewardNightSchema,
name: z.string(),
operaId: z.string(),
parking: z.array(parkingSchema),
pointsOfInterest: z
.array(pointOfInterestSchema)
.transform((pois) => pois.sort((a, b) => a.distance - b.distance)),
parking: z.array(parkingSchema),
specialNeedGroups: z.array(specialNeedGroupSchema),
ratings: ratingsSchema,
rewardNight: rewardNightSchema,
restaurantImages: facilitySchema.optional(),
socialMedia: socialMediaSchema,
specialAlerts: specialAlertsSchema,
isActive: z.boolean(),
conferencesAndMeetings: facilitySchema.optional(),
healthAndWellness: facilitySchema.optional(),
restaurantImages: facilitySchema.optional(),
gallery: gallerySchema.optional(),
specialNeedGroups: z.array(specialNeedGroupSchema),
}),
relationships: relationshipsSchema,
}),
@@ -631,7 +671,7 @@ export const apiCitiesByCountrySchema = z.object({
})
export interface CitiesByCountry
extends z.output<typeof apiCitiesByCountrySchema> {}
extends z.output<typeof apiCitiesByCountrySchema> { }
export type CitiesGroupedByCountry = Record<string, CitiesByCountry["data"]>
export const apiCountriesSchema = z.object({
@@ -661,7 +701,7 @@ export const apiCountriesSchema = z.object({
}),
})
export interface Countries extends z.output<typeof apiCountriesSchema> {}
export interface Countries extends z.output<typeof apiCountriesSchema> { }
export const apiLocationCitySchema = z.object({
attributes: z.object({
@@ -802,10 +842,7 @@ export const breakfastPackageSchema = z.object({
description: z.string(),
localPrice: breakfastPackagePriceSchema,
requestedPrice: breakfastPackagePriceSchema,
packageType: z.enum([
PackageTypeEnum.BreakfastAdult,
PackageTypeEnum.BreakfastChildren,
]),
packageType: z.literal(PackageTypeEnum.BreakfastAdult),
})
export const breakfastPackagesSchema = z

View File

@@ -1062,20 +1062,10 @@ export const hotelQueryRouter = router({
user.membership &&
["L6", "L7"].includes(user.membership.membershipLevel)
) {
const originalBreakfastPackage = breakfastPackages.data.find(
(pkg) => pkg.code === BreakfastPackageEnum.REGULAR_BREAKFAST
)
const freeBreakfastPackage = breakfastPackages.data.find(
(pkg) => pkg.code === BreakfastPackageEnum.FREE_MEMBER_BREAKFAST
)
if (freeBreakfastPackage && freeBreakfastPackage.localPrice) {
if (
originalBreakfastPackage &&
originalBreakfastPackage.localPrice
) {
freeBreakfastPackage.localPrice.price =
originalBreakfastPackage.localPrice.price
}
if (freeBreakfastPackage?.localPrice) {
return [freeBreakfastPackage]
}
}