diff --git a/apps/scandic-web/components/HotelReservation/MyStay/ManageStay/ActionPanel/Actions/ModifyStay/hooks/useModifyStay.ts b/apps/scandic-web/components/HotelReservation/MyStay/ManageStay/ActionPanel/Actions/ModifyStay/hooks/useModifyStay.ts index da941d64e..59721f0d0 100644 --- a/apps/scandic-web/components/HotelReservation/MyStay/ManageStay/ActionPanel/Actions/ModifyStay/hooks/useModifyStay.ts +++ b/apps/scandic-web/components/HotelReservation/MyStay/ManageStay/ActionPanel/Actions/ModifyStay/hooks/useModifyStay.ts @@ -99,7 +99,7 @@ export default function useModifyStay({ bookingCode: bookedRoom.bookingCode ?? undefined, rateCode: bookedRoom.rateDefinition.rateCode, roomTypeCode: bookedRoom.roomTypeCode, - lang, + inputLang: lang, }) if (!data?.selectedRoom || data.selectedRoom.roomsLeft <= 0) { diff --git a/apps/scandic-web/components/HotelReservation/MyStay/utils.ts b/apps/scandic-web/components/HotelReservation/MyStay/utils.ts index db4e51db1..70002010b 100644 --- a/apps/scandic-web/components/HotelReservation/MyStay/utils.ts +++ b/apps/scandic-web/components/HotelReservation/MyStay/utils.ts @@ -1,3 +1,5 @@ +import { ChildBedTypeEnum } from "@/constants/booking" + export function formatChildBedPreferences({ childrenAges, childBedPreferences, @@ -11,13 +13,51 @@ export function formatChildBedPreferences({ }) { if (childrenAges.length === 0) return "" - const preferences = childrenAges - .map((age, index) => { - const bed = childBedPreferences[index].bedType - if (!bed) return null - return `${age}:${bed}` - }) - .filter(Boolean) + // Find the bed types from preferences + const cribBed = childBedPreferences.find( + (pref) => pref.bedType === ChildBedTypeEnum.Crib + )?.bedType + const parentsBed = childBedPreferences.find( + (pref) => pref.bedType === ChildBedTypeEnum.ParentsBed + )?.bedType + const extraBed = childBedPreferences.find( + (pref) => pref.bedType === ChildBedTypeEnum.ExtraBed + )?.bedType - return `[${preferences.join(", ")}]` + // Step 1: Assign cribs to all children <= 2 years + const preferences = childrenAges.map((age, index) => { + if (age <= 2 && cribBed) return `${age}:${cribBed}` + return { age, index } + }) + + // Filter out children who still need bed assignment + const remainingChildren = preferences.filter( + (pref): pref is { age: number; index: number } => typeof pref === "object" + ) + + // Step 2: Assign adults bed to one child <= 5 years if available + const hasParentsBed = childBedPreferences.some( + (pref) => pref.bedType === ChildBedTypeEnum.ParentsBed && pref.quantity > 0 + ) + + if (hasParentsBed && parentsBed) { + const youngChildIndex = remainingChildren.findIndex( + (child) => child.age <= 5 + ) + if (youngChildIndex >= 0) { + const child = remainingChildren[youngChildIndex] + preferences[child.index] = `${child.age}:${parentsBed}` + remainingChildren.splice(youngChildIndex, 1) + } + } + + // Step 3: Assign extra beds to remaining children + if (extraBed) { + remainingChildren.forEach(({ age, index }) => { + preferences[index] = `${age}:${extraBed}` + }) + } + + // Filter out any null values and join the results + return `[${preferences.filter((pref) => typeof pref === "string").join(", ")}]` } diff --git a/apps/scandic-web/server/routers/hotels/input.ts b/apps/scandic-web/server/routers/hotels/input.ts index 0acf5c70c..703d45b1b 100644 --- a/apps/scandic-web/server/routers/hotels/input.ts +++ b/apps/scandic-web/server/routers/hotels/input.ts @@ -59,7 +59,7 @@ export const selectedRoomAvailabilityInputSchema = z.object({ roomTypeCode: z.string(), counterRateCode: z.string().optional(), packageCodes: z.array(z.nativeEnum(RoomPackageCodeEnum)).optional(), - lang: z.nativeEnum(Lang).optional(), + inputLang: z.nativeEnum(Lang).optional(), redemption: z.boolean().optional(), }) diff --git a/apps/scandic-web/server/routers/hotels/query.ts b/apps/scandic-web/server/routers/hotels/query.ts index c3c69493e..d3c1b7334 100644 --- a/apps/scandic-web/server/routers/hotels/query.ts +++ b/apps/scandic-web/server/routers/hotels/query.ts @@ -593,8 +593,11 @@ export const getRoomAvailability = async ( counterRateCode, roomTypeCode, redemption, + inputLang, } = input + const language = inputLang ?? lang + const params: Record = { roomStayStartDate, roomStayEndDate, @@ -602,7 +605,7 @@ export const getRoomAvailability = async ( ...(children && { children }), ...(bookingCode && { bookingCode }), ...(redemption && { isRedemption: "true" }), - language: toApiLang(lang), + language: toApiLang(language), } metrics.selectedRoomAvailability.counter.add(1, { @@ -685,7 +688,7 @@ export const getRoomAvailability = async ( { hotelId, isCardOnlyPayment: false, - language: lang, + language, }, serviceToken ?? token )