Merged in fix/SW-2890-select-rate-not-updating (pull request #2190)
fix: select-rate didn't update results when switching back to a recent search SW-2890 * fix: select-rate didn't update results when switching back to a recent search Approved-by: Linus Flood
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
|
import { useSearchParams } from "next/navigation"
|
||||||
import { useIntl } from "react-intl"
|
import { useIntl } from "react-intl"
|
||||||
|
|
||||||
import { trpc } from "@/lib/trpc/client"
|
import { trpc } from "@/lib/trpc/client"
|
||||||
@@ -7,6 +8,7 @@ import { trpc } from "@/lib/trpc/client"
|
|||||||
import Alert from "@/components/TempDesignSystem/Alert"
|
import Alert from "@/components/TempDesignSystem/Alert"
|
||||||
import useLang from "@/hooks/useLang"
|
import useLang from "@/hooks/useLang"
|
||||||
import RatesProvider from "@/providers/RatesProvider"
|
import RatesProvider from "@/providers/RatesProvider"
|
||||||
|
import { convertSearchParamsToObj, searchParamsToRecord } from "@/utils/url"
|
||||||
|
|
||||||
import RateSummary from "./RateSummary"
|
import RateSummary from "./RateSummary"
|
||||||
import Rooms from "./Rooms"
|
import Rooms from "./Rooms"
|
||||||
@@ -15,16 +17,21 @@ import { RoomsContainerSkeleton } from "./RoomsContainerSkeleton"
|
|||||||
import styles from "./index.module.css"
|
import styles from "./index.module.css"
|
||||||
|
|
||||||
import type { RoomsContainerProps } from "@/types/components/hotelReservation/selectRate/roomsContainer"
|
import type { RoomsContainerProps } from "@/types/components/hotelReservation/selectRate/roomsContainer"
|
||||||
|
import type { SelectRateSearchParams } from "@/types/components/hotelReservation/selectRate/selectRate"
|
||||||
import { AlertTypeEnum } from "@/types/enums/alert"
|
import { AlertTypeEnum } from "@/types/enums/alert"
|
||||||
|
|
||||||
export function RoomsContainer({
|
export function RoomsContainer({
|
||||||
booking,
|
|
||||||
hotelType,
|
hotelType,
|
||||||
roomCategories,
|
roomCategories,
|
||||||
vat,
|
vat,
|
||||||
}: RoomsContainerProps) {
|
}: RoomsContainerProps) {
|
||||||
const lang = useLang()
|
const lang = useLang()
|
||||||
const intl = useIntl()
|
const intl = useIntl()
|
||||||
|
const searchParams = useSearchParams()
|
||||||
|
|
||||||
|
const booking = convertSearchParamsToObj<SelectRateSearchParams>(
|
||||||
|
searchParamsToRecord(searchParams)
|
||||||
|
)
|
||||||
|
|
||||||
const { data, isFetching, isError, error } =
|
const { data, isFetching, isError, error } =
|
||||||
trpc.hotel.availability.selectRate.rooms.useQuery(
|
trpc.hotel.availability.selectRate.rooms.useQuery(
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import HotelInfoCard from "@/components/HotelReservation/SelectRate/HotelInfoCar
|
|||||||
import { RoomsContainer } from "@/components/HotelReservation/SelectRate/RoomsContainer"
|
import { RoomsContainer } from "@/components/HotelReservation/SelectRate/RoomsContainer"
|
||||||
import { setLang } from "@/i18n/serverContext"
|
import { setLang } from "@/i18n/serverContext"
|
||||||
import { getHotelSearchDetails } from "@/utils/hotelSearchDetails"
|
import { getHotelSearchDetails } from "@/utils/hotelSearchDetails"
|
||||||
import { convertSearchParamsToObj } from "@/utils/url"
|
|
||||||
|
|
||||||
import FnFNotAllowedAlert from "../FnFNotAllowedAlert/FnFNotAllowedAlert"
|
import FnFNotAllowedAlert from "../FnFNotAllowedAlert/FnFNotAllowedAlert"
|
||||||
import AvailabilityError from "./AvailabilityError"
|
import AvailabilityError from "./AvailabilityError"
|
||||||
@@ -39,8 +38,6 @@ export default async function SelectRatePage({
|
|||||||
return notFound()
|
return notFound()
|
||||||
}
|
}
|
||||||
|
|
||||||
const booking = convertSearchParamsToObj<SelectRateSearchParams>(searchParams)
|
|
||||||
|
|
||||||
let isInValidFNF = false
|
let isInValidFNF = false
|
||||||
if (bookingCode && FamilyAndFriendsCodes.includes(bookingCode)) {
|
if (bookingCode && FamilyAndFriendsCodes.includes(bookingCode)) {
|
||||||
const cookieStore = cookies()
|
const cookieStore = cookies()
|
||||||
@@ -54,7 +51,6 @@ export default async function SelectRatePage({
|
|||||||
<FnFNotAllowedAlert />
|
<FnFNotAllowedAlert />
|
||||||
) : (
|
) : (
|
||||||
<RoomsContainer
|
<RoomsContainer
|
||||||
booking={booking}
|
|
||||||
hotelType={hotelData.hotel.hotelType}
|
hotelType={hotelData.hotel.hotelType}
|
||||||
roomCategories={hotelData.roomCategories}
|
roomCategories={hotelData.roomCategories}
|
||||||
vat={hotelData.hotel.vat}
|
vat={hotelData.hotel.vat}
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import { usePathname, useSearchParams } from "next/navigation"
|
import { usePathname, useSearchParams } from "next/navigation"
|
||||||
import { useRef } from "react"
|
import { useMemo } from "react"
|
||||||
import { useIntl } from "react-intl"
|
import { useIntl } from "react-intl"
|
||||||
|
|
||||||
import { createRatesStore } from "@/stores/select-rate"
|
import { createRatesStore } from "@/stores/select-rate"
|
||||||
|
|
||||||
import { RatesContext } from "@/contexts/Rates"
|
import { RatesContext } from "@/contexts/Rates"
|
||||||
|
|
||||||
import type { RatesStore } from "@/types/contexts/rates"
|
|
||||||
import type { RatesProviderProps } from "@/types/providers/rates"
|
import type { RatesProviderProps } from "@/types/providers/rates"
|
||||||
|
|
||||||
export default function RatesProvider({
|
export default function RatesProvider({
|
||||||
@@ -18,37 +18,43 @@ export default function RatesProvider({
|
|||||||
roomsAvailability,
|
roomsAvailability,
|
||||||
vat,
|
vat,
|
||||||
}: RatesProviderProps) {
|
}: RatesProviderProps) {
|
||||||
const storeRef = useRef<RatesStore>()
|
|
||||||
const pathname = usePathname()
|
const pathname = usePathname()
|
||||||
const searchParams = useSearchParams()
|
const searchParams = useSearchParams()
|
||||||
const intl = useIntl()
|
const intl = useIntl()
|
||||||
|
|
||||||
if (!storeRef.current) {
|
const store = useMemo(
|
||||||
storeRef.current = createRatesStore({
|
() =>
|
||||||
|
createRatesStore({
|
||||||
|
booking,
|
||||||
|
hotelType,
|
||||||
|
labels: {
|
||||||
|
accessibilityRoom: intl.formatMessage({
|
||||||
|
defaultMessage: "Accessible room",
|
||||||
|
}),
|
||||||
|
allergyRoom: intl.formatMessage({
|
||||||
|
defaultMessage: "Allergy-friendly room",
|
||||||
|
}),
|
||||||
|
petRoom: intl.formatMessage({
|
||||||
|
defaultMessage: "Pet-friendly room",
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
pathname,
|
||||||
|
roomCategories,
|
||||||
|
roomsAvailability,
|
||||||
|
searchParams: new URLSearchParams(searchParams),
|
||||||
|
vat,
|
||||||
|
}),
|
||||||
|
[
|
||||||
booking,
|
booking,
|
||||||
hotelType,
|
hotelType,
|
||||||
labels: {
|
intl,
|
||||||
accessibilityRoom: intl.formatMessage({
|
|
||||||
defaultMessage: "Accessible room",
|
|
||||||
}),
|
|
||||||
allergyRoom: intl.formatMessage({
|
|
||||||
defaultMessage: "Allergy-friendly room",
|
|
||||||
}),
|
|
||||||
petRoom: intl.formatMessage({
|
|
||||||
defaultMessage: "Pet-friendly room",
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
pathname,
|
pathname,
|
||||||
roomCategories,
|
roomCategories,
|
||||||
roomsAvailability,
|
roomsAvailability,
|
||||||
searchParams: new URLSearchParams(searchParams),
|
searchParams,
|
||||||
vat,
|
vat,
|
||||||
})
|
]
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<RatesContext.Provider value={storeRef.current}>
|
|
||||||
{children}
|
|
||||||
</RatesContext.Provider>
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
return <RatesContext.Provider value={store}>{children}</RatesContext.Provider>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
import type { HotelData } from "@/types/hotel"
|
import type { HotelData } from "@/types/hotel"
|
||||||
import type { SelectRateSearchParams } from "./selectRate"
|
|
||||||
|
|
||||||
export interface RoomsContainerProps
|
export interface RoomsContainerProps
|
||||||
extends Pick<HotelData, "roomCategories">,
|
extends Pick<HotelData, "roomCategories">,
|
||||||
Pick<HotelData["hotel"], "hotelType" | "vat"> {
|
Pick<HotelData["hotel"], "hotelType" | "vat"> {}
|
||||||
booking: SelectRateSearchParams
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user