diff --git a/apps/scandic-web/components/HotelReservation/BookingConfirmation/Rooms/LinkedReservation/index.tsx b/apps/scandic-web/components/HotelReservation/BookingConfirmation/Rooms/LinkedReservation/index.tsx index 1b76ff457..40e6e2104 100644 --- a/apps/scandic-web/components/HotelReservation/BookingConfirmation/Rooms/LinkedReservation/index.tsx +++ b/apps/scandic-web/components/HotelReservation/BookingConfirmation/Rooms/LinkedReservation/index.tsx @@ -78,14 +78,19 @@ export function LinkedReservation({ if (!data?.room) { return } - + const { booking, room } = data return ( ) } diff --git a/apps/scandic-web/components/HotelReservation/BookingConfirmation/Rooms/Room/index.tsx b/apps/scandic-web/components/HotelReservation/BookingConfirmation/Rooms/Room/index.tsx index 33d20db5e..263b82929 100644 --- a/apps/scandic-web/components/HotelReservation/BookingConfirmation/Rooms/Room/index.tsx +++ b/apps/scandic-web/components/HotelReservation/BookingConfirmation/Rooms/Room/index.tsx @@ -20,24 +20,28 @@ import styles from "./room.module.css" import type { RoomProps } from "@/types/components/hotelReservation/bookingConfirmation/rooms/room" export default function Room({ - booking, + checkInDate, + checkOutDate, checkInTime, checkOutTime, + confirmationNumber, + guaranteeInfo, + guest, img, + rateDefinition, roomName, }: RoomProps) { const intl = useIntl() const lang = useLang() - const guestName = `${booking.guest.firstName} ${booking.guest.lastName}` - const fromDate = dt(booking.checkInDate).locale(lang) - const toDate = dt(booking.checkOutDate).locale(lang) - + const guestName = `${guest.firstName} ${guest.lastName}` + const fromDate = dt(checkInDate).locale(lang) + const toDate = dt(checkOutDate).locale(lang) const isFlexBooking = - booking.rateDefinition.cancellationRule === + rateDefinition.cancellationRule === CancellationRuleEnum.CancellableBefore6PM const isChangeBooking = - booking.rateDefinition.cancellationRule === CancellationRuleEnum.Changeable + rateDefinition.cancellationRule === CancellationRuleEnum.Changeable return (
@@ -47,11 +51,11 @@ export default function Room({ { defaultMessage: "Booking number {value}", }, - { value: booking.confirmationNumber } + { value: confirmationNumber } )} - {booking.rateDefinition.isMemberRate ? ( + {rateDefinition.isMemberRate ? (
<>
) : null} - {booking.guaranteeInfo && ( + {guaranteeInfo && (
- {booking.rateDefinition.cancellationText} + {rateDefinition.cancellationText} {isFlexBooking || isChangeBooking ? ( @@ -196,25 +200,23 @@ export default function Room({ })} {guestName} - {booking.guest.membershipNumber ? ( + {guest.membershipNumber ? ( {intl.formatMessage( { defaultMessage: "Friend no. {value}", }, { - value: booking.guest.membershipNumber, + value: guest.membershipNumber, } )} ) : null} - {booking.guest.phoneNumber ? ( - - {booking.guest.phoneNumber} - + {guest.phoneNumber ? ( + {guest.phoneNumber} ) : null} - {booking.guest.email ? ( - {booking.guest.email} + {guest.email ? ( + {guest.email} ) : null}
diff --git a/apps/scandic-web/components/HotelReservation/BookingConfirmation/Rooms/index.tsx b/apps/scandic-web/components/HotelReservation/BookingConfirmation/Rooms/index.tsx index 32dec7c98..991d62212 100644 --- a/apps/scandic-web/components/HotelReservation/BookingConfirmation/Rooms/index.tsx +++ b/apps/scandic-web/components/HotelReservation/BookingConfirmation/Rooms/index.tsx @@ -34,10 +34,15 @@ export default async function Rooms({ ) : null} diff --git a/apps/scandic-web/components/HotelReservation/BookingConfirmation/index.tsx b/apps/scandic-web/components/HotelReservation/BookingConfirmation/index.tsx index 91f39fb4f..8be66fd31 100644 --- a/apps/scandic-web/components/HotelReservation/BookingConfirmation/index.tsx +++ b/apps/scandic-web/components/HotelReservation/BookingConfirmation/index.tsx @@ -1,7 +1,6 @@ import { notFound } from "next/navigation" import { getBookingConfirmation } from "@/lib/trpc/memoizedRequests" -import { encrypt } from "@/server/routers/utils/encryption" import HotelDetails from "@/components/HotelReservation/BookingConfirmation/HotelDetails" import PaymentDetails from "@/components/HotelReservation/BookingConfirmation/PaymentDetails" @@ -12,6 +11,7 @@ import SidePanel from "@/components/HotelReservation/SidePanel" import Divider from "@/components/TempDesignSystem/Divider" import { getIntl } from "@/i18n" import BookingConfirmationProvider from "@/providers/BookingConfirmationProvider" +import { encrypt } from "@/utils/encryption" import Alerts from "./Alerts" import Confirmation from "./Confirmation" @@ -66,11 +66,7 @@ export default async function BookingConfirmation({ - +
diff --git a/apps/scandic-web/components/HotelReservation/MyStay/Receipt/index.tsx b/apps/scandic-web/components/HotelReservation/MyStay/Receipt/index.tsx index b7f5923c3..70e17a294 100644 --- a/apps/scandic-web/components/HotelReservation/MyStay/Receipt/index.tsx +++ b/apps/scandic-web/components/HotelReservation/MyStay/Receipt/index.tsx @@ -10,9 +10,9 @@ import { getBookingConfirmation, getProfileSafely, } from "@/lib/trpc/memoizedRequests" -import { decrypt } from "@/server/routers/utils/encryption" import { getIntl } from "@/i18n" +import { decrypt } from "@/utils/encryption" import AdditionalInfoForm from "../../FindMyBooking/AdditionalInfoForm" import accessBooking, { @@ -132,6 +132,7 @@ export async function Receipt({ refId }: { refId: string }) {
diff --git a/apps/scandic-web/server/routers/booking/query.ts b/apps/scandic-web/server/routers/booking/query.ts index 280a49769..76067970c 100644 --- a/apps/scandic-web/server/routers/booking/query.ts +++ b/apps/scandic-web/server/routers/booking/query.ts @@ -7,8 +7,9 @@ import { serviceProcedure, } from "@/server/trpc" +import { calculateRefId } from "@/utils/refId" + import { getHotel } from "../hotels/utils" -import { encrypt } from "../utils/encryption" import { createRefIdInput, getBookingInput, @@ -169,7 +170,7 @@ export const bookingQueryRouter = router({ .input(createRefIdInput) .mutation(async function ({ input }) { const { confirmationNumber, lastName } = input - const encryptedRefId = encrypt(`${confirmationNumber},${lastName}`) + const encryptedRefId = calculateRefId(confirmationNumber, lastName) if (!encryptedRefId) { throw serverErrorByStatus(422, "Was not able to encrypt ref id") diff --git a/apps/scandic-web/server/routers/user/utils.ts b/apps/scandic-web/server/routers/user/utils.ts index d0eafd976..fc0b67468 100644 --- a/apps/scandic-web/server/routers/user/utils.ts +++ b/apps/scandic-web/server/routers/user/utils.ts @@ -4,10 +4,10 @@ import { myStay } from "@/constants/routes/myStay" import { env } from "@/env/server" import * as api from "@/lib/api" import { dt } from "@/lib/dt" -import { encrypt } from "@/server/routers/utils/encryption" import { createCounter } from "@/server/telemetry" import { cache } from "@/utils/cache" +import { encrypt } from "@/utils/encryption" import * as maskValue from "@/utils/maskValue" import { isValidSession } from "@/utils/session" import { getCurrentWebUrl } from "@/utils/url" diff --git a/apps/scandic-web/types/components/hotelReservation/bookingConfirmation/promos.ts b/apps/scandic-web/types/components/hotelReservation/bookingConfirmation/promos.ts index 2d786d63c..5fef57ef7 100644 --- a/apps/scandic-web/types/components/hotelReservation/bookingConfirmation/promos.ts +++ b/apps/scandic-web/types/components/hotelReservation/bookingConfirmation/promos.ts @@ -1,8 +1,4 @@ -import type { BookingConfirmation } from "@/types/trpc/routers/booking/confirmation" - -export interface PromosProps - extends Pick< - BookingConfirmation["booking"], - "confirmationNumber" | "hotelId" - >, - Pick {} +export interface PromosProps { + hotelId: string + refId: string +} diff --git a/apps/scandic-web/types/components/hotelReservation/bookingConfirmation/rooms/room.ts b/apps/scandic-web/types/components/hotelReservation/bookingConfirmation/rooms/room.ts index bc2ce6b9a..21baa038a 100644 --- a/apps/scandic-web/types/components/hotelReservation/bookingConfirmation/rooms/room.ts +++ b/apps/scandic-web/types/components/hotelReservation/bookingConfirmation/rooms/room.ts @@ -1,9 +1,14 @@ import type { BookingConfirmation } from "@/types/trpc/routers/booking/confirmation" export interface RoomProps { - booking: BookingConfirmation["booking"] + checkInDate: BookingConfirmation["booking"]["checkInDate"] + checkOutDate: BookingConfirmation["booking"]["checkOutDate"] checkInTime: string checkOutTime: string + confirmationNumber: string + guest: BookingConfirmation["booking"]["guest"] + guaranteeInfo: BookingConfirmation["booking"]["guaranteeInfo"] img: NonNullable["images"][number] + rateDefinition: BookingConfirmation["booking"]["rateDefinition"] roomName: NonNullable["name"] } diff --git a/apps/scandic-web/server/routers/utils/encryption.ts b/apps/scandic-web/utils/encryption.ts similarity index 100% rename from apps/scandic-web/server/routers/utils/encryption.ts rename to apps/scandic-web/utils/encryption.ts diff --git a/apps/scandic-web/utils/refId.ts b/apps/scandic-web/utils/refId.ts new file mode 100644 index 000000000..95a0aef05 --- /dev/null +++ b/apps/scandic-web/utils/refId.ts @@ -0,0 +1,21 @@ +import "server-only" + +import { decrypt, encrypt } from "./encryption" + +export function calculateRefId(confirmationNumber: string, lastName: string) { + const encryptedRefId = encrypt(`${confirmationNumber},${lastName}`) + + return encryptedRefId +} + +export function parseRefId(refId: string) { + const data = decrypt(refId) + const parts = data.split(",") + if (parts.length !== 2) { + throw new Error("Invalid refId format") + } + return { + confirmationNumber: parts[0], + lastName: parts[1], + } +}