Merged in feat/refactor-select-rate (pull request #1402)
Select-rate: refactor - converted RoomsContainer into a client component * feat/select-rate - refactor and fixed duplicate key warning * Rooms as client component * Fixed lang in input * It works * Cleanup * Cleanup * PR fixes Approved-by: Joakim Jäderberg
This commit is contained in:
@@ -1,4 +1,9 @@
|
||||
import { trpc } from "@/lib/trpc/client"
|
||||
|
||||
import { RoomPackageCodeEnum } from "@/types/components/hotelReservation/selectRate/roomFilter"
|
||||
import type { Child } from "@/types/components/hotelReservation/selectRate/selectRate"
|
||||
import type { RoomsAvailability } from "@/types/trpc/routers/hotel/roomAvailability"
|
||||
import type { Lang } from "@/constants/languages"
|
||||
|
||||
export function combineRoomAvailabilities(
|
||||
availabilityResults: PromiseSettledResult<RoomsAvailability | null>[]
|
||||
@@ -37,3 +42,56 @@ export function getRates(
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
export function useRoomsAvailability(
|
||||
uniqueAdultsCount: number[],
|
||||
hotelId: number,
|
||||
fromDateString: string,
|
||||
toDateString: string,
|
||||
lang: Lang,
|
||||
childArray?: Child[]
|
||||
) {
|
||||
const returnValue =
|
||||
trpc.hotel.availability.roomsCombinedAvailability.useQuery({
|
||||
hotelId,
|
||||
roomStayStartDate: fromDateString,
|
||||
roomStayEndDate: toDateString,
|
||||
uniqueAdultsCount,
|
||||
childArray,
|
||||
lang,
|
||||
})
|
||||
|
||||
const combinedAvailability = returnValue.data?.length
|
||||
? combineRoomAvailabilities(
|
||||
returnValue.data as PromiseSettledResult<RoomsAvailability | null>[]
|
||||
)
|
||||
: null
|
||||
|
||||
return {
|
||||
...returnValue,
|
||||
data: combinedAvailability,
|
||||
}
|
||||
}
|
||||
|
||||
export function useHotelPackages(
|
||||
adultArray: number[],
|
||||
childArray: Child[] | undefined,
|
||||
fromDateString: string,
|
||||
toDateString: string,
|
||||
hotelId: number,
|
||||
lang: Lang
|
||||
) {
|
||||
return trpc.hotel.packages.get.useQuery({
|
||||
adults: adultArray[0], // Using the first adult count
|
||||
children: childArray ? childArray.length : undefined,
|
||||
endDate: toDateString,
|
||||
hotelId: hotelId.toString(),
|
||||
packageCodes: [
|
||||
RoomPackageCodeEnum.ACCESSIBILITY_ROOM,
|
||||
RoomPackageCodeEnum.PET_ROOM,
|
||||
RoomPackageCodeEnum.ALLERGY_ROOM,
|
||||
],
|
||||
startDate: fromDateString,
|
||||
lang: lang,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user