diff --git a/apps/scandic-web/app/[lang]/(live)/(public)/hotelreservation/my-stay/page.tsx b/apps/scandic-web/app/[lang]/(live)/(public)/hotelreservation/my-stay/page.tsx
index 8aabd17fc..17be92f63 100644
--- a/apps/scandic-web/app/[lang]/(live)/(public)/hotelreservation/my-stay/page.tsx
+++ b/apps/scandic-web/app/[lang]/(live)/(public)/hotelreservation/my-stay/page.tsx
@@ -79,10 +79,20 @@ export default async function MyStay({
email
)
} else {
- return renderAdditionalInfoForm()
+ return (
+
+ )
}
} else {
- return renderAdditionalInfoForm()
+ return (
+
+ )
}
if (!bookingConfirmation) {
@@ -258,18 +268,24 @@ export default async function MyStay({
)
}
- function renderAdditionalInfoForm() {
- return (
-
-
-
- )
- }
-
return notFound()
}
+
+function RenderAdditionalInfoForm({
+ confirmationNumber,
+ lastName,
+}: {
+ confirmationNumber: string
+ lastName: string
+}) {
+ return (
+
+
+
+ )
+}
diff --git a/apps/scandic-web/app/[lang]/webview/hotelreservation/my-stay/page.tsx b/apps/scandic-web/app/[lang]/webview/hotelreservation/my-stay/page.tsx
index e083c1cde..c87a6a567 100644
--- a/apps/scandic-web/app/[lang]/webview/hotelreservation/my-stay/page.tsx
+++ b/apps/scandic-web/app/[lang]/webview/hotelreservation/my-stay/page.tsx
@@ -6,6 +6,7 @@ import { Typography } from "@scandic-hotels/design-system/Typography"
import { env } from "@/env/server"
import { dt } from "@/lib/dt"
import {
+ findBooking,
getAncillaryPackages,
getBookingConfirmation,
getLinkedReservations,
@@ -15,6 +16,7 @@ import {
} from "@/lib/trpc/memoizedRequests"
import { decrypt } from "@/server/routers/utils/encryption"
+import { auth } from "@/auth"
import AdditionalInfoForm from "@/components/HotelReservation/FindMyBooking/AdditionalInfoForm"
import accessBooking, {
ACCESS_GRANTED,
@@ -32,6 +34,7 @@ import Image from "@/components/Image"
import { getIntl } from "@/i18n"
import { setLang } from "@/i18n/serverContext"
import MyStayProvider from "@/providers/MyStay"
+import { isValidSession } from "@/utils/session"
import { getCurrentWebUrl } from "@/utils/url"
import styles from "./page.module.css"
@@ -54,9 +57,42 @@ export default async function MyStay({
if (!value) {
return notFound()
}
+ const session = await auth()
+ const isLoggedIn = isValidSession(session)
const [confirmationNumber, lastName] = value.split(",")
- const bookingConfirmation = await getBookingConfirmation(confirmationNumber)
+ const bv = cookies().get("bv")?.value
+ let bookingConfirmation
+ if (isLoggedIn) {
+ bookingConfirmation = await getBookingConfirmation(confirmationNumber)
+ } else if (bv) {
+ const params = new URLSearchParams(bv)
+ const firstName = params.get("firstName")
+ const email = params.get("email")
+
+ if (firstName && email) {
+ bookingConfirmation = await findBooking(
+ confirmationNumber,
+ lastName,
+ firstName,
+ email
+ )
+ } else {
+ return (
+
+ )
+ }
+ } else {
+ return (
+
+ )
+ }
if (!bookingConfirmation) {
return notFound()
}
@@ -64,7 +100,6 @@ export default async function MyStay({
const { additionalData, booking, hotel, roomCategories } = bookingConfirmation
const user = await getProfileSafely()
- const bv = cookies().get("bv")?.value
const intl = await getIntl()
const access = accessBooking(booking.guest, lastName, user, bv)
@@ -232,3 +267,22 @@ export default async function MyStay({
return notFound()
}
+
+function RenderAdditionalInfoForm({
+ confirmationNumber,
+ lastName,
+}: {
+ confirmationNumber: string
+ lastName: string
+}) {
+ return (
+
+
+
+ )
+}
diff --git a/apps/scandic-web/components/HotelReservation/MyStay/Receipt/index.tsx b/apps/scandic-web/components/HotelReservation/MyStay/Receipt/index.tsx
index b7f5923c3..420648db7 100644
--- a/apps/scandic-web/components/HotelReservation/MyStay/Receipt/index.tsx
+++ b/apps/scandic-web/components/HotelReservation/MyStay/Receipt/index.tsx
@@ -6,13 +6,16 @@ import { Typography } from "@scandic-hotels/design-system/Typography"
import { dt } from "@/lib/dt"
import {
+ findBooking,
getAncillaryPackages,
getBookingConfirmation,
getProfileSafely,
} from "@/lib/trpc/memoizedRequests"
import { decrypt } from "@/server/routers/utils/encryption"
+import { auth } from "@/auth"
import { getIntl } from "@/i18n"
+import { isValidSession } from "@/utils/session"
import AdditionalInfoForm from "../../FindMyBooking/AdditionalInfoForm"
import accessBooking, {
@@ -33,15 +36,48 @@ export async function Receipt({ refId }: { refId: string }) {
if (!value) {
return notFound()
}
+ const session = await auth()
+ const isLoggedIn = isValidSession(session)
+
const [confirmationNumber, lastName] = value.split(",")
- const bookingConfirmation = await getBookingConfirmation(confirmationNumber)
+ const bv = cookies().get("bv")?.value
+ let bookingConfirmation
+ if (isLoggedIn) {
+ bookingConfirmation = await getBookingConfirmation(confirmationNumber)
+ } else if (bv) {
+ const params = new URLSearchParams(bv)
+ const firstName = params.get("firstName")
+ const email = params.get("email")
+
+ if (firstName && email) {
+ bookingConfirmation = await findBooking(
+ confirmationNumber,
+ lastName,
+ firstName,
+ email
+ )
+ } else {
+ return (
+
+ )
+ }
+ } else {
+ return (
+
+ )
+ }
if (!bookingConfirmation) {
return notFound()
}
const { booking, hotel, room } = bookingConfirmation
const user = await getProfileSafely()
- const bv = cookies().get("bv")?.value
const intl = await getIntl()
const access = accessBooking(booking.guest, lastName, user, bv)
@@ -166,3 +202,22 @@ export async function Receipt({ refId }: { refId: string }) {
return notFound()
}
+
+function RenderAdditionalInfoForm({
+ confirmationNumber,
+ lastName,
+}: {
+ confirmationNumber: string
+ lastName: string
+}) {
+ return (
+
+
+
+ )
+}
diff --git a/apps/scandic-web/server/routers/booking/query.ts b/apps/scandic-web/server/routers/booking/query.ts
index 5ae8d3857..2c8a518d3 100644
--- a/apps/scandic-web/server/routers/booking/query.ts
+++ b/apps/scandic-web/server/routers/booking/query.ts
@@ -81,16 +81,7 @@ export const bookingQueryRouter = router({
}),
findBooking: safeProtectedServiceProcedure
.input(findBookingInput)
- .use(async ({ ctx, input, next }) => {
- const lang = input.lang ?? ctx.lang
- const token = ctx.session?.token.access_token ?? ctx.serviceToken
- return next({
- ctx: {
- lang,
- token,
- },
- })
- })
+
.query(async function ({
ctx,
input: { confirmationNumber, lastName, firstName, email },
@@ -99,10 +90,11 @@ export const bookingQueryRouter = router({
const metricsFindBooking = findBookingCounter.init({ confirmationNumber })
metricsFindBooking.start()
+
const booking = await findBooking(
confirmationNumber,
ctx.lang,
- ctx.token,
+ ctx.serviceToken,
lastName,
firstName,
email