Merged in feat/sw-2857-refactor-booking-flow-url-updates (pull request #2302)
feat(SW-2857): Refactor booking flow url updates * Add support for removing parameters when using initial values in serializeSearchParams * Don't manually write search params in rate store * Booking is already from live search params so no need * Fix input type in serializeBookingSearchParams Approved-by: Linus Flood
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
"use client"
|
||||
import { useRouter } from "next/navigation"
|
||||
import { useRouter, useSearchParams } from "next/navigation"
|
||||
import { useSession } from "next-auth/react"
|
||||
import { useState, useTransition } from "react"
|
||||
import { useIntl } from "react-intl"
|
||||
@@ -32,7 +32,6 @@ export default function RateSummary() {
|
||||
isFetchingPackages,
|
||||
rateSummary,
|
||||
roomsAvailability,
|
||||
searchParams,
|
||||
} = useRatesStore((state) => ({
|
||||
bookingCode: state.booking.bookingCode,
|
||||
bookingRooms: state.booking.rooms,
|
||||
@@ -43,7 +42,6 @@ export default function RateSummary() {
|
||||
isFetchingPackages: state.rooms.some((room) => room.isFetchingPackages),
|
||||
rateSummary: state.rateSummary,
|
||||
roomsAvailability: state.roomsAvailability,
|
||||
searchParams: state.searchParams,
|
||||
}))
|
||||
const { data: session } = useSession()
|
||||
const isUserLoggedIn = isValidClientSession(session)
|
||||
@@ -51,7 +49,7 @@ export default function RateSummary() {
|
||||
const [isSubmitting, setIsSubmitting] = useState(false)
|
||||
const intl = useIntl()
|
||||
const router = useRouter()
|
||||
const params = new URLSearchParams(searchParams)
|
||||
const params = useSearchParams()
|
||||
const [_, startTransition] = useTransition()
|
||||
|
||||
if (!roomsAvailability) {
|
||||
|
||||
@@ -38,6 +38,9 @@ export default function Form({ close }: { close: () => void }) {
|
||||
})
|
||||
|
||||
async function getFilteredRates(packages: PackageEnum[]) {
|
||||
const bookingCode = bookingRoom.rateCode
|
||||
? bookingRoom.bookingCode
|
||||
: booking.bookingCode
|
||||
const filterRates = await utils.hotel.availability.selectRate.room.fetch({
|
||||
booking: {
|
||||
fromDate: booking.fromDate,
|
||||
@@ -46,9 +49,7 @@ export default function Form({ close }: { close: () => void }) {
|
||||
toDate: booking.toDate,
|
||||
room: {
|
||||
...bookingRoom,
|
||||
bookingCode: bookingRoom.rateCode
|
||||
? bookingRoom.bookingCode
|
||||
: booking.bookingCode,
|
||||
bookingCode: bookingCode ?? undefined,
|
||||
packages,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -33,6 +33,10 @@ export default function RoomPackageFilter() {
|
||||
|
||||
async function deleteSelectedPackage(code: PackageEnum) {
|
||||
removeSelectedPackage(code)
|
||||
const bookingCode = bookingRoom.rateCode
|
||||
? bookingRoom.bookingCode
|
||||
: booking.bookingCode
|
||||
|
||||
const filterRates = await utils.hotel.availability.selectRate.room.fetch({
|
||||
booking: {
|
||||
fromDate: booking.fromDate,
|
||||
@@ -41,9 +45,7 @@ export default function RoomPackageFilter() {
|
||||
toDate: booking.toDate,
|
||||
room: {
|
||||
...bookingRoom,
|
||||
bookingCode: bookingRoom.rateCode
|
||||
? bookingRoom.bookingCode
|
||||
: booking.bookingCode,
|
||||
bookingCode: bookingCode ?? undefined,
|
||||
packages: selectedPackages
|
||||
.filter((pkg) => pkg.code !== code)
|
||||
.map((pkg) => pkg.code),
|
||||
|
||||
Reference in New Issue
Block a user