fix: unbreak toApiLang call that failed everytime

This commit is contained in:
Simon Emanuelsson
2025-04-03 09:16:15 +02:00
committed by Michael Zetterberg
parent 30c7eb07fa
commit 6d869ceba7
7 changed files with 23 additions and 20 deletions

View File

@@ -34,6 +34,12 @@ export default async function SelectRatePage({
return notFound() return notFound()
} }
// If someone tries to update the url with
// a bookingCode also, then we need to remove it
if (isRedemption && searchParams.bookingCode) {
searchParams.bookingCode = ""
}
return ( return (
<Suspense <Suspense
key={suspenseKey} key={suspenseKey}

View File

@@ -99,7 +99,7 @@ export default function useModifyStay({
bookingCode: bookedRoom.bookingCode ?? undefined, bookingCode: bookedRoom.bookingCode ?? undefined,
rateCode: bookedRoom.rateDefinition.rateCode, rateCode: bookedRoom.rateDefinition.rateCode,
roomTypeCode: bookedRoom.roomTypeCode, roomTypeCode: bookedRoom.roomTypeCode,
inputLang: lang, lang,
}) })
if (!data?.selectedRoom || data.selectedRoom.roomsLeft <= 0) { if (!data?.selectedRoom || data.selectedRoom.roomsLeft <= 0) {

View File

@@ -483,20 +483,18 @@ export const bookingMutationRouter = router({
update: safeProtectedServiceProcedure update: safeProtectedServiceProcedure
.input(updateBookingInput) .input(updateBookingInput)
.mutation(async function ({ ctx, input }) { .mutation(async function ({ ctx, input }) {
const accessToken = ctx.serviceToken const accessToken = ctx.session?.token.access_token || ctx.serviceToken
const { confirmationNumber, ...body } = input const { confirmationNumber, ...body } = input
updateBookingCounter.add(1, { confirmationNumber }) updateBookingCounter.add(1, { confirmationNumber })
const headers = {
Authorization: `Bearer ${accessToken}`,
}
const apiResponse = await api.put( const apiResponse = await api.put(
api.endpoints.v1.Booking.booking(confirmationNumber), api.endpoints.v1.Booking.booking(confirmationNumber),
{ {
headers, body,
body: body, headers: {
Authorization: `Bearer ${accessToken}`,
},
} }
) )

View File

@@ -61,7 +61,7 @@ export const selectedRoomAvailabilityInputSchema = z.object({
roomTypeCode: z.string(), roomTypeCode: z.string(),
counterRateCode: z.string().optional(), counterRateCode: z.string().optional(),
packageCodes: z.array(z.nativeEnum(RoomPackageCodeEnum)).optional(), packageCodes: z.array(z.nativeEnum(RoomPackageCodeEnum)).optional(),
inputLang: z.nativeEnum(Lang).optional(), lang: z.nativeEnum(Lang).optional(),
redemption: z.boolean().optional(), redemption: z.boolean().optional(),
}) })

View File

@@ -705,9 +705,10 @@ export const hotelQueryRouter = router({
}) })
}) })
.query(async ({ input, ctx }) => { .query(async ({ input, ctx }) => {
const lang = toApiLang(input.lang || ctx.lang)
let selectedRoomData = await getSelectedRoomAvailability( let selectedRoomData = await getSelectedRoomAvailability(
input, input,
toApiLang(ctx.lang), lang,
ctx.token, ctx.token,
ctx.userPoints ctx.userPoints
) )
@@ -718,7 +719,6 @@ export const hotelQueryRouter = router({
children, children,
counterRateCode, counterRateCode,
hotelId, hotelId,
inputLang,
roomStayEndDate, roomStayEndDate,
roomStayStartDate, roomStayStartDate,
roomTypeCode, roomTypeCode,
@@ -797,7 +797,7 @@ export const hotelQueryRouter = router({
{ {
hotelId, hotelId,
isCardOnlyPayment: false, isCardOnlyPayment: false,
language: inputLang ?? ctx.lang, language: input.lang || ctx.lang,
}, },
ctx.serviceToken ctx.serviceToken
) )
@@ -884,7 +884,7 @@ export const hotelQueryRouter = router({
adults, adults,
...(children && { children }), ...(children && { children }),
...(bookingCode && { bookingCode }), ...(bookingCode && { bookingCode }),
language: inputLang ?? ctx.lang, language: lang,
}, },
}, },
}) })

View File

@@ -618,7 +618,6 @@ export async function getSelectedRoomAvailability(
bookingCode, bookingCode,
children, children,
hotelId, hotelId,
inputLang,
roomStayEndDate, roomStayEndDate,
roomStayStartDate, roomStayStartDate,
redemption, redemption,
@@ -631,7 +630,7 @@ export async function getSelectedRoomAvailability(
...(children && { children }), ...(children && { children }),
...(bookingCode && { bookingCode }), ...(bookingCode && { bookingCode }),
...(redemption && { isRedemption: "true" }), ...(redemption && { isRedemption: "true" }),
language: inputLang ?? lang, language: lang,
} }
metrics.selectedRoomAvailability.counter.add(1, input) metrics.selectedRoomAvailability.counter.add(1, input)

View File

@@ -198,16 +198,16 @@ export const protectedServerActionProcedure = serverActionProcedure.use(
// NOTE: This is actually safe to use, just the implementation could change // NOTE: This is actually safe to use, just the implementation could change
// in minor version bumps. Please read: https://trpc.io/docs/faq#unstable // in minor version bumps. Please read: https://trpc.io/docs/faq#unstable
export const contentStackUidWithServiceProcedure = export const contentStackUidWithServiceProcedure =
contentstackExtendedProcedureUID.unstable_concat(serviceProcedure) contentstackExtendedProcedureUID.concat(serviceProcedure)
export const contentStackBaseWithServiceProcedure = export const contentStackBaseWithServiceProcedure =
contentstackBaseProcedure.unstable_concat(serviceProcedure) contentstackBaseProcedure.concat(serviceProcedure)
export const contentStackBaseWithProtectedProcedure = export const contentStackBaseWithProtectedProcedure =
contentstackBaseProcedure.unstable_concat(protectedProcedure) contentstackBaseProcedure.concat(protectedProcedure)
export const safeProtectedServiceProcedure = export const safeProtectedServiceProcedure =
safeProtectedProcedure.unstable_concat(serviceProcedure) safeProtectedProcedure.concat(serviceProcedure)
export const languageProtectedProcedure = export const languageProtectedProcedure =
protectedProcedure.unstable_concat(languageProcedure) protectedProcedure.concat(languageProcedure)