Feat/SW-755 price change non happy * fix(SW-755): dont show field error if checkbox has no children * feat(SW-755): Price change route + dialog WIP * fix(SW-755): minor refactoring * fix(SW-755): added logging to price change route * fix(SW-755): remove redundant search param logic * fix(SW-755): moved enum cast to zod instead * fix(SW-755): move prop type to types folder * fix(SW-755): Added suspense to Payment and refactored payment options hook * fix(SW-755): seperated terms and conditions copy from the checkbox label * fix(SW-755): add currency format and fixed wrong translation * fix(SW-755): change from undefined to null * fix(SW-755): added extra type safety to payment options Approved-by: Christian Andolf Approved-by: Simon.Emanuelsson
52 lines
1.1 KiB
TypeScript
52 lines
1.1 KiB
TypeScript
"use client"
|
|
|
|
import { useRef } from "react"
|
|
|
|
import { BookingStatusEnum } from "@/constants/booking"
|
|
import { trpc } from "@/lib/trpc/client"
|
|
|
|
export function useHandleBookingStatus({
|
|
confirmationNumber,
|
|
expectedStatus,
|
|
maxRetries,
|
|
retryInterval,
|
|
enabled,
|
|
}: {
|
|
confirmationNumber: string | null
|
|
expectedStatus: BookingStatusEnum
|
|
maxRetries: number
|
|
retryInterval: number
|
|
enabled: boolean
|
|
}) {
|
|
const retries = useRef(0)
|
|
|
|
const query = trpc.booking.status.useQuery(
|
|
{ confirmationNumber: confirmationNumber ?? "" },
|
|
{
|
|
enabled,
|
|
refetchInterval: (query) => {
|
|
retries.current = query.state.dataUpdateCount
|
|
|
|
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,
|
|
isTimeout: retries.current >= maxRetries,
|
|
}
|
|
}
|