fix: race condition with booking confirmation being set in session storage
This commit is contained in:
@@ -58,11 +58,6 @@ export default function Payment({ hotel }: PaymentProps) {
|
|||||||
const initiateBooking = trpc.booking.booking.create.useMutation({
|
const initiateBooking = trpc.booking.booking.create.useMutation({
|
||||||
onSuccess: (result) => {
|
onSuccess: (result) => {
|
||||||
if (result?.confirmationNumber) {
|
if (result?.confirmationNumber) {
|
||||||
// Planet doesn't support query params so we have to store values in session storage
|
|
||||||
sessionStorage.setItem(
|
|
||||||
BOOKING_CONFIRMATION_NUMBER,
|
|
||||||
result.confirmationNumber
|
|
||||||
)
|
|
||||||
setConfirmationNumber(result.confirmationNumber)
|
setConfirmationNumber(result.confirmationNumber)
|
||||||
} else {
|
} else {
|
||||||
// TODO: add proper error message
|
// TODO: add proper error message
|
||||||
@@ -85,6 +80,8 @@ export default function Payment({ hotel }: PaymentProps) {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (confirmationNumber && bookingStatus?.data?.paymentUrl) {
|
if (confirmationNumber && bookingStatus?.data?.paymentUrl) {
|
||||||
|
// Planet doesn't support query params so we have to store values in session storage
|
||||||
|
sessionStorage.setItem(BOOKING_CONFIRMATION_NUMBER, confirmationNumber)
|
||||||
router.push(bookingStatus.data.paymentUrl)
|
router.push(bookingStatus.data.paymentUrl)
|
||||||
}
|
}
|
||||||
}, [confirmationNumber, bookingStatus, router])
|
}, [confirmationNumber, bookingStatus, router])
|
||||||
|
|||||||
Reference in New Issue
Block a user