65 lines
1.5 KiB
TypeScript
65 lines
1.5 KiB
TypeScript
import { trpc } from "@/lib/trpc/client"
|
|
|
|
import { RoomPackageCodeEnum } from "@/types/components/hotelReservation/selectRate/roomFilter"
|
|
import type { Lang } from "@/constants/languages"
|
|
import type { ChildrenInRoom } from "@/utils/hotelSearchDetails"
|
|
|
|
export function useRoomsAvailability(
|
|
adultsCount: number[],
|
|
hotelId: number,
|
|
fromDateString: string,
|
|
toDateString: string,
|
|
lang: Lang,
|
|
childArray: ChildrenInRoom,
|
|
bookingCode?: string
|
|
) {
|
|
const roomsAvailability =
|
|
trpc.hotel.availability.roomsCombinedAvailability.useQuery({
|
|
adultsCount,
|
|
bookingCode,
|
|
childArray,
|
|
hotelId,
|
|
lang,
|
|
roomStayEndDate: toDateString,
|
|
roomStayStartDate: fromDateString,
|
|
})
|
|
|
|
const data = roomsAvailability.data?.map((ra) => {
|
|
if (ra.status === "fulfilled") {
|
|
return ra.value
|
|
}
|
|
return {
|
|
details: ra.reason,
|
|
error: "request_failure",
|
|
}
|
|
})
|
|
|
|
return {
|
|
...roomsAvailability,
|
|
data,
|
|
}
|
|
}
|
|
|
|
export function useHotelPackages(
|
|
adultArray: number[],
|
|
childArray: ChildrenInRoom,
|
|
fromDateString: string,
|
|
toDateString: string,
|
|
hotelId: number,
|
|
lang: Lang
|
|
) {
|
|
return trpc.hotel.packages.get.useQuery({
|
|
adults: adultArray[0], // Using the first adult count
|
|
children: childArray?.[0]?.length, // Using the first children count
|
|
endDate: toDateString,
|
|
hotelId: hotelId.toString(),
|
|
packageCodes: [
|
|
RoomPackageCodeEnum.ACCESSIBILITY_ROOM,
|
|
RoomPackageCodeEnum.PET_ROOM,
|
|
RoomPackageCodeEnum.ALLERGY_ROOM,
|
|
],
|
|
startDate: fromDateString,
|
|
lang: lang,
|
|
})
|
|
}
|