feat: SW-276 Optimized code
This commit is contained in:
@@ -53,22 +53,22 @@ export const guestsRoomsStore = create<GuestsRooms>((set, get) => ({
|
||||
produce((state: GuestsRooms) => {
|
||||
state.rooms[roomIndex].adults = state.rooms[roomIndex].adults - 1
|
||||
state.adultCount = state.adultCount - 1
|
||||
let childrenInAdultsBed = 0
|
||||
state.rooms[roomIndex].children = state.rooms[roomIndex].children.map(
|
||||
(child) => {
|
||||
if (child.bed == BedTypeEnum["In adults bed"]) {
|
||||
childrenInAdultsBed = childrenInAdultsBed + 1
|
||||
if (childrenInAdultsBed > state.rooms[roomIndex].adults)
|
||||
child.bed =
|
||||
child.age < 3
|
||||
? BedTypeEnum["In crib"]
|
||||
: BedTypeEnum["In extra bed"]
|
||||
}
|
||||
return child
|
||||
}
|
||||
)
|
||||
state.rooms[roomIndex].childrenInAdultsBed =
|
||||
if (
|
||||
state.rooms[roomIndex].childrenInAdultsBed >
|
||||
state.rooms[roomIndex].adults
|
||||
) {
|
||||
const toUpdateIndex = state.rooms[roomIndex].children.findIndex(
|
||||
(child) => child.bed == BedTypeEnum["In adults bed"]
|
||||
)
|
||||
if (toUpdateIndex != -1) {
|
||||
state.rooms[roomIndex].children[toUpdateIndex].bed =
|
||||
state.rooms[roomIndex].children[toUpdateIndex].age < 3
|
||||
? BedTypeEnum["In crib"]
|
||||
: BedTypeEnum["In extra bed"]
|
||||
state.rooms[roomIndex].childrenInAdultsBed =
|
||||
state.rooms[roomIndex].adults
|
||||
}
|
||||
}
|
||||
})
|
||||
),
|
||||
increaseChildren: (roomIndex) =>
|
||||
|
||||
Reference in New Issue
Block a user