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:
@@ -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)
|
||||
},
|
||||
[
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
import { logger } from "@scandic-hotels/common/logger"
|
||||
import { getServiceToken } from "@scandic-hotels/common/tokenManager"
|
||||
import { BookingErrorCodeEnum } from "@scandic-hotels/trpc/enums/bookingErrorCode"
|
||||
import { getBooking } from "@scandic-hotels/trpc/routers/booking/utils"
|
||||
import { getBooking } from "@scandic-hotels/trpc/services/booking/getBooking"
|
||||
import { encrypt } from "@scandic-hotels/trpc/utils/encryption"
|
||||
|
||||
import { BookingFlowConfig } from "../bookingFlowConfig/bookingFlowConfig"
|
||||
@@ -18,7 +18,7 @@ import { HandleSuccessCallback } from "../components/EnterDetails/Payment/Paymen
|
||||
import { serverClient } from "../trpc"
|
||||
|
||||
import type { Lang } from "@scandic-hotels/common/constants/language"
|
||||
import type { CreateBookingSchema } from "@scandic-hotels/trpc/routers/booking/mutation/create/schema"
|
||||
import type { BookingStatus } from "@scandic-hotels/trpc/services/booking/getBookingStatus"
|
||||
|
||||
import type { NextSearchParams } from "../types"
|
||||
|
||||
@@ -99,7 +99,7 @@ export async function PaymentCallbackPage({
|
||||
notFound()
|
||||
}
|
||||
|
||||
const booking = await getBooking(confirmationNumber, lang, token)
|
||||
const booking = await getBooking({ confirmationNumber, lang }, token)
|
||||
const refId = booking?.refId
|
||||
|
||||
const caller = await serverClient()
|
||||
@@ -156,7 +156,7 @@ function HandleBookingStatusError({
|
||||
config,
|
||||
status,
|
||||
}: {
|
||||
booking: CreateBookingSchema | null
|
||||
booking: BookingStatus | null
|
||||
confirmationNumber?: string
|
||||
returnUrl: string
|
||||
config: BookingFlowConfig
|
||||
|
||||
Reference in New Issue
Block a user