From 9dbd10afdd243d67163d12de2dfc6bb7945670e6 Mon Sep 17 00:00:00 2001 From: Hrishikesh Vaipurkar Date: Mon, 7 Oct 2024 16:13:07 +0200 Subject: [PATCH] feat: SW-276 Optimized code --- .../GuestsRoomsPicker/ChildSelector/index.tsx | 13 ++++++++----- types/components/bookingWidget/guestsRoomsPicker.ts | 6 ------ 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/components/GuestsRoomsPicker/ChildSelector/index.tsx b/components/GuestsRoomsPicker/ChildSelector/index.tsx index e9d8ff625..c1563f79f 100644 --- a/components/GuestsRoomsPicker/ChildSelector/index.tsx +++ b/components/GuestsRoomsPicker/ChildSelector/index.tsx @@ -19,14 +19,17 @@ export default function ChildSelector({ roomIndex = 0 }: ChildSelectorProps) { const children = guestsRoomsStore().rooms[roomIndex].children const { increaseChildren, decreaseChildren, childCount } = guestsRoomsStore() - function updateChildrenCount(direction: string, roomIndex: number) { - if (direction == "up" && children.length < 5) { + function increaseChildrenCount(roomIndex: number) { + if (children.length < 5) { increaseChildren(roomIndex) setValue(`rooms.${roomIndex}.children.${children.length}`, { age: -1, bed: -1, }) - } else if (children.length > 0) { + } + } + function decreaseChildrenCount(roomIndex: number) { + if (children.length > 0) { decreaseChildren(roomIndex) let newChildrenList = JSON.parse(JSON.stringify(children)) newChildrenList.pop() @@ -41,7 +44,7 @@ export default function ChildSelector({ roomIndex = 0 }: ChildSelectorProps) { @@ -49,7 +52,7 @@ export default function ChildSelector({ roomIndex = 0 }: ChildSelectorProps) { diff --git a/types/components/bookingWidget/guestsRoomsPicker.ts b/types/components/bookingWidget/guestsRoomsPicker.ts index 198d84d08..a7b0bec48 100644 --- a/types/components/bookingWidget/guestsRoomsPicker.ts +++ b/types/components/bookingWidget/guestsRoomsPicker.ts @@ -14,17 +14,11 @@ export type GuestsRoom = { } export interface GuestsRoomsPickerProps { - // handleOnSelect: (selected: GuestsRoom[]) => void - // initialSelected?: GuestsRoom[] closePicker: () => void - // isValid: boolean } export type GuestsRoomPickerProps = { - // handleOnSelect: (selected: GuestsRoom, index: number) => void - // room: GuestsRoom index: number - // isValid: boolean } export type AdultSelectorProps = {