Merged in revert-pr-1925 (pull request #1927)
Revert "Feat/sw 2323 find booking (pull request #1925)" Approved-by: Anton Gunnarsson
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
"use client"
|
||||
|
||||
import { notFound } from "next/navigation"
|
||||
import { use, useRef } from "react"
|
||||
import { useIntl } from "react-intl"
|
||||
|
||||
import { type RouterOutput, trpc } from "@/lib/trpc/client"
|
||||
import { trpc } from "@/lib/trpc/client"
|
||||
import { createMyStayStore } from "@/stores/my-stay"
|
||||
|
||||
import { MyStaySkeleton } from "@/components/HotelReservation/MyStay/myStaySkeleton"
|
||||
@@ -13,7 +12,10 @@ import { MyStayContext } from "@/contexts/MyStay"
|
||||
import type { Packages } from "@/types/components/myPages/myStay/ancillaries"
|
||||
import type { MyStayStore } from "@/types/contexts/my-stay"
|
||||
import type { RoomCategories } from "@/types/hotel"
|
||||
import type { BookingConfirmation } from "@/types/trpc/routers/booking/confirmation"
|
||||
import type {
|
||||
BookingConfirmation,
|
||||
BookingConfirmationSchema,
|
||||
} from "@/types/trpc/routers/booking/confirmation"
|
||||
import type { CreditCard } from "@/types/user"
|
||||
import type { Lang } from "@/constants/languages"
|
||||
|
||||
@@ -21,9 +23,7 @@ interface MyStayProviderProps {
|
||||
bookingConfirmation: BookingConfirmation
|
||||
breakfastPackages: Packages | null
|
||||
lang: Lang
|
||||
linkedReservationsPromise: Promise<
|
||||
RouterOutput["booking"]["linkedReservations"]
|
||||
>
|
||||
linkedReservationsPromise: Promise<BookingConfirmationSchema[]>
|
||||
refId: string
|
||||
roomCategories: RoomCategories
|
||||
savedCreditCards: CreditCard[] | null
|
||||
@@ -39,14 +39,13 @@ export default function MyStayProvider({
|
||||
roomCategories,
|
||||
savedCreditCards,
|
||||
}: React.PropsWithChildren<MyStayProviderProps>) {
|
||||
const storeRef = useRef<MyStayStore>()
|
||||
const intl = useIntl()
|
||||
|
||||
const storeRef = useRef<MyStayStore>()
|
||||
|
||||
const { data, error, isFetching, isFetchedAfterMount } =
|
||||
trpc.booking.confirmation.useQuery(
|
||||
trpc.booking.get.useQuery(
|
||||
{
|
||||
refId,
|
||||
confirmationNumber: bookingConfirmation.booking.confirmationNumber,
|
||||
lang,
|
||||
},
|
||||
{
|
||||
@@ -69,7 +68,7 @@ export default function MyStayProvider({
|
||||
} = trpc.booking.linkedReservations.useQuery(
|
||||
{
|
||||
lang,
|
||||
refId,
|
||||
rooms: bookingConfirmation.booking.linkedReservations,
|
||||
},
|
||||
{
|
||||
initialData: linkedReservationsResponses,
|
||||
@@ -86,16 +85,15 @@ export default function MyStayProvider({
|
||||
return notFound()
|
||||
}
|
||||
|
||||
const rooms = [data.booking].concat(linkedReservations ?? [])
|
||||
const rooms = [data.booking, ...linkedReservations]
|
||||
|
||||
const hasInvalidatedQueryAndRefetched =
|
||||
(isFetchedAfterMount && data) ||
|
||||
(linkedReservationsIsFetchedAfterMount && linkedReservations)
|
||||
|
||||
if (!storeRef.current || hasInvalidatedQueryAndRefetched) {
|
||||
storeRef.current = createMyStayStore({
|
||||
breakfastPackages,
|
||||
hotel: bookingConfirmation.hotelData.hotel,
|
||||
hotel: bookingConfirmation.hotel,
|
||||
intl,
|
||||
refId,
|
||||
roomCategories,
|
||||
|
||||
Reference in New Issue
Block a user