fix: race condition with booking confirmation being set in session storage

This commit is contained in:
Tobias Johansson
2024-10-10 15:55:51 +02:00
parent 740419bad2
commit 1bce311666

View File

@@ -58,11 +58,6 @@ export default function Payment({ hotel }: PaymentProps) {
const initiateBooking = trpc.booking.booking.create.useMutation({
onSuccess: (result) => {
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)
} else {
// TODO: add proper error message
@@ -85,6 +80,8 @@ export default function Payment({ hotel }: PaymentProps) {
useEffect(() => {
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)
}
}, [confirmationNumber, bookingStatus, router])