feat(SW-415): Normalize roomSchema
This commit is contained in:
@@ -22,20 +22,20 @@ export function Rooms({ rooms }: RoomsProps) {
|
|||||||
|
|
||||||
const mappedRooms = rooms
|
const mappedRooms = rooms
|
||||||
.map((room) => {
|
.map((room) => {
|
||||||
const size = `${room.attributes.roomSize.min} - ${room.attributes.roomSize.max} m²`
|
const size = `${room.roomSize.min} - ${room.roomSize.max} m²`
|
||||||
const personLabel =
|
const personLabel =
|
||||||
room.attributes.occupancy.total === 1
|
room.occupancy.total === 1
|
||||||
? intl.formatMessage({ id: "hotelPages.rooms.roomCard.person" })
|
? intl.formatMessage({ id: "hotelPages.rooms.roomCard.person" })
|
||||||
: intl.formatMessage({ id: "hotelPages.rooms.roomCard.persons" })
|
: intl.formatMessage({ id: "hotelPages.rooms.roomCard.persons" })
|
||||||
|
|
||||||
const subtitle = `${size} (${room.attributes.occupancy.total} ${personLabel})`
|
const subtitle = `${size} (${room.occupancy.total} ${personLabel})`
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: room.id,
|
id: room.id,
|
||||||
images: room.attributes.content.images,
|
images: room.images,
|
||||||
title: room.attributes.name,
|
title: room.name,
|
||||||
subtitle: subtitle,
|
subtitle: subtitle,
|
||||||
sortOrder: room.attributes.sortOrder,
|
sortOrder: room.sortOrder,
|
||||||
popularChoice: null,
|
popularChoice: null,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -53,16 +53,16 @@ export default function RoomCard({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const roomSize = roomCategories.find(
|
const roomSize = roomCategories.find(
|
||||||
(category) => category.attributes.name === roomConfiguration.roomType
|
(category) => category.name === roomConfiguration.roomType
|
||||||
)?.attributes.roomSize
|
)?.roomSize
|
||||||
|
|
||||||
const occupancy = roomCategories.find(
|
const occupancy = roomCategories.find(
|
||||||
(category) => category.attributes.name === roomConfiguration.roomType
|
(category) => category.name === roomConfiguration.roomType
|
||||||
)?.attributes.occupancy.total
|
)?.occupancy.total
|
||||||
|
|
||||||
const roomDescription = roomCategories.find(
|
const roomDescription = roomCategories.find(
|
||||||
(room) => room.attributes.name === roomConfiguration.roomType
|
(room) => room.name === roomConfiguration.roomType
|
||||||
)?.attributes.content.texts.descriptions.short
|
)?.descriptions.short
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.card}>
|
<div className={styles.card}>
|
||||||
|
|||||||
@@ -425,26 +425,39 @@ const roomFacilitiesSchema = z.object({
|
|||||||
sortOrder: z.number(),
|
sortOrder: z.number(),
|
||||||
})
|
})
|
||||||
|
|
||||||
export const roomSchema = z.object({
|
export const roomSchema = z
|
||||||
attributes: z.object({
|
.object({
|
||||||
name: z.string(),
|
attributes: z.object({
|
||||||
sortOrder: z.number(),
|
name: z.string(),
|
||||||
content: roomContentSchema,
|
sortOrder: z.number(),
|
||||||
roomTypes: z.array(roomTypesSchema),
|
content: roomContentSchema,
|
||||||
roomFacilities: z.array(roomFacilitiesSchema),
|
roomTypes: z.array(roomTypesSchema),
|
||||||
occupancy: z.object({
|
roomFacilities: z.array(roomFacilitiesSchema),
|
||||||
total: z.number(),
|
occupancy: z.object({
|
||||||
adults: z.number(),
|
total: z.number(),
|
||||||
children: z.number(),
|
adults: z.number(),
|
||||||
|
children: z.number(),
|
||||||
|
}),
|
||||||
|
roomSize: z.object({
|
||||||
|
min: z.number(),
|
||||||
|
max: z.number(),
|
||||||
|
}),
|
||||||
}),
|
}),
|
||||||
roomSize: z.object({
|
id: z.string(),
|
||||||
min: z.number(),
|
type: z.enum(["roomcategories"]),
|
||||||
max: z.number(),
|
})
|
||||||
}),
|
.transform((data) => {
|
||||||
}),
|
return {
|
||||||
id: z.string(),
|
descriptions: data.attributes.content.texts.descriptions,
|
||||||
type: z.enum(["roomcategories"]),
|
id: data.id,
|
||||||
})
|
images: data.attributes.content.images,
|
||||||
|
name: data.attributes.name,
|
||||||
|
occupancy: data.attributes.occupancy,
|
||||||
|
roomSize: data.attributes.roomSize,
|
||||||
|
sortOrder: data.attributes.sortOrder,
|
||||||
|
type: data.type,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
const merchantInformationSchema = z.object({
|
const merchantInformationSchema = z.object({
|
||||||
webMerchantId: z.string(),
|
webMerchantId: z.string(),
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import type { RoomData } from "@/types/hotel"
|
|||||||
|
|
||||||
export interface RoomCardProps {
|
export interface RoomCardProps {
|
||||||
id: string
|
id: string
|
||||||
images: RoomData["attributes"]["content"]["images"]
|
images: RoomData["images"]
|
||||||
title: string
|
title: string
|
||||||
subtitle: string
|
subtitle: string
|
||||||
badgeTextTransKey: string | null
|
badgeTextTransKey: string | null
|
||||||
|
|||||||
Reference in New Issue
Block a user