Feat/SW-1737 design mystay multiroom * feat(SW-1737) Fixed member view of guest details * feat(SW-1737) fix merge issues * feat(SW-1737) Fixed price details * feat(SW-1737) removed unused imports * feat(SW-1737) removed true as statement * feat(SW-1737) updated store handling * feat(SW-1737) fixed bug showing double numbers * feat(SW-1737) small design fixed * feat(SW-1737) fixed rebase errors * feat(SW-1737) fixed create booking error with dates * feat(SW-1737) fixed view multiroom as singleroom * feat(SW-1737) fixes for multiroom * feat(SW-1737) fixed bookingsummary * feat(SW-1737) dont hide modify dates * feat(SW-1737) updated breakfast to handle number * feat(SW-1737) Added red color if member rate * feat(SW-1737) fix PR comments * feat(SW-1737) updated member tiers svg * feat(SW-1737) updated how to handle paymentMethodDescription * feat(SW-1737) fixes after testing mystay * feat(SW-1737) updated Room type to just use whats used * feat(SW-1737) fixed access * feat(SW-1737) refactor my stay after PR comments * feat(SW-1737) fix roomNumber translation * feat(SW-1737) removed log Approved-by: Arvid Norlin
150 lines
4.4 KiB
TypeScript
150 lines
4.4 KiB
TypeScript
import { cookies } from "next/headers"
|
|
import { notFound } from "next/navigation"
|
|
|
|
import { homeHrefs } from "@/constants/homeHrefs"
|
|
import { env } from "@/env/server"
|
|
import { dt } from "@/lib/dt"
|
|
import {
|
|
getAncillaryPackages,
|
|
getBookingConfirmation,
|
|
getProfileSafely,
|
|
getSavedPaymentCardsSafely,
|
|
} from "@/lib/trpc/memoizedRequests"
|
|
import { decrypt } from "@/server/routers/utils/encryption"
|
|
|
|
import Image from "@/components/Image"
|
|
import Body from "@/components/TempDesignSystem/Text/Body"
|
|
import { getIntl } from "@/i18n"
|
|
import { getLang } from "@/i18n/serverContext"
|
|
|
|
import AdditionalInfoForm from "../FindMyBooking/AdditionalInfoForm"
|
|
import accessBooking, {
|
|
ACCESS_GRANTED,
|
|
ERROR_BAD_REQUEST,
|
|
ERROR_UNAUTHORIZED,
|
|
} from "./accessBooking"
|
|
import { Ancillaries } from "./Ancillaries"
|
|
import BookingSummary from "./BookingSummary"
|
|
import { Header } from "./Header"
|
|
import Promo from "./Promo"
|
|
import { ReferenceCard } from "./ReferenceCard"
|
|
import Rooms from "./Rooms"
|
|
|
|
import styles from "./myStay.module.css"
|
|
|
|
export async function MyStay({ refId }: { refId: string }) {
|
|
const value = decrypt(refId)
|
|
if (!value) {
|
|
return notFound()
|
|
}
|
|
const [confirmationNumber, lastName] = value.split(",")
|
|
const bookingConfirmation = await getBookingConfirmation(confirmationNumber)
|
|
if (!bookingConfirmation) {
|
|
return notFound()
|
|
}
|
|
|
|
const { booking, hotel, additionalData, room } = bookingConfirmation
|
|
const user = await getProfileSafely()
|
|
const bv = cookies().get("bv")?.value
|
|
const intl = await getIntl()
|
|
|
|
const access = accessBooking(booking.guest, lastName, user, bv)
|
|
if (access === ACCESS_GRANTED) {
|
|
const lang = getLang()
|
|
const ancillaryPackages = await getAncillaryPackages({
|
|
fromDate: dt(booking.checkInDate).format("YYYY-MM-DD"),
|
|
hotelId: hotel.operaId,
|
|
toDate: dt(booking.checkOutDate).format("YYYY-MM-DD"),
|
|
})
|
|
const supportedCards = hotel.merchantInformationData.cards
|
|
const savedCreditCards = await getSavedPaymentCardsSafely({
|
|
supportedCards,
|
|
})
|
|
|
|
const imageSrc =
|
|
hotel.hotelContent.images.imageSizes.large ??
|
|
additionalData.gallery?.heroImages[0]?.imageSizes.large ??
|
|
hotel.galleryImages[0]?.imageSizes.large
|
|
|
|
return (
|
|
<main className={styles.main}>
|
|
<div className={styles.imageContainer}>
|
|
<div className={styles.blurOverlay} />
|
|
{imageSrc && (
|
|
<Image
|
|
className={styles.image}
|
|
src={imageSrc}
|
|
alt={hotel.name}
|
|
fill
|
|
/>
|
|
)}
|
|
</div>
|
|
<div className={styles.content}>
|
|
<div className={styles.headerContainer}>
|
|
<Header hotel={hotel} />
|
|
<ReferenceCard
|
|
booking={booking}
|
|
hotel={hotel}
|
|
savedCreditCards={savedCreditCards}
|
|
refId={refId}
|
|
room={room}
|
|
isLoggedIn={!!user}
|
|
/>
|
|
</div>
|
|
{booking.showAncillaries && (
|
|
<Ancillaries
|
|
ancillaries={ancillaryPackages}
|
|
booking={booking}
|
|
user={user}
|
|
savedCreditCards={savedCreditCards}
|
|
refId={refId}
|
|
/>
|
|
)}
|
|
|
|
<Rooms booking={booking} room={room} hotel={hotel} user={user} />
|
|
|
|
<BookingSummary hotel={hotel} />
|
|
<Promo
|
|
title={intl.formatMessage({ id: "Book your next stay" })}
|
|
text={intl.formatMessage({
|
|
id: "Get inspired and start dreaming beyond your next trip. Explore more Scandic destinations.",
|
|
})}
|
|
buttonText={intl.formatMessage({ id: "Explore Scandic hotels" })}
|
|
href={`${homeHrefs[env.NODE_ENV][lang]}?hotel=${hotel.operaId}`}
|
|
image={hotel.hotelContent.images}
|
|
/>
|
|
</div>
|
|
</main>
|
|
)
|
|
}
|
|
|
|
if (access === ERROR_BAD_REQUEST) {
|
|
return (
|
|
<main className={styles.main}>
|
|
<div className={styles.form}>
|
|
<AdditionalInfoForm
|
|
confirmationNumber={confirmationNumber}
|
|
lastName={lastName}
|
|
/>
|
|
</div>
|
|
</main>
|
|
)
|
|
}
|
|
|
|
if (access === ERROR_UNAUTHORIZED) {
|
|
return (
|
|
<main className={styles.main}>
|
|
<div className={styles.logIn}>
|
|
<Body textAlign="center">
|
|
{intl.formatMessage({
|
|
id: "In order to view your booking, please log in.",
|
|
})}
|
|
</Body>
|
|
</div>
|
|
</main>
|
|
)
|
|
}
|
|
|
|
return notFound()
|
|
}
|