fix: make sure all searchparams are used in redirect
This commit is contained in:
committed by
Simon.Emanuelsson
parent
1b3999a050
commit
744af22b08
@@ -83,10 +83,10 @@ export default async function SummaryPage({
|
|||||||
price: availability.publicRate.localPrice.pricePerStay,
|
price: availability.publicRate.localPrice.pricePerStay,
|
||||||
currency: availability.publicRate.localPrice.currency,
|
currency: availability.publicRate.localPrice.currency,
|
||||||
},
|
},
|
||||||
euro: availability.publicRate.requestedPrice
|
euro: availability.publicRate?.requestedPrice
|
||||||
? {
|
? {
|
||||||
price: availability.publicRate.requestedPrice.pricePerStay,
|
price: availability.publicRate?.requestedPrice.pricePerStay,
|
||||||
currency: availability.publicRate.requestedPrice.currency,
|
currency: availability.publicRate?.requestedPrice.currency,
|
||||||
}
|
}
|
||||||
: undefined,
|
: undefined,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import "./enterDetailsLayout.css"
|
import "./enterDetailsLayout.css"
|
||||||
|
|
||||||
import { notFound, redirect, RedirectType } from "next/navigation"
|
import { notFound } from "next/navigation"
|
||||||
|
|
||||||
import {
|
import {
|
||||||
getBreakfastPackages,
|
getBreakfastPackages,
|
||||||
@@ -38,6 +38,8 @@ export default async function StepPage({
|
|||||||
}: PageArgs<LangParams, SelectRateSearchParams & { step: StepEnum }>) {
|
}: PageArgs<LangParams, SelectRateSearchParams & { step: StepEnum }>) {
|
||||||
const intl = await getIntl()
|
const intl = await getIntl()
|
||||||
const selectRoomParams = new URLSearchParams(searchParams)
|
const selectRoomParams = new URLSearchParams(searchParams)
|
||||||
|
selectRoomParams.delete("step")
|
||||||
|
const searchParamsString = selectRoomParams.toString()
|
||||||
const {
|
const {
|
||||||
hotel: hotelId,
|
hotel: hotelId,
|
||||||
rooms,
|
rooms,
|
||||||
@@ -123,6 +125,7 @@ export default async function StepPage({
|
|||||||
bedTypes={roomAvailability.bedTypes}
|
bedTypes={roomAvailability.bedTypes}
|
||||||
breakfastPackages={breakfastPackages}
|
breakfastPackages={breakfastPackages}
|
||||||
isMember={!!user}
|
isMember={!!user}
|
||||||
|
searchParams={searchParamsString}
|
||||||
step={searchParams.step}
|
step={searchParams.step}
|
||||||
>
|
>
|
||||||
<section>
|
<section>
|
||||||
|
|||||||
@@ -81,7 +81,6 @@ export default function Summary({ showMemberPrice, room }: SummaryProps) {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setChosenBed(bedType)
|
setChosenBed(bedType)
|
||||||
setChosenBreakfast(breakfast)
|
|
||||||
|
|
||||||
if (breakfast || breakfast === false) {
|
if (breakfast || breakfast === false) {
|
||||||
setChosenBreakfast(breakfast)
|
setChosenBreakfast(breakfast)
|
||||||
@@ -94,9 +93,9 @@ export default function Summary({ showMemberPrice, room }: SummaryProps) {
|
|||||||
euro:
|
euro:
|
||||||
room.euroPrice && roomsPriceEuro
|
room.euroPrice && roomsPriceEuro
|
||||||
? {
|
? {
|
||||||
price: roomsPriceEuro,
|
price: roomsPriceEuro,
|
||||||
currency: room.euroPrice.currency,
|
currency: room.euroPrice.currency,
|
||||||
}
|
}
|
||||||
: undefined,
|
: undefined,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
@@ -108,11 +107,11 @@ export default function Summary({ showMemberPrice, room }: SummaryProps) {
|
|||||||
euro:
|
euro:
|
||||||
room.euroPrice && roomsPriceEuro
|
room.euroPrice && roomsPriceEuro
|
||||||
? {
|
? {
|
||||||
price:
|
price:
|
||||||
roomsPriceEuro +
|
roomsPriceEuro +
|
||||||
parseInt(breakfast.requestedPrice.totalPrice),
|
parseInt(breakfast.requestedPrice.totalPrice),
|
||||||
currency: room.euroPrice.currency,
|
currency: room.euroPrice.currency,
|
||||||
}
|
}
|
||||||
: undefined,
|
: undefined,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -199,24 +198,24 @@ export default function Summary({ showMemberPrice, room }: SummaryProps) {
|
|||||||
</div>
|
</div>
|
||||||
{room.packages
|
{room.packages
|
||||||
? room.packages.map((roomPackage) => (
|
? room.packages.map((roomPackage) => (
|
||||||
<div className={styles.entry} key={roomPackage.code}>
|
<div className={styles.entry} key={roomPackage.code}>
|
||||||
<div>
|
<div>
|
||||||
<Body color="uiTextHighContrast">
|
<Body color="uiTextHighContrast">
|
||||||
{roomPackage.description}
|
{roomPackage.description}
|
||||||
</Body>
|
</Body>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Caption color="uiTextHighContrast">
|
<Caption color="uiTextHighContrast">
|
||||||
{intl.formatMessage(
|
{intl.formatMessage(
|
||||||
{ id: "{amount} {currency}" },
|
{ id: "{amount} {currency}" },
|
||||||
{
|
{
|
||||||
amount: roomPackage.localPrice.price,
|
amount: roomPackage.localPrice.price,
|
||||||
currency: roomPackage.localPrice.currency,
|
currency: roomPackage.localPrice.currency,
|
||||||
}
|
}
|
||||||
)}
|
)}
|
||||||
</Caption>
|
</Caption>
|
||||||
</div>
|
</div>
|
||||||
))
|
))
|
||||||
: null}
|
: null}
|
||||||
{chosenBed ? (
|
{chosenBed ? (
|
||||||
<div className={styles.entry}>
|
<div className={styles.entry}>
|
||||||
@@ -263,9 +262,8 @@ export default function Summary({ showMemberPrice, room }: SummaryProps) {
|
|||||||
)}
|
)}
|
||||||
</Caption>
|
</Caption>
|
||||||
</div>
|
</div>
|
||||||
) : null
|
) : null}
|
||||||
}
|
</div>
|
||||||
</div >
|
|
||||||
<Divider color="primaryLightSubtle" />
|
<Divider color="primaryLightSubtle" />
|
||||||
<div className={styles.total}>
|
<div className={styles.total}>
|
||||||
<div className={styles.entry}>
|
<div className={styles.entry}>
|
||||||
@@ -306,6 +304,6 @@ export default function Summary({ showMemberPrice, room }: SummaryProps) {
|
|||||||
</div>
|
</div>
|
||||||
<Divider className={styles.bottomDivider} color="primaryLightSubtle" />
|
<Divider className={styles.bottomDivider} color="primaryLightSubtle" />
|
||||||
</div>
|
</div>
|
||||||
</section >
|
</section>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,10 @@ export function filterDuplicateRoomTypesByLowestPrice(
|
|||||||
|
|
||||||
products.forEach((product) => {
|
products.forEach((product) => {
|
||||||
const { productType } = product
|
const { productType } = product
|
||||||
const publicProduct = productType.public
|
const publicProduct = productType.public || {
|
||||||
|
requestedPrice: null,
|
||||||
|
localPrice: null,
|
||||||
|
}
|
||||||
const memberProduct = productType.member || {
|
const memberProduct = productType.member || {
|
||||||
requestedPrice: null,
|
requestedPrice: null,
|
||||||
localPrice: null,
|
localPrice: null,
|
||||||
@@ -53,7 +56,7 @@ export function filterDuplicateRoomTypesByLowestPrice(
|
|||||||
Number(memberRequestedPrice?.pricePerNight) ?? Infinity
|
Number(memberRequestedPrice?.pricePerNight) ?? Infinity
|
||||||
)
|
)
|
||||||
const currentLocalPrice = Math.min(
|
const currentLocalPrice = Math.min(
|
||||||
Number(publicLocalPrice.pricePerNight) ?? Infinity,
|
Number(publicLocalPrice?.pricePerNight) ?? Infinity,
|
||||||
Number(memberLocalPrice?.pricePerNight) ?? Infinity
|
Number(memberLocalPrice?.pricePerNight) ?? Infinity
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
import { useRouter } from "next/navigation"
|
||||||
import { useRef } from "react"
|
import { useRef } from "react"
|
||||||
|
|
||||||
import { useDetailsStore } from "@/stores/details"
|
import { useDetailsStore } from "@/stores/details"
|
||||||
@@ -14,6 +15,7 @@ export default function StepsProvider({
|
|||||||
breakfastPackages,
|
breakfastPackages,
|
||||||
children,
|
children,
|
||||||
isMember,
|
isMember,
|
||||||
|
searchParams,
|
||||||
step,
|
step,
|
||||||
}: StepsProviderProps) {
|
}: StepsProviderProps) {
|
||||||
const storeRef = useRef<StepsStore>()
|
const storeRef = useRef<StepsStore>()
|
||||||
@@ -21,6 +23,7 @@ export default function StepsProvider({
|
|||||||
const updateBreakfast = useDetailsStore(
|
const updateBreakfast = useDetailsStore(
|
||||||
(state) => state.actions.updateBreakfast
|
(state) => state.actions.updateBreakfast
|
||||||
)
|
)
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
if (!storeRef.current) {
|
if (!storeRef.current) {
|
||||||
const noBedChoices = bedTypes.length === 1
|
const noBedChoices = bedTypes.length === 1
|
||||||
@@ -41,7 +44,9 @@ export default function StepsProvider({
|
|||||||
step,
|
step,
|
||||||
isMember,
|
isMember,
|
||||||
noBedChoices,
|
noBedChoices,
|
||||||
noBreakfast
|
noBreakfast,
|
||||||
|
searchParams,
|
||||||
|
router.push
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -512,7 +512,16 @@ export const productTypePriceSchema = z.object({
|
|||||||
|
|
||||||
const productSchema = z.object({
|
const productSchema = z.object({
|
||||||
productType: z.object({
|
productType: z.object({
|
||||||
public: productTypePriceSchema,
|
public: productTypePriceSchema.default({
|
||||||
|
rateCode: "",
|
||||||
|
rateType: "",
|
||||||
|
localPrice: {
|
||||||
|
currency: "SEK",
|
||||||
|
pricePerNight: 0,
|
||||||
|
pricePerStay: 0,
|
||||||
|
},
|
||||||
|
requestedPrice: undefined,
|
||||||
|
}),
|
||||||
member: productTypePriceSchema.optional(),
|
member: productTypePriceSchema.optional(),
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -731,7 +731,7 @@ export const hotelQueryRouter = router({
|
|||||||
|
|
||||||
const rateTypes = selectedRoom.products.find(
|
const rateTypes = selectedRoom.products.find(
|
||||||
(rate) =>
|
(rate) =>
|
||||||
rate.productType.public.rateCode === rateCode ||
|
rate.productType.public?.rateCode === rateCode ||
|
||||||
rate.productType.member?.rateCode === rateCode
|
rate.productType.member?.rateCode === rateCode
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
"use client"
|
"use client"
|
||||||
import merge from "deepmerge"
|
import merge from "deepmerge"
|
||||||
import { produce } from "immer"
|
import { produce } from "immer"
|
||||||
|
import { AppRouterInstance } from "next/dist/shared/lib/app-router-context.shared-runtime"
|
||||||
import { useContext } from "react"
|
import { useContext } from "react"
|
||||||
import { create, useStore } from "zustand"
|
import { create, useStore } from "zustand"
|
||||||
|
|
||||||
@@ -18,17 +19,13 @@ import { StepEnum } from "@/types/enums/step"
|
|||||||
import type { DetailsState } from "@/types/stores/details"
|
import type { DetailsState } from "@/types/stores/details"
|
||||||
import type { StepState } from "@/types/stores/steps"
|
import type { StepState } from "@/types/stores/steps"
|
||||||
|
|
||||||
function push(data: Record<string, string>, url: string) {
|
|
||||||
if (typeof window !== "undefined") {
|
|
||||||
window.history.pushState(data, "", url + window.location.search)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function createStepsStore(
|
export function createStepsStore(
|
||||||
currentStep: StepEnum,
|
currentStep: StepEnum,
|
||||||
isMember: boolean,
|
isMember: boolean,
|
||||||
noBedChoices: boolean,
|
noBedChoices: boolean,
|
||||||
noBreakfast: boolean
|
noBreakfast: boolean,
|
||||||
|
searchParams: string,
|
||||||
|
push: AppRouterInstance["push"]
|
||||||
) {
|
) {
|
||||||
const isBrowser = typeof window !== "undefined"
|
const isBrowser = typeof window !== "undefined"
|
||||||
const steps = [
|
const steps = [
|
||||||
@@ -51,14 +48,14 @@ export function createStepsStore(
|
|||||||
steps.splice(1, 1)
|
steps.splice(1, 1)
|
||||||
if (currentStep === StepEnum.breakfast) {
|
if (currentStep === StepEnum.breakfast) {
|
||||||
currentStep = steps[1]
|
currentStep = steps[1]
|
||||||
push({ step: currentStep }, currentStep)
|
push(`${currentStep}?${searchParams}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (noBedChoices) {
|
if (noBedChoices) {
|
||||||
if (currentStep === StepEnum.selectBed) {
|
if (currentStep === StepEnum.selectBed) {
|
||||||
currentStep = steps[1]
|
currentStep = steps[1]
|
||||||
push({ step: currentStep }, currentStep)
|
push(`${currentStep}?${searchParams}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,7 +91,7 @@ export function createStepsStore(
|
|||||||
if (!validPaths.includes(currentStep) && isBrowser) {
|
if (!validPaths.includes(currentStep) && isBrowser) {
|
||||||
// We will always have at least one valid path
|
// We will always have at least one valid path
|
||||||
currentStep = validPaths.pop()!
|
currentStep = validPaths.pop()!
|
||||||
push({ step: currentStep }, currentStep)
|
push(`${currentStep}?${searchParams}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,5 +6,6 @@ export interface StepsProviderProps extends React.PropsWithChildren {
|
|||||||
bedTypes: BedTypeSelection[]
|
bedTypes: BedTypeSelection[]
|
||||||
breakfastPackages: BreakfastPackage[] | null
|
breakfastPackages: BreakfastPackage[] | null
|
||||||
isMember: boolean
|
isMember: boolean
|
||||||
|
searchParams: string
|
||||||
step: StepEnum
|
step: StepEnum
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user