Merged in chore/SW-3321-move-selectratecontext-to- (pull request #2729)
chore(SW-3321): Moved Select rate context to booking-flow package * chore(SW-3321): Moved Select rate context to booking-flow package * chore(SW-3321): Optimised code Approved-by: Joakim Jäderberg
This commit is contained in:
31
packages/booking-flow/lib/contexts/SelectRate/clearRooms.ts
Normal file
31
packages/booking-flow/lib/contexts/SelectRate/clearRooms.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import type { SelectRateBooking } from "../../types/components/selectRate/selectRate"
|
||||
|
||||
/**
|
||||
* Removes room data
|
||||
*/
|
||||
export function clearRooms({
|
||||
selectRateBooking,
|
||||
roomIndexesToClear,
|
||||
}: {
|
||||
selectRateBooking: SelectRateBooking | null
|
||||
roomIndexesToClear: number[]
|
||||
}):
|
||||
| { selectRateBooking: SelectRateBooking; hasUpdated: true }
|
||||
| { hasUpdated: false } {
|
||||
if (!selectRateBooking || roomIndexesToClear.length === 0) {
|
||||
return { hasUpdated: false }
|
||||
}
|
||||
|
||||
roomIndexesToClear.forEach((roomIndex) => {
|
||||
if (!selectRateBooking?.rooms?.[roomIndex]) {
|
||||
return
|
||||
}
|
||||
|
||||
selectRateBooking.rooms[roomIndex].roomTypeCode = null
|
||||
selectRateBooking.rooms[roomIndex].rateCode = null
|
||||
selectRateBooking.rooms[roomIndex].counterRateCode = null
|
||||
selectRateBooking.rooms[roomIndex].bookingCode = null
|
||||
})
|
||||
|
||||
return { hasUpdated: true, selectRateBooking: selectRateBooking }
|
||||
}
|
||||
Reference in New Issue
Block a user