Merged in feat/sw-2879-booking-widget-to-booking-flow-package (pull request #2532)
feat(SW-2879): Move BookingWidget to booking-flow package * Fix lockfile * Fix styling * a tiny little booking widget test * Tiny fixes * Merge branch 'master' into feat/sw-2879-booking-widget-to-booking-flow-package * Remove unused scripts * lint:fix * Merge branch 'master' into feat/sw-2879-booking-widget-to-booking-flow-package * Tiny lint fixes * update test * Update Input in booking-flow * Clean up comments etc * Merge branch 'master' into feat/sw-2879-booking-widget-to-booking-flow-package * Setup tracking context for booking-flow * Add missing use client * Fix temp tracking function * Pass booking to booking-widget * Remove comment * Add use client to booking widget tracking provider * Add use client to tracking functions * Merge branch 'master' into feat/sw-2879-booking-widget-to-booking-flow-package * Move debug page * Merge branch 'master' into feat/sw-2879-booking-widget-to-booking-flow-package * Merge branch 'master' into feat/sw-2879-booking-widget-to-booking-flow-package * Merge branch 'master' into feat/sw-2879-booking-widget-to-booking-flow-package Approved-by: Bianca Widstam
This commit is contained in:
73
packages/booking-flow/lib/components/BookingWidget/index.tsx
Normal file
73
packages/booking-flow/lib/components/BookingWidget/index.tsx
Normal file
@@ -0,0 +1,73 @@
|
||||
import { Suspense } from "react"
|
||||
|
||||
import {
|
||||
getPageSettingsBookingCode,
|
||||
isBookingWidgetHidden,
|
||||
} from "../../trpc/memoizedRequests"
|
||||
import BookingWidgetClient from "./Client"
|
||||
import { BookingWidgetSkeleton } from "./Skeleton"
|
||||
|
||||
import type { Lang } from "@scandic-hotels/common/constants/language"
|
||||
import type { Child } from "@scandic-hotels/trpc/types/child"
|
||||
import type { VariantProps } from "class-variance-authority"
|
||||
|
||||
import type { BookingSearchType } from "../../misc/searchType"
|
||||
import type { bookingWidgetVariants } from "./BookingWidgetForm/variants"
|
||||
|
||||
export type GuestsRoom = {
|
||||
adults: number
|
||||
childrenInRoom: Child[]
|
||||
}
|
||||
|
||||
export type BookingWidgetSearchData = {
|
||||
city?: string
|
||||
hotelId?: string
|
||||
fromDate?: string
|
||||
toDate?: string
|
||||
rooms?: GuestsRoom[]
|
||||
bookingCode?: string
|
||||
searchType?: BookingSearchType
|
||||
}
|
||||
|
||||
export type BookingWidgetType = VariantProps<
|
||||
typeof bookingWidgetVariants
|
||||
>["type"]
|
||||
|
||||
export type BookingWidgetProps = {
|
||||
type?: BookingWidgetType
|
||||
booking: BookingWidgetSearchData
|
||||
lang: Lang
|
||||
}
|
||||
|
||||
export async function BookingWidget(props: BookingWidgetProps) {
|
||||
return (
|
||||
<Suspense fallback={<BookingWidgetSkeleton />}>
|
||||
<InternalBookingWidget {...props} />
|
||||
</Suspense>
|
||||
)
|
||||
}
|
||||
|
||||
async function InternalBookingWidget({
|
||||
lang,
|
||||
type,
|
||||
booking,
|
||||
}: BookingWidgetProps) {
|
||||
const isHidden = await isBookingWidgetHidden(lang)
|
||||
|
||||
if (isHidden) {
|
||||
return null
|
||||
}
|
||||
|
||||
let pageSettingsBookingCodePromise: Promise<string> | null = null
|
||||
if (!booking.bookingCode) {
|
||||
pageSettingsBookingCodePromise = getPageSettingsBookingCode(lang)
|
||||
}
|
||||
|
||||
return (
|
||||
<BookingWidgetClient
|
||||
type={type}
|
||||
data={booking}
|
||||
pageSettingsBookingCodePromise={pageSettingsBookingCodePromise}
|
||||
/>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user