Merged in feat/SW-431-payment-flow (pull request #635)
Feat/SW-431 payment flow * feat(SW-431): Update mock hotel data * feat(SW-431): Added route handler and trpc routes * feat(SW-431): List payment methods and handle booking status and redirection * feat(SW-431): Updated booking page to poll for booking status * feat(SW-431): Updated create booking contract * feat(SW-431): small fix * fix(SW-431): Added intl string and sorted dictionaries * fix(SW-431): Changes from PR * fix(SW-431): fixes from PR * fix(SW-431): add todo comments * fix(SW-431): update schema prop Approved-by: Simon.Emanuelsson
This commit is contained in:
35
hooks/booking/useHandleBookingStatus.ts
Normal file
35
hooks/booking/useHandleBookingStatus.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
"use client"
|
||||
|
||||
import { BookingStatusEnum } from "@/constants/booking"
|
||||
import { trpc } from "@/lib/trpc/client"
|
||||
|
||||
export function useHandleBookingStatus(
|
||||
confirmationNumber: string | null,
|
||||
expectedStatus: BookingStatusEnum,
|
||||
maxRetries: number,
|
||||
retryInterval: number
|
||||
) {
|
||||
const query = trpc.booking.status.useQuery(
|
||||
{ confirmationNumber: confirmationNumber ?? "" },
|
||||
{
|
||||
enabled: !!confirmationNumber,
|
||||
refetchInterval: (query) => {
|
||||
if (query.state.error || query.state.dataUpdateCount >= maxRetries) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (query.state.data?.reservationStatus === expectedStatus) {
|
||||
return false
|
||||
}
|
||||
|
||||
return retryInterval
|
||||
},
|
||||
refetchIntervalInBackground: true,
|
||||
refetchOnWindowFocus: false,
|
||||
refetchOnMount: false,
|
||||
retry: false,
|
||||
}
|
||||
)
|
||||
|
||||
return query
|
||||
}
|
||||
Reference in New Issue
Block a user