Merged in chore/refactor-trpc-booking-routes (pull request #3510)

feat(BOOK-750): refactor booking endpoints

* WIP

* wip

* wip

* parse dates in UTC

* wip

* no more errors

* Merge branch 'master' of bitbucket.org:scandic-swap/web into chore/refactor-trpc-booking-routes

* .

* cleanup

* import named z from zod

* fix(BOOK-750): updateBooking api endpoint expects dateOnly, we passed ISO date


Approved-by: Anton Gunnarsson
This commit is contained in:
Joakim Jäderberg
2026-02-02 14:28:14 +00:00
parent 8ac2c4ba22
commit 16cc26632e
44 changed files with 1621 additions and 1041 deletions

View File

@@ -52,7 +52,7 @@ import { getPaymentHeadingConfig } from "./utils"
import styles from "./payment.module.css"
import type { CreateBookingInput } from "@scandic-hotels/trpc/routers/booking/mutation/create/schema"
import type { CreateBookingInput } from "@scandic-hotels/trpc/routers/booking/input"
import type { CreditCard } from "@scandic-hotels/trpc/types/user"
import type { PriceChangeData } from "../PriceChangeData"
@@ -128,45 +128,46 @@ export default function PaymentClient({
const initiateBooking = trpc.booking.create.useMutation({
onSuccess: (result) => {
if (result) {
if ("error" in result) {
const queryParams = new URLSearchParams(searchParams.toString())
queryParams.set("errorCode", result.cause)
window.history.replaceState(
{},
"",
`${pathname}?${queryParams.toString()}`
)
handlePaymentError(result.cause)
return
}
const { booking } = result
const mainRoom = booking.rooms[0]
if (booking.reservationStatus == BookingStatusEnum.BookingCompleted) {
clearBookingWidgetState()
// Cookie is used by Booking Confirmation page to validate that the user came from payment callback
// eslint-disable-next-line react-hooks/immutability
document.cookie = `bcsig=${result.sig}; Path=/; Max-Age=60; Secure; SameSite=Strict`
const confirmationUrl = `${bookingConfirmation(lang)}?RefId=${encodeURIComponent(mainRoom.refId)}`
router.push(confirmationUrl)
return
}
setRefId(mainRoom.refId)
const hasPriceChange = booking.rooms.some((r) => r.priceChangedMetadata)
if (hasPriceChange) {
const priceChangeData = booking.rooms
.map((room) => room.priceChangedMetadata || null)
.filter(isNotNull)
setPriceChangeData(priceChangeData)
} else {
setIsPollingForBookingStatus(true)
}
} else {
if (!result) {
handlePaymentError("No confirmation number")
return
}
if ("error" in result) {
const queryParams = new URLSearchParams(searchParams.toString())
queryParams.set("errorCode", result.cause)
window.history.replaceState(
{},
"",
`${pathname}?${queryParams.toString()}`
)
handlePaymentError(result.cause)
return
}
const { booking } = result
const mainRoom = booking.rooms[0]
if (booking.reservationStatus == BookingStatusEnum.BookingCompleted) {
clearBookingWidgetState()
// Cookie is used by Booking Confirmation page to validate that the user came from payment callback
// eslint-disable-next-line react-hooks/immutability
document.cookie = `bcsig=${result.sig}; Path=/; Max-Age=60; Secure; SameSite=Strict`
const confirmationUrl = `${bookingConfirmation(lang)}?RefId=${encodeURIComponent(mainRoom.refId)}`
router.push(confirmationUrl)
return
}
setRefId(mainRoom.refId)
const hasPriceChange = booking.rooms.some((r) => r.priceChangedMetadata)
if (hasPriceChange) {
const priceChangeData = booking.rooms
.map((room) => room.priceChangedMetadata || null)
.filter(isNotNull)
setPriceChangeData(priceChangeData)
} else {
setIsPollingForBookingStatus(true)
}
},
onError: (error) => {
@@ -419,6 +420,7 @@ export default function PaymentClient({
}
),
}
initiateBooking.mutate(payload)
},
[