Merged in fix/refetching-availability-on-select (pull request #2204)
don't use rateCode to determine if bookingCode should come from the room or the 'big' input * don't use rateCode to determine if bookingCode should come from the room or the 'big' input Approved-by: Linus Flood
This commit is contained in:
@@ -4,6 +4,7 @@ import { useSearchParams } from "next/navigation"
|
||||
import { useIntl } from "react-intl"
|
||||
|
||||
import { trpc } from "@/lib/trpc/client"
|
||||
import { selectRateRoomsAvailabilityInputSchema } from "@/server/routers/hotels/input"
|
||||
|
||||
import Alert from "@/components/TempDesignSystem/Alert"
|
||||
import useLang from "@/hooks/useLang"
|
||||
@@ -33,29 +34,32 @@ export function RoomsContainer({
|
||||
searchParamsToRecord(searchParams)
|
||||
)
|
||||
|
||||
const { data, isFetching, isError, error } =
|
||||
trpc.hotel.availability.selectRate.rooms.useQuery(
|
||||
{
|
||||
booking,
|
||||
lang,
|
||||
},
|
||||
{
|
||||
retry(failureCount, error) {
|
||||
if (error.data?.code === "BAD_REQUEST") {
|
||||
return false
|
||||
}
|
||||
const bookingInput = selectRateRoomsAvailabilityInputSchema.safeParse({
|
||||
booking,
|
||||
lang,
|
||||
})
|
||||
|
||||
return failureCount <= 3
|
||||
},
|
||||
}
|
||||
)
|
||||
const { data, isFetching, isError, error } =
|
||||
trpc.hotel.availability.selectRate.rooms.useQuery(bookingInput.data!, {
|
||||
retry(failureCount, error) {
|
||||
if (error.data?.code === "BAD_REQUEST") {
|
||||
return false
|
||||
}
|
||||
|
||||
return failureCount <= 3
|
||||
},
|
||||
enabled: bookingInput.success,
|
||||
})
|
||||
|
||||
if (isFetching) {
|
||||
return <RoomsContainerSkeleton />
|
||||
}
|
||||
|
||||
if (isError) {
|
||||
const errorMessage = getErrorMessage(error.data?.zodError?.formErrors, intl)
|
||||
if (isError || !bookingInput.success) {
|
||||
const errorMessage = getErrorMessage(
|
||||
error?.data?.zodError?.formErrors,
|
||||
intl
|
||||
)
|
||||
|
||||
return (
|
||||
<div className={styles.errorContainer}>
|
||||
|
||||
@@ -142,12 +142,7 @@ const baseBookingSchema = z.object({
|
||||
export const selectRateRoomsAvailabilityInputSchema = z
|
||||
.object({
|
||||
booking: baseBookingSchema.extend({
|
||||
rooms: z.array(
|
||||
baseRoomSchema.extend({
|
||||
rateCode: z.string().optional(),
|
||||
roomTypeCode: z.string().optional(),
|
||||
})
|
||||
),
|
||||
rooms: z.array(baseRoomSchema),
|
||||
}),
|
||||
lang: z.nativeEnum(Lang),
|
||||
})
|
||||
@@ -196,10 +191,7 @@ export const selectRateRoomsAvailabilityInputSchema = z
|
||||
|
||||
export const selectRateRoomAvailabilityInputSchema = z.object({
|
||||
booking: baseBookingSchema.extend({
|
||||
room: baseRoomSchema.extend({
|
||||
rateCode: z.string().optional(),
|
||||
roomTypeCode: z.string().optional(),
|
||||
}),
|
||||
room: baseRoomSchema,
|
||||
}),
|
||||
lang: z.nativeEnum(Lang),
|
||||
})
|
||||
|
||||
@@ -431,10 +431,9 @@ export const hotelQueryRouter = router({
|
||||
.query(async function ({ ctx, input }) {
|
||||
input.booking.rooms = input.booking.rooms.map((room) => ({
|
||||
...room,
|
||||
bookingCode: room.rateCode
|
||||
? room.bookingCode
|
||||
: input.booking.bookingCode,
|
||||
bookingCode: room.bookingCode || input.booking.bookingCode,
|
||||
}))
|
||||
|
||||
const availability = await getRoomsAvailability(
|
||||
input,
|
||||
ctx.token,
|
||||
|
||||
@@ -1038,9 +1038,6 @@ export async function getRoomsAvailability(
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
next: {
|
||||
revalidate: 60,
|
||||
},
|
||||
},
|
||||
params
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user