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 { useIntl } from "react-intl"
|
||||||
|
|
||||||
import { trpc } from "@/lib/trpc/client"
|
import { trpc } from "@/lib/trpc/client"
|
||||||
|
import { selectRateRoomsAvailabilityInputSchema } from "@/server/routers/hotels/input"
|
||||||
|
|
||||||
import Alert from "@/components/TempDesignSystem/Alert"
|
import Alert from "@/components/TempDesignSystem/Alert"
|
||||||
import useLang from "@/hooks/useLang"
|
import useLang from "@/hooks/useLang"
|
||||||
@@ -33,29 +34,32 @@ export function RoomsContainer({
|
|||||||
searchParamsToRecord(searchParams)
|
searchParamsToRecord(searchParams)
|
||||||
)
|
)
|
||||||
|
|
||||||
const { data, isFetching, isError, error } =
|
const bookingInput = selectRateRoomsAvailabilityInputSchema.safeParse({
|
||||||
trpc.hotel.availability.selectRate.rooms.useQuery(
|
booking,
|
||||||
{
|
lang,
|
||||||
booking,
|
})
|
||||||
lang,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
retry(failureCount, error) {
|
|
||||||
if (error.data?.code === "BAD_REQUEST") {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
if (isFetching) {
|
||||||
return <RoomsContainerSkeleton />
|
return <RoomsContainerSkeleton />
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isError) {
|
if (isError || !bookingInput.success) {
|
||||||
const errorMessage = getErrorMessage(error.data?.zodError?.formErrors, intl)
|
const errorMessage = getErrorMessage(
|
||||||
|
error?.data?.zodError?.formErrors,
|
||||||
|
intl
|
||||||
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.errorContainer}>
|
<div className={styles.errorContainer}>
|
||||||
|
|||||||
@@ -142,12 +142,7 @@ const baseBookingSchema = z.object({
|
|||||||
export const selectRateRoomsAvailabilityInputSchema = z
|
export const selectRateRoomsAvailabilityInputSchema = z
|
||||||
.object({
|
.object({
|
||||||
booking: baseBookingSchema.extend({
|
booking: baseBookingSchema.extend({
|
||||||
rooms: z.array(
|
rooms: z.array(baseRoomSchema),
|
||||||
baseRoomSchema.extend({
|
|
||||||
rateCode: z.string().optional(),
|
|
||||||
roomTypeCode: z.string().optional(),
|
|
||||||
})
|
|
||||||
),
|
|
||||||
}),
|
}),
|
||||||
lang: z.nativeEnum(Lang),
|
lang: z.nativeEnum(Lang),
|
||||||
})
|
})
|
||||||
@@ -196,10 +191,7 @@ export const selectRateRoomsAvailabilityInputSchema = z
|
|||||||
|
|
||||||
export const selectRateRoomAvailabilityInputSchema = z.object({
|
export const selectRateRoomAvailabilityInputSchema = z.object({
|
||||||
booking: baseBookingSchema.extend({
|
booking: baseBookingSchema.extend({
|
||||||
room: baseRoomSchema.extend({
|
room: baseRoomSchema,
|
||||||
rateCode: z.string().optional(),
|
|
||||||
roomTypeCode: z.string().optional(),
|
|
||||||
}),
|
|
||||||
}),
|
}),
|
||||||
lang: z.nativeEnum(Lang),
|
lang: z.nativeEnum(Lang),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -431,10 +431,9 @@ export const hotelQueryRouter = router({
|
|||||||
.query(async function ({ ctx, input }) {
|
.query(async function ({ ctx, input }) {
|
||||||
input.booking.rooms = input.booking.rooms.map((room) => ({
|
input.booking.rooms = input.booking.rooms.map((room) => ({
|
||||||
...room,
|
...room,
|
||||||
bookingCode: room.rateCode
|
bookingCode: room.bookingCode || input.booking.bookingCode,
|
||||||
? room.bookingCode
|
|
||||||
: input.booking.bookingCode,
|
|
||||||
}))
|
}))
|
||||||
|
|
||||||
const availability = await getRoomsAvailability(
|
const availability = await getRoomsAvailability(
|
||||||
input,
|
input,
|
||||||
ctx.token,
|
ctx.token,
|
||||||
|
|||||||
@@ -1038,9 +1038,6 @@ export async function getRoomsAvailability(
|
|||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${token}`,
|
Authorization: `Bearer ${token}`,
|
||||||
},
|
},
|
||||||
next: {
|
|
||||||
revalidate: 60,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
params
|
params
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user