feat: SW-276 Optimized code
This commit is contained in:
@@ -19,14 +19,17 @@ export default function ChildSelector({ roomIndex = 0 }: ChildSelectorProps) {
|
|||||||
const children = guestsRoomsStore().rooms[roomIndex].children
|
const children = guestsRoomsStore().rooms[roomIndex].children
|
||||||
const { increaseChildren, decreaseChildren, childCount } = guestsRoomsStore()
|
const { increaseChildren, decreaseChildren, childCount } = guestsRoomsStore()
|
||||||
|
|
||||||
function updateChildrenCount(direction: string, roomIndex: number) {
|
function increaseChildrenCount(roomIndex: number) {
|
||||||
if (direction == "up" && children.length < 5) {
|
if (children.length < 5) {
|
||||||
increaseChildren(roomIndex)
|
increaseChildren(roomIndex)
|
||||||
setValue(`rooms.${roomIndex}.children.${children.length}`, {
|
setValue(`rooms.${roomIndex}.children.${children.length}`, {
|
||||||
age: -1,
|
age: -1,
|
||||||
bed: -1,
|
bed: -1,
|
||||||
})
|
})
|
||||||
} else if (children.length > 0) {
|
}
|
||||||
|
}
|
||||||
|
function decreaseChildrenCount(roomIndex: number) {
|
||||||
|
if (children.length > 0) {
|
||||||
decreaseChildren(roomIndex)
|
decreaseChildren(roomIndex)
|
||||||
let newChildrenList = JSON.parse(JSON.stringify(children))
|
let newChildrenList = JSON.parse(JSON.stringify(children))
|
||||||
newChildrenList.pop()
|
newChildrenList.pop()
|
||||||
@@ -41,7 +44,7 @@ export default function ChildSelector({ roomIndex = 0 }: ChildSelectorProps) {
|
|||||||
<Button
|
<Button
|
||||||
intent="text"
|
intent="text"
|
||||||
size="small"
|
size="small"
|
||||||
onClick={() => updateChildrenCount("down", roomIndex)}
|
onClick={() => decreaseChildrenCount(roomIndex)}
|
||||||
>
|
>
|
||||||
-
|
-
|
||||||
</Button>
|
</Button>
|
||||||
@@ -49,7 +52,7 @@ export default function ChildSelector({ roomIndex = 0 }: ChildSelectorProps) {
|
|||||||
<Button
|
<Button
|
||||||
intent="text"
|
intent="text"
|
||||||
size="small"
|
size="small"
|
||||||
onClick={() => updateChildrenCount("up", roomIndex)}
|
onClick={() => increaseChildrenCount(roomIndex)}
|
||||||
>
|
>
|
||||||
+
|
+
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -14,17 +14,11 @@ export type GuestsRoom = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface GuestsRoomsPickerProps {
|
export interface GuestsRoomsPickerProps {
|
||||||
// handleOnSelect: (selected: GuestsRoom[]) => void
|
|
||||||
// initialSelected?: GuestsRoom[]
|
|
||||||
closePicker: () => void
|
closePicker: () => void
|
||||||
// isValid: boolean
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type GuestsRoomPickerProps = {
|
export type GuestsRoomPickerProps = {
|
||||||
// handleOnSelect: (selected: GuestsRoom, index: number) => void
|
|
||||||
// room: GuestsRoom
|
|
||||||
index: number
|
index: number
|
||||||
// isValid: boolean
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type AdultSelectorProps = {
|
export type AdultSelectorProps = {
|
||||||
|
|||||||
Reference in New Issue
Block a user