Merged in feature/SW-3516-pass-eurobonus-number-on-booking (pull request #2902)
* feat(SW-3516): Include partnerLoyaltyNumber on bookings - Added user context to BookingFlowProviders for user state management. - Updated booking input and output schemas to accommodate new user data. - Refactored booking mutation logic to include user-related information. - Improved type definitions for better TypeScript support across booking components. Approved-by: Anton Gunnarsson
This commit is contained in:
@@ -1,17 +1,50 @@
|
||||
"use client"
|
||||
|
||||
import { BookingFlowContextProvider } from "@scandic-hotels/booking-flow/BookingFlowContextProvider"
|
||||
import { trpc } from "@scandic-hotels/trpc/client"
|
||||
|
||||
import { useIsUserLoggedIn } from "@/hooks/useIsUserLoggedIn"
|
||||
|
||||
import type { ReactNode } from "react"
|
||||
import type { ComponentProps, ReactNode } from "react"
|
||||
|
||||
export function BookingFlowProviders({ children }: { children: ReactNode }) {
|
||||
const isLoggedIn = useIsUserLoggedIn()
|
||||
const user = useBookingFlowUser()
|
||||
|
||||
return (
|
||||
<BookingFlowContextProvider data={{ isLoggedIn }}>
|
||||
<BookingFlowContextProvider data={{ isLoggedIn, user }}>
|
||||
{children}
|
||||
</BookingFlowContextProvider>
|
||||
)
|
||||
}
|
||||
|
||||
type BookingFlowContextData = ComponentProps<
|
||||
typeof BookingFlowContextProvider
|
||||
>["data"]
|
||||
type BookingFlowUser = BookingFlowContextData["user"]
|
||||
|
||||
function useBookingFlowUser(): BookingFlowUser {
|
||||
const isLoggedIn = useIsUserLoggedIn()
|
||||
const { data, isError, isLoading } = trpc.user.getSafely.useQuery(undefined, {
|
||||
enabled: isLoggedIn,
|
||||
})
|
||||
|
||||
if (isLoading) {
|
||||
return { state: "loading", data: undefined }
|
||||
}
|
||||
if (isError || !data) {
|
||||
return { state: "error", data: undefined }
|
||||
}
|
||||
|
||||
return {
|
||||
state: "loaded",
|
||||
data: {
|
||||
type: "scandic",
|
||||
partnerLoyaltyNumber: null,
|
||||
membershipNumber: data.membershipNumber,
|
||||
firstName: data.firstName || null,
|
||||
lastName: data.lastName || null,
|
||||
email: data.email,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ export async function createAppContext() {
|
||||
const loginType = headersList.get("loginType")
|
||||
|
||||
const ctx = createContext({
|
||||
app: "scandic-web",
|
||||
lang: headersList.get("x-lang") as Lang,
|
||||
pathname: headersList.get("x-pathname")!,
|
||||
uid: headersList.get("x-uid"),
|
||||
|
||||
Reference in New Issue
Block a user