Merged in fix/SW-3283-select-rate-booking-code (pull request #2699)
fix(SW-3283): add booking code when selecting rate and reset state when removing booking code * fix(SW-3283): add booking code when selecting rate and reset state when removing booking code * feat: add removeBookingCode action to SelectRateContext * fix(SW-3283): add booking code when selecting rate and reset state when removing booking code * fix(SW-3283): merge Approved-by: Joakim Jäderberg
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
import { usePathname, useRouter, useSearchParams } from "next/navigation"
|
||||
|
||||
import { BookingCodeChip } from "@scandic-hotels/design-system/BookingCodeChip"
|
||||
|
||||
import { useSelectRateContext } from "@/contexts/SelectRate/SelectRateContext"
|
||||
@@ -7,10 +5,8 @@ import { useSelectRateContext } from "@/contexts/SelectRate/SelectRateContext"
|
||||
export function RemoveBookingCodeButton() {
|
||||
const {
|
||||
input: { bookingCode },
|
||||
actions: { removeBookingCode },
|
||||
} = useSelectRateContext()
|
||||
const router = useRouter()
|
||||
const searchParams = useSearchParams()
|
||||
const pathname = usePathname()
|
||||
|
||||
if (!bookingCode) {
|
||||
return null
|
||||
@@ -23,12 +19,7 @@ export function RemoveBookingCodeButton() {
|
||||
withCloseButton={true}
|
||||
withText={false}
|
||||
onClose={() => {
|
||||
const newSearchParams = new URLSearchParams(searchParams)
|
||||
newSearchParams.delete("bookingCode")
|
||||
|
||||
const url = `${pathname}?${newSearchParams.toString()}`
|
||||
|
||||
router.replace(url)
|
||||
removeBookingCode()
|
||||
}}
|
||||
/>
|
||||
)
|
||||
|
||||
@@ -66,7 +66,7 @@ function InnerCode({
|
||||
} = useSelectRateContext()
|
||||
|
||||
function handleSelectRate(rateCode: string) {
|
||||
selectRate({ roomIndex, rateCode, roomTypeCode })
|
||||
selectRate({ roomIndex, rateCode, roomTypeCode, bookingCode })
|
||||
}
|
||||
|
||||
const bannerText = useBannerText({
|
||||
|
||||
@@ -29,6 +29,7 @@ export default function Redemptions({
|
||||
const intl = useIntl()
|
||||
const rateTitles = useRateTitles()
|
||||
const {
|
||||
input: { bookingCode },
|
||||
actions: { selectRate },
|
||||
selectedRates,
|
||||
} = useSelectRateContext()
|
||||
@@ -114,6 +115,7 @@ export default function Redemptions({
|
||||
roomIndex: roomIndex,
|
||||
rateCode: rateCode,
|
||||
roomTypeCode: roomTypeCode,
|
||||
bookingCode: bookingCode,
|
||||
})
|
||||
}}
|
||||
paymentTerm={rateTitles[firstRedemption.rate].paymentTerm}
|
||||
|
||||
@@ -243,6 +243,7 @@ function Inner({
|
||||
rateCode: rateCode,
|
||||
roomTypeCode: roomTypeCode,
|
||||
counterRateCode: counterRateCode,
|
||||
bookingCode: product.bookingCode,
|
||||
})
|
||||
}}
|
||||
isMemberRateActive={isMemberRateActive}
|
||||
|
||||
@@ -454,6 +454,24 @@ export function SelectRateProvider({
|
||||
updateBooking(selectRateBooking)
|
||||
setActiveRoomIndex("next")
|
||||
},
|
||||
removeBookingCode: () => {
|
||||
if (!selectRateInput.data) {
|
||||
return
|
||||
}
|
||||
|
||||
const clearedBooking: SelectRateBooking = {
|
||||
hotelId: selectRateInput.data.booking.hotelId,
|
||||
fromDate: selectRateInput.data.booking.fromDate,
|
||||
toDate: selectRateInput.data.booking.toDate,
|
||||
rooms: selectRateInput.data.booking.rooms.map((room) => ({
|
||||
...room,
|
||||
bookingCode: null,
|
||||
})),
|
||||
}
|
||||
|
||||
updateBooking(clearedBooking)
|
||||
setActiveRoomIndex(0)
|
||||
},
|
||||
},
|
||||
}}
|
||||
>
|
||||
|
||||
@@ -73,6 +73,7 @@ export type SelectRateContext = {
|
||||
roomTypeCode: string
|
||||
bookingCode?: string
|
||||
}) => void
|
||||
removeBookingCode: () => void
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user